NOTES / PROMPTING AND CONTEXT ENGINEERING

Compaction and summarisation

Keeping long-running agents inside the window: clear stale tool results, summarise older history, and know what each approach throws away.

UPDATED 18 NOV 2026#compaction#context-editing#summarisation#agents

The problem

An agent that works for dozens of turns accumulates messages and tool outputs until it nears the limit or its quality sags (see The context window as a budget). You have three levers.

Diagram: three levers: clear old tool results, compact the history, write to memory

Diagram: my own.

Lever 1: clear what is already used

Tool results are often the bulkiest and least useful part of history once the agent has acted on them. Once a tool result has been used, the raw output rarely needs to stay in history; Anthropic’s engineering post discusses clearing old tool results as a light form of compaction4. Anthropic’s context editing feature does this server side: a tool-result clearing strategy removes results once context passes a configured threshold, and a separate strategy clears thinking blocks. These edits are applied before the prompt reaches Claude, and each strategy can be configured independently2.

Lever 2: summarise the history

Compaction replaces older conversation with a summary. Anthropic’s docs describe server-side compaction as the recommended strategy for long-running conversations and agent workflows: when input tokens exceed a trigger threshold you set, the API generates a summary in a compaction block and continues with the compacted context1. You can also have the API pause after compaction, so your code can decide whether to continue1.

Diagram: history near the threshold is summarised into a summary block and the recent turns are kept

Diagram: my own, following the flow Anthropic documents in 1.

What a good summary keeps is a judgement call. My rule of thumb: decisions made, unresolved problems, and the specifics the next step depends on, while dropping redundant output. Tune for recall first so nothing critical is lost, then trim. This is my own guidance, not a quotation from the sources.

Risks of summaries, from general experience:

  • Silent loss. Details dropped from a summary are gone from the model’s view.
  • Drift. Repeated summarising of summaries compounds errors.
  • Reasoning lost. Some versions drop earlier thinking blocks, so the summary is all the model has of that work, according to Anthropic’s docs on newer models1.

Mitigate by writing critical state to files or memory before compaction, and by testing long tasks end to end.

Lever 3: move it outside the window

Structured note-taking means the agent writes progress notes to storage outside the context and reads them back later4. That is the subject of Memory.

Does it help?

Anthropic reported on an internal evaluation of agentic search tasks that combining the memory tool with context editing improved performance by 39 percent over baseline, and context editing alone gave 29 percent3. That is the vendor’s own test, so check on your tasks.

Practical advice

  • Prefer the built-in features over hand-rolled summarisation unless you need custom control1.
  • Set the threshold with headroom. Compact well before the limit so the summary call has room.
  • Mind the cache. Changing earlier content can invalidate a prompt cache; plan edits accordingly.
  • Test with long scripted tasks and check that facts needed at step 80 survive. This belongs in your evals.
  • Sub-agents are another form of compression: each explores deeply and returns a condensed result4. See Subagents.

Next: Memory.

Sources

  1. [1]Compaction — Anthropic, Claude Platform docsPARAPHRASED
  2. [2]Context editing — Anthropic, Claude Platform docsPARAPHRASED
  3. [3]Managing context on the Claude Developer Platform — Anthropic · 2025PARAPHRASED
  4. [4]Effective context engineering for AI agents — Anthropic Engineering · 2025PARAPHRASED

© Ashish Kumar. All rights reserved. Quoted and cited material belongs to its owners. How I attribute sources.

Product, company and framework names are trademarks of their respective owners. Mentioning them does not imply affiliation or endorsement.