Skip to main content

Module compact

Module compact 

Source
Expand description

Compaction (RFC 0026 §5.2): when a context’s token estimate crosses context.compact_at × model_window (or context.compact is called), the older messages are summarized by a structured think into the summary block, the last keep_last messages stay verbatim, the plan stays verbatim, skill bodies not referenced in the kept window are evicted (the names stay), the version bumps and the record is checkpointed.

The runtime never calls the model itself, so compaction is two halves: a pure plan (plan_compaction — which messages to fold + the prompt + the output schema for the summarizer) and a pure apply (apply_compaction — fold the summarizer’s verdict into the context). The turn worker runs the think in between.

Structs§

CompactionOutcome
CompactionRequest
A prepared compaction: what to summarize and how.

Functions§

apply_compaction
Fold the summarizer’s verdict into the context: absorb the summary, drop the folded messages, bump the version, evict unreferenced skill bodies (names stay — the caller drops the bodies from its cache), recount. Refuses when the context changed since the plan (version drift).
apply_fallback
A degraded compaction for when the summarizer is unavailable: fold the older messages into a plain narrative built from their rendered lines (truncated). Never loses the plan or the skill names.
plan_compaction
Decide what to fold. keep_last messages stay verbatim; a fold always ends before the kept window and never splits an assistant tool-call from its tool results. Returns None when there is nothing worth folding (fewer than keep_last + 2 messages).
summary_schema
The summarizer’s output schema (RFC 0026 §5.1 summary block).