Skip to main content

CompactionStrategy

Trait CompactionStrategy 

Source
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§

Source

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§