Compactor

Trait Compactor 

Source
pub trait Compactor: Send + Sync {
    // Required methods
    fn should_compact(&self, context_used: i64, context_limit: i32) -> bool;
    fn compact(
        &self,
        conversation: &mut Vec<Message>,
        compact_summaries: &HashMap<String, String>,
    ) -> CompactionResult;

    // Provided method
    fn is_async(&self) -> bool { ... }
}
Expand description

Trait for conversation compaction strategies. Implementations decide when and how to compact conversation history to reduce token usage while preserving important context.

Required Methods§

Source

fn should_compact(&self, context_used: i64, context_limit: i32) -> bool

Returns true if compaction should occur before this LLM call.

§Arguments
  • context_used - Current number of tokens in the conversation context
  • context_limit - Maximum context size for the model
Source

fn compact( &self, conversation: &mut Vec<Message>, compact_summaries: &HashMap<String, String>, ) -> CompactionResult

Performs synchronous compaction on the conversation. Returns the compaction statistics.

§Arguments
  • conversation - The conversation messages to compact
  • compact_summaries - Map of tool_use_id to pre-computed compact summaries

Provided Methods§

Source

fn is_async(&self) -> bool

Returns true if this compactor requires async compaction. When true, the caller should use AsyncCompactor::compact_async() instead of compact().

Implementors§