pub struct CompressionConfig {
pub enabled: bool,
pub trigger_tokens: usize,
pub keep_recent_messages: usize,
pub max_summary_chars: usize,
pub max_transcript_chars: usize,
}Expand description
Tuning knobs for context compression.
Controls when and how the conversation history is compressed to fit within the model’s context window. The compressor keeps the most recent N messages intact (including tool results) and summarises older history via LLM.
§Defaults
| Field | Default | Purpose |
|---|---|---|
enabled | true | Master switch |
trigger_tokens | 256 000 | Skip compression when estimated tokens are below this |
keep_recent_messages | 16 | Number of most-recent messages kept verbatim |
max_summary_chars | 10 240 (10 KB) | Hard cap on the generated summary length |
max_transcript_chars | 20 480 (20 KB) | Max chars of old messages sent to the summarizer |
Fields§
§enabled: boolMaster switch. When false, compression is a no-op.
trigger_tokens: usizeCompress when the estimated token count of the message list exceeds this.
Set lower than context_window so compression fires before the window
manager’s blunt trim kicks in.
keep_recent_messages: usizeAlways keep the most recent N messages intact (the agent’s working context, including tool results). Older messages are summarised.
max_summary_chars: usizeHard cap (in chars) on the summary the summarizer LLM may produce. Output exceeding this is truncated (front 80 % + rear 20 %).
max_transcript_chars: usizeMax chars of the old-message transcript handed to the summarizer.
Implementations§
Source§impl CompressionConfig
impl CompressionConfig
Sourcepub fn builder() -> Self
pub fn builder() -> Self
Create a config with everything at default, then customise via builder.
pub fn with_enabled(self, enabled: bool) -> Self
pub fn with_trigger_tokens(self, tokens: usize) -> Self
pub fn with_keep_recent_messages(self, n: usize) -> Self
pub fn with_max_summary_chars(self, chars: usize) -> Self
pub fn with_max_transcript_chars(self, chars: usize) -> Self
Sourcepub fn validate_context_window(self, context_window: usize) -> Self
pub fn validate_context_window(self, context_window: usize) -> Self
Validate that trigger_tokens is less than the model’s context window.
Logs a warning and clamps if violated. Returns the (possibly clamped) config.