P-07Server-side Compaction & Context Editing

/ops/server-side-compaction

The API folds a long transcript for you: compact_20260112 summarizes older turns, or context editing clears old tool results and leaves a placeholder.

Step-by-step walkthrough2 variants · 14 steps

Compaction

  1. A long agent transcript crosses the token trigger. Something has to leave the window before the next turn.
  2. Threshold compaction sends the compact_20260112 strategy. The API writes the summary; you do not run a second model call to do it.
  3. Older turns become one compaction block. The API drops what the block replaces when you send it back.
  4. Recent turns stay verbatim — the file you just opened, the error you just read — instead of being paraphrased with the rest.
  5. The model continues from the summary, then those exact turns.
  6. A summarizer you wrote yourself is still available, and it is now the path you maintain: the prompt, the rewrite, and whatever it silently drops.
  7. On demand, the same idea uses a newer beta — you ask for the summary when you choose. Threshold compaction is the one that fires inside an ordinary request.

Context editing

  1. Tool results are usually the bulk of a long agent window: file dumps, logs, search hits.
  2. Context editing is the server-side rule for that slice. Past a token threshold it clears the oldest tool results, not a summary of the whole transcript.
  3. Each cleared result is replaced with a placeholder, so the model can tell that something was removed.
  4. The tool call itself can stay. The model still sees what it asked for, without the payload it has already used.
  5. The newest result is the one you keep. Clearing is oldest-first, and you choose the trigger.
  6. This is not compaction. Nothing was summarized. A fact that lived only inside a cleared tool result is gone unless you wrote it down elsewhere.
  7. Use editing to shed observations, compaction to fold the story, and a memory tool for what must outlive both.
Key insight

Both are the context plates, shipped as parameters. Threshold compaction (beta header compact-2026-01-12) fires inside an ordinary request when input crosses a trigger; on-demand compaction, under compact-2026-09-04, lets you ask for the summary when you choose. Context editing (clear_tool_uses_20250919) is for the observation slice, not the story. A memory tool is where a fact goes if neither may drop it.

Failure mode

Compacting and editing in the same request, or assuming a summary kept the one line that mattered. The API will not invent your write policy. Say what stays verbatim, and write the rest to memory before it ages out.

Elsewhere in the atlas