Compaction tiers
| When | Step | Action | LLM | Breaks cache | Status |
|---|---|---|---|---|---|
| When a result is made | Budget Reduction | Bounds one tool result over its weight cap, once | No | No | Built |
Before a turn, at the auto-compact share; or /compact | Auto-Compact | One rolling summary per chain | Once | Yes | Built |
| Between a turn's steps, at the auto-compact share | Mid-turn | Auto-Compact of the history before the turn; once per turn | Once | Yes | Built |
| Provider reports overflow | Reactive | Auto-Compact, then the same request again; once per request, twice per turn | Yes | Yes | Built |
| Each provider request, over budget | Request checkpoint | One checkpoint of the older prefix, in that request only | Bounded | Yes | Built |
| Still over, about 90% | Context Collapse | Segment summaries, originals kept | Per segment | Yes | Not built |
Summary semantics: Compaction. Claude Code's version of this ladder: Claude Code compaction. /context shows the token distribution.
Budget Reduction
| Aspect | Rule |
|---|---|
| Scope | Tool results only, not user or assistant messages |
| Threshold | spill.result_cap(): a weight of 10,000 (or the model's tool_output_weight), at most 30% of the window; applied once, when the result is made. Old results are never aged: they stay whole until Auto-Compact |
| Method | Keeps head and tail about 60/40 on line breaks, keeps the whole text in a file and names the lines to read |
| Code | agent/loop/tool_dispatch.py _as_stored, state/store/session/files/spill.py bound_text |
Auto-Compact and Reactive
Auto-Compact is the pipeline in Compaction. /compact [tokens] takes how many recent tokens to keep. Mid-turn and Reactive run in the agent loop (Overflow recovery) on the branch the turn runs on; a Stop ends the summary request.
Context Collapse (design)
- Trigger: still over, about 90%; blocking at 95%.
- 5–10 turns per segment, each summarized in about 100–300 tokens; LLM calls equal segments (30 turns in 3 segments: 3 calls).
- Originals stay in a collapse store through read-time projection.
Function-call nodes
A DAG addition with no Claude Code counterpart.
| Node state | Context | Compaction |
|---|---|---|
| Running | Inside: subtree fully expanded. Callers: expose=io by default, input and output only. Controlled by render_context callers, subcalls and expose | Inner tool outputs get Budget Reduction. |
| Completed or error | expose=io hides the subtree with no extra step; children stay inspectable in the DAG and readable through tools | Input and output are treated like a conversation node |
Rolling summary
Beyond Compaction:
- Always retain the latest complete user turn, and by default the latest two; the token budget may allow fewer than twenty top-level messages.
- A posted report is a boundary too, so a run of reports can be folded even with no user message between them; only the tail that fits stays.
- A large completed tool-heavy turn must not make compaction ineffective, so the cut moves to the next complete user boundary. An active user turn is never split, and its tool evidence is not discarded without entering the summary.
- Summary input and
covers_idsdescribe the same range. - Estimates include summary markers and tool results. The completion event reports both token counts and whether a summary was applied.
- Historical incorrect summaries are not rewritten; nothing is migrated or deleted.
- Session-graph compaction scope uses the same message snapshot, so a repeat during loading stays consistent.
Acceptance
- With large tool results among sixteen top-level messages, coverage includes complete older turns and context shrinks.
- The summary receives every replaced user request and visible tool result; recent turns are unchanged.
- Equal or longer summaries, cancellation, provider errors and edits during the call write nothing.
- Repeated compaction, branch switching, occupancy statistics and final requests render consistently.
Request checkpoint scope
Rules: Request checkpoint. Beyond those:
- Measured after message conversion, memory injection and actual-tool resolution; rechecked on every send and for fallback models.
- Cache belongs to the current AgentContext and never spans function views.
- It serves calls that cannot compact durably. It does not replace DAG summaries or promise lossless semantics or exact agreement with provider counts.
Request checkpoints
| Stage | Behaviour | Boundary |
|---|---|---|
| Budget | Counts system prompt, tools, response schema, output reserve, history | Recalculated for fallback models |
| Checkpoint | Older complete text-only prefix becomes a task summary | Never splits tool groups or discards multimodal or unresolved content |
| Summary request | All source text in budgeted chunks with rolling summaries | Cancellation, errors and exhausted budgets keep the original |
| Continue | Sends only a verified smaller request | Raw messages and DAG nodes unchanged |
Adapted from Codex local compaction, which keeps user messages and replaces execution history. OpenProgram copies no Rust source, truncates no user instructions, adopts no remote encrypted compaction and keeps the DAG. The checkpoint text is assistant data, never system instructions.
Acceptance
- AgentLoop continues after long assistant text and tool arguments exceed a model window.
- Every retained tool call has its result; the latest execution and user messages are exact.
- Summary calls fit the window, cover the full source and recover from provider overflow without dropping input.
- Cancellation, changed prefixes, model switches and non-text evidence do not reuse incompatible summaries.
- Open: installed-App acceptance.
A long session, 200K context
- 0–30%: Budget Reduction only.
paper_agentruns: its tool calls expand inside, oversized outputs are truncated; on completionexpose=iohides them.- The share is reached: Auto-Compact replaces older turns with one summary.
- A long tool run inside one message: Mid-turn compacts the history before it.
- The provider overflows: Reactive, then the same request again.
- A call that cannot compact durably: request checkpoint.
Last updated · 2026-11-25