The Write Strategy: Memory and Scratchpads for AI Agents
The most direct attack on the token-accumulation problem, and arguably the single most powerful technique in context engineering. By moving information out of the active window, you let agents accumulate knowledge across long tasks without paying the token cost.
Long-running agents have a fundamental problem: every step adds to the context window, and eventually the accumulated history bloats the context, degrades quality, and runs up costs. The write strategy solves this elegantly by moving information out of the active window into external storage, keeping only what is immediately needed in context. It is the technique that makes genuinely long agent tasks possible.
What a Scratchpad Is
A scratchpad is external storage where an agent records information during a task. Instead of keeping every tool output and intermediate reasoning in the message history, the agent writes them to a file, database, or state object, and keeps only a lightweight reference or summary in the active context. When it needs the detail, it reads it back.
Consider an agent reviewing fifty files. Without a scratchpad, every file it examines stays in context, and by file forty the window is bloated with thirty-nine files it no longer actively needs. With a scratchpad, it logs findings per file to external storage and keeps only the running summary in context. The window stays lean; the knowledge persists.
|
Context Engineering: The Complete Guide Want the complete write strategy with memory patterns? 40 pages covering the four core strategies, the context window anatomy, all four failure modes, RAG, memory systems, multi-agent isolation, 20 production patterns and a complete 30-day mastery plan. Get the Complete Guide → |
Short-Term vs Long-Term Memory
The write strategy splits into two timescales. Short-term memory persists within a single task: the scratchpad an agent uses while working, discarded when the task completes. Long-term memory persists across sessions: facts about a user, learned preferences, accumulated knowledge that should survive from one conversation to the next.
These require different implementations. Short-term memory is often just a state object scoped to the current run. Long-term memory needs durable storage, usually a database or vector store, with mechanisms to write new memories, retrieve relevant ones, and prune stale ones. Both are forms of writing context out of the window for later use.
The todo.md Pattern
One particularly instructive write pattern comes from the agent framework Manus: the agent maintains a todo.md file with its task plan and constantly rewrites it as work progresses. This does two things at once. It persists the plan outside the window, and it pushes the current plan into the model most recent attention zone by rewriting it at the end of context each step. The pattern exploits recency bias, ensuring the strategic picture always sits in the highest-attention region rather than getting lost in the middle.
When to Write and When Not To
Writing is not free; it adds storage, retrieval logic, and decisions about what to write and when to read it back. For short tasks that fit comfortably in the window, it is unnecessary overhead. The strategy earns its keep on long-running tasks and multi-step workflows where context would otherwise accumulate beyond the comfortable zone. A good heuristic: if a task involves more than a handful of steps, introduce a write strategy; if it is quick and bounded, keep it simple.
Where to Start
The easiest write strategy to adopt first is a simple scratchpad: have the agent log its progress and findings to a structured file or state object, and reference that summary rather than carrying full detail in context. This single pattern often resolves the majority of token-bloat problems in multi-step agents, making it the highest-return first move in the entire discipline.
|
Ready to engineer context deliberately? Context Engineering: The Complete Guide covers everything: the anatomy of a context window, the four core strategies (Write, Select, Compress, Isolate), RAG and memory systems, multi-agent isolation, the four failure modes and how to diagnose them, what the research says about formats, 20 production patterns, 12 common pitfalls, and a 30-day plan that takes you from the concepts to real production systems. Get the Complete Guide →Instant PDF download · 40 pages · Current as of 2026 |