pub async fn compact(
messages: &[Message],
provider: &dyn LlmProvider,
keep_recent_turns: usize,
compact_to_tokens: u64,
) -> Result<(Vec<Message>, Vec<Message>)>Expand description
Compact the message history via an LLM-generated summary.
Strategy:
- Front-trim messages so the compaction request fits in the context window.
- Summarise with the LLM.
- Build new_window = [summary] + last
keep_recent_turnsturns verbatim. - Trim new_window to ≤
compact_to_tokensso future turns have room.
Returns: (new_window, original_archive)