Expand description
Compaction: 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§
- Compaction
Outcome - Compaction
Request - 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’s
versionhas moved since the plan was made, or when the plan’s fold exceeds the messages actually present. - 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_lastmessages stay verbatim; a fold always ends before the kept window, never splits an assistant tool-call from its tool results, and always leaves aUsermessage first in the kept window. ReturnsNonewhen there is nothing worth folding (fewer thankeep_last + 2messages, or no user message to fold up to). - summary_
schema - The summarizer’s output schema: the fields of the summary block, all required, with no additional properties so a model cannot smuggle unread keys into a record that is kept forever.