Skip to main content

Module compaction

Module compaction 

Source
Expand description

Compaction planning + assembly (M2).

Pure functions: the engine owns the trigger and the summarize call; this module decides what folds and assembles the new projection. The shape is always preserved prefix + typed digest + verbatim tail, and the tail snaps to a clean boundary so tool_use/tool_result pairing survives (split-turn handling): a tail may start at a User or an Assistant item, never at ToolResults (results must follow their assistant message).

Structs§

Plan

Constants§

SUMMARIZE_SYSTEM

Functions§

apply
The new projection: preserved prefix + digest + verbatim tail.
digest_item
The digest as a provenance-tagged user item.
floor_digest
The degradation floor: every summarize attempt failed, so the session continues with an honest placeholder instead of bricking.
plan
Choose what to fold. Picks the earliest clean boundary whose tail fits tail_budget tokens (keeping the most verbatim history that fits); if no tail fits, keeps the minimal clean tail and folds everything else. None means nothing can fold — the caller must surface context exhaustion rather than loop.
summarize_prompt
Render the folded items as a plain transcript for the summarize call. Tool results are clipped per-item — the digest needs their gist, and the summarize call must stay far smaller than the window being compacted.