Skip to lesson

AnthropicClaude Certified Architect – Professional2026-102.4 Optimize context windows and manage token usage

Context Engineering for AI Agents: Memory vs. Compaction vs. Tool Clearing

Completed by opening the official lab

Why it matters

2.4 asks you to name what fills a long-running agent’s window before you pick a remedy; this notebook makes each remedy’s effect visible.

What to practise

Run a research agent over a large corpus with no context management, then under the clear_tool_uses_20250919 context edit, threshold compaction with the compact_20260112 edit, and the client-side memory_20250818 tool, alone and together. Tune trigger, keep and clear_at_least, and read context_management.applied_edits to see what clearing removed. Probe the compaction summary for dropped facts; custom instructions replace its default prompt. In the combined run, see why exclude_tools: ["memory"] protects memory calls. Watch clearing step the token trajectory down, compaction drop it further, and memory carry findings into a second session.

How it fits

The exercise puts 2.4.3’s choice between compaction and tool-result clearing into practice, and 2.4.4’s durable memory beyond the window. It shows threshold compaction only; set it beside 2.4.3’s on-demand compaction, where the application picks the turn boundary. Hold its memory backend to 2.4.4’s scope, expiry and validation: a saved note is not authoritative state.