pub trait Compactor: Send + Sync {
// Required methods
fn should_compact(&self, ctx: &CompactionContext) -> bool;
fn compaction_prompt(&self) -> &str;
fn max_summary_tokens(&self) -> u32;
fn rebuild_history(
&self,
messages: &[Message],
summary: &str,
) -> CompactionResult;
// Provided method
fn prepare_for_summarization(&self, messages: &[Message]) -> Vec<Message> { ... }
}Expand description
Provider-agnostic compaction strategy.
Determines when to compact and how to rebuild the history after summarization.
Required Methods§
Sourcefn should_compact(&self, ctx: &CompactionContext) -> bool
fn should_compact(&self, ctx: &CompactionContext) -> bool
Check whether compaction should run given the current context.
Sourcefn compaction_prompt(&self) -> &str
fn compaction_prompt(&self) -> &str
Return the prompt to send to the LLM for summarization.
Sourcefn max_summary_tokens(&self) -> u32
fn max_summary_tokens(&self) -> u32
Maximum tokens the summarization response may consume.
Sourcefn rebuild_history(
&self,
messages: &[Message],
summary: &str,
) -> CompactionResult
fn rebuild_history( &self, messages: &[Message], summary: &str, ) -> CompactionResult
Rebuild the session history from a summary and current messages.
The system prompt is extracted from messages directly (the first
Message::System if present). No dual source of truth.
The implementation should:
- Preserve any
Message::Systemverbatim. - Inject a summary message.
- Retain recent complete turns per
recent_turn_budget. - Return everything else as
discarded.
Provided Methods§
Sourcefn prepare_for_summarization(&self, messages: &[Message]) -> Vec<Message>
fn prepare_for_summarization(&self, messages: &[Message]) -> Vec<Message>
Prepare messages for the summarization LLM call.
Called before sending the history to the LLM for summarization. Implementations may strip content that is not suitable for the summarization pass (e.g. base64-encoded images).
The default implementation returns an unmodified clone.