pub async fn compact_split(
messages: &[Message],
provider: &dyn LlmProvider,
keep_recent_turns: usize,
compact_to_tokens: u64,
) -> Result<(Vec<Message>, Vec<Message>)>Expand description
Hierarchical compaction used when primary compact() fails.
Strategy:
- Isolate the recent verbatim tail (last
keep_recent_turnsturns). - Split the remaining older messages into two halves.
- Summarise each half independently with the LLM (two API calls).
- Combine both summaries + recent tail into the new window.
- Trim new_window to ≤ 50 % of context_window.
Because each half is at most ~50 % of the full history, the summarisation requests are well within the context window even when the full history is not.