agent_sdk/context/
config.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, Serialize, Deserialize)]
19pub struct CompactionConfig {
20 pub threshold_tokens: usize,
24
25 pub retain_recent: usize,
29
30 pub min_messages_for_compaction: usize,
34
35 pub auto_compact: bool,
39}
40
41impl Default for CompactionConfig {
42 fn default() -> Self {
43 Self {
44 threshold_tokens: 80_000,
45 retain_recent: 10,
46 min_messages_for_compaction: 20,
47 auto_compact: true,
48 }
49 }
50}
51
52impl CompactionConfig {
53 #[must_use]
55 pub fn new() -> Self {
56 Self::default()
57 }
58
59 #[must_use]
61 pub const fn with_threshold_tokens(mut self, threshold: usize) -> Self {
62 self.threshold_tokens = threshold;
63 self
64 }
65
66 #[must_use]
68 pub const fn with_retain_recent(mut self, count: usize) -> Self {
69 self.retain_recent = count;
70 self
71 }
72
73 #[must_use]
75 pub const fn with_min_messages(mut self, count: usize) -> Self {
76 self.min_messages_for_compaction = count;
77 self
78 }
79
80 #[must_use]
82 pub const fn with_auto_compact(mut self, auto: bool) -> Self {
83 self.auto_compact = auto;
84 self
85 }
86}
87
88#[cfg(test)]
89mod tests {
90 use super::*;
91
92 #[test]
93 fn test_default_config() {
94 let config = CompactionConfig::default();
95 assert_eq!(config.threshold_tokens, 80_000);
96 assert_eq!(config.retain_recent, 10);
97 assert_eq!(config.min_messages_for_compaction, 20);
98 assert!(config.auto_compact);
99 }
100
101 #[test]
102 fn test_builder_pattern() {
103 let config = CompactionConfig::new()
104 .with_threshold_tokens(50_000)
105 .with_retain_recent(5)
106 .with_min_messages(10)
107 .with_auto_compact(false);
108
109 assert_eq!(config.threshold_tokens, 50_000);
110 assert_eq!(config.retain_recent, 5);
111 assert_eq!(config.min_messages_for_compaction, 10);
112 assert!(!config.auto_compact);
113 }
114}