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§
Sourcefn should_compact(&self, context_used: i64, context_limit: i32) -> bool
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 contextcontext_limit- Maximum context size for the model
Sourcefn compact(
&self,
conversation: &mut Vec<Message>,
compact_summaries: &HashMap<String, String>,
) -> CompactionResult
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 compactcompact_summaries- Map of tool_use_id to pre-computed compact summaries