pub trait CompactionStrategy: Send + Sync {
// Required method
fn compact(
&self,
messages: Vec<AgentMessage>,
config: &ContextConfig,
) -> Vec<AgentMessage>;
}Expand description
Strategy for compacting messages when context exceeds budget.
Implement this to customize what happens during compaction:
- Index discarded content into a memory store before removal
- Apply custom preservation rules (e.g., always keep decisions)
- Emit metadata about what was compressed
See the Custom Compaction docs for examples.
Required Methods§
Sourcefn compact(
&self,
messages: Vec<AgentMessage>,
config: &ContextConfig,
) -> Vec<AgentMessage>
fn compact( &self, messages: Vec<AgentMessage>, config: &ContextConfig, ) -> Vec<AgentMessage>
Compact messages to fit within the token budget defined by config.
Called before each LLM turn when context_config is set.