Loading patterns…
Context Editing & Tool-Result Clearing(CETC)
A harness or API-level primitive that automatically evicts stale content from the live context window once it crosses a token threshold, most often by surgically replacing old tool_result blocks with short placeholders while keeping the matching tool_use record intact. Because file reads, search hits, and API dumps are re-fetchable, they are dropped at zero inference cost and re-pulled only if a later turn actually needs them, which keeps the KV-cache prefix stable and counters context rot on long loops. Anthropic ships this as clear_tool_uses_20250919 and compact_20260112, with a reported ~84% token reduction on a 100-turn web-search evaluation and a 29-39% performance lift. Distinct from `context-compress-patterns`: clearing losslessly evicts re-fetchable raw results rather than lossily summarizing them, unlike `filesystem-as-context` it needs no explicit write-to-disk offload step, and unlike `memory-forgetting-policies` it is not about decaying long-term memory but about pruning the working window.
In 30 seconds
- What
- Automatically removes old tool result payloads from context when token limits approach, replacing them with placeholders while preserving tool call records.
- When to use
- Long-running agent loops where tool results accumulate faster than consumption and results remain re-fetchable from external sources.
- Watch out
- If a cleared result is needed without re-running the tool, the placeholder breaks transcript coherence and forces a re-fetch.
Ask the AI expert about this pattern
Opens the assistant with your question prefilled. You review it before sending.
Context Editing & Tool-Result Clearing: Overview
A harness or API-level primitive that automatically evicts stale content from the live context window once it crosses a token threshold, most often by surgically replacing old tool_result blocks with short placeholders while keeping the matching tool_use record intact. Because file reads, search hits, and API dumps are re-fetchable, they are dropped at zero inference cost and re-pulled only if a later turn actually needs them, which keeps the KV-cache prefix stable and counters context rot on long loops. Anthropic ships this as clear_tool_uses_20250919 and compact_20260112, with a reported ~84% token reduction on a 100-turn web-search evaluation and a 29-39% performance lift. Distinct from `context-compress-patterns`: clearing losslessly evicts re-fetchable raw results rather than lossily summarizing them, unlike `filesystem-as-context` it needs no explicit write-to-disk offload step, and unlike `memory-forgetting-policies` it is not about decaying long-term memory but about pruning the working window.
- Threshold-triggered eviction fires automatically at a configured input-token budget
- Surgically clears the oldest tool_result blocks, replacing payloads with a short placeholder
- Keeps the tool_use call record so the transcript stays coherent and re-callable
- Zero inference cost: eviction is a harness edit, not a model summarization pass
- Re-fetchable by design, the agent re-runs the tool only when the data is needed again
- Preserves the KV-cache prefix on prior turns so cached tokens stay cheap
The Agent Architect
One pattern, one tradeoff, one production failure story. A short weekly briefing for people building agentic systems.
Weekly email, one-click unsubscribe. We only use your address to send the briefing.
References
The papers, specifications, and repositories this pattern is based on.
From the engineer behind this catalog
Get your agent architecture reviewed
This page documents one pattern. Your system runs dozens, and most failures live in how they fit together. Have the whole design reviewed against the 288 patterns in this catalog: architecture, reliability, evaluation and cost, every finding mapped to the pattern that fixes it.
€750 instead of €1,500, one week, written report and walkthrough call, until 30 September