Skip to main content

compact_ctx

Function compact_ctx 

Source
pub async fn compact_ctx(
    ctx: &mut Vec<AgentMessage>,
    policy: &CompactionPolicy,
    stream_fn: &StreamFn,
    opts: &LlmOpts,
    instructions: Option<&str>,
    session: Option<&mut Session>,
) -> Result<CompactOutcome, String>
Expand description

Summarize the older prefix of ctx in place: keep the newest messages per policy, replace the rest with a summary message, and — when a session is open — persist the boundary so a resume rebuilds the same view.

Ordered so a failure leaves ctx untouched: the session write happens before the in-memory splice. Ok(NothingToDo) when the cut keeps everything (nothing worth summarizing).