Agent working memory is the information an agent holds live while it works on a task: the goal, the plan, the conversation so far, the tool results it has gathered, and the notes it is keeping for itself. The central question is simple: how does an agent keep track of a task that takes many steps without forgetting what it is doing? The short answer is that agent working memory combines the model’s context window with an explicit scratchpad and a compact plan, and it stays useful only when stale detail is regularly cleared away.
This guide explains what working memory is, what belongs in it, why it fills up, and the techniques that keep long tasks on track. It draws on the working memory model proposed by Baddeley and Hitch in 1974, which described a limited-capacity system for holding and manipulating information.
Key takeaways
- Agent working memory is the live, session-bound context an agent reasons over — everything else is long-term memory.
- It is strictly limited: the context window has a hard ceiling, and every token of history competes with tokens for reasoning.
- A compact plan, a scratchpad for intermediate results, and the latest tool outputs are what deserve space; raw transcripts do not.
- Compaction and summarisation are maintenance, not optimisation: without them, long tasks degrade or fail.
- Anything that must survive the session has to be written out to episodic or semantic memory before the session ends.
What agent working memory is
Working memory is the agent’s mental desktop. In human psychology, it is the system that holds a phone number in mind while you dial it, or keeps the steps of a calculation available while you work through them. In an AI agent, it is the set of information the model can directly reason over in a single call.
For a language-model agent, working memory has two parts. The first is the context window itself: the system instructions, the conversation history, the retrieved documents, and the tool outputs assembled into one prompt. The second is any explicit state the agent maintains outside the model but inside the session — a task plan, a scratchpad of intermediate results, and variables such as the current step or the remaining budget.
The CoALA framework, published by researchers at Princeton in 2023, calls this layer in-context memory and treats it as one of four memory types, alongside episodic, semantic, and procedural memory. The key point of the framework is that working memory is the only memory the model reasons over directly. Everything else must be retrieved into it before it can influence a decision.
What lives in working memory
A healthy working memory holds a small number of things, each earning its place.
The goal and the plan
The agent needs the current goal and a compact plan for reaching it: the steps already done, the step in progress, and the next step. A plan written as a short checklist is cheap in tokens and enormously valuable for staying on track. Agents without an explicit plan drift, repeating steps or wandering into side quests.
The plan should be updated as work proceeds, not rewritten from scratch each turn. A short status line — “step 3 of 6 done, waiting on search results” — keeps the agent oriented without costing much context.
Recent tool results
The most recent tool outputs matter most, because the agent’s next action usually depends on them. But tool results are also the fastest-growing part of working memory: a search can return pages of text, a database query can return hundreds of rows, and an agent that keeps all of it will run out of room.
The fix is to store the full result outside working memory and keep only what the agent needs: a summary, the relevant rows, or the extracted answer. Tools that return concise, structured results are worth more than tools that return everything and leave the agent to sift through it.
The scratchpad
A scratchpad is a small, structured space where the agent records intermediate results: numbers it has computed, names it has found, decisions it has made and why. Unlike the transcript, which grows passively, the scratchpad is written deliberately, and it is the agent’s own summary of what matters so far.
A good scratchpad is short and factual. It records conclusions, not reasoning, and it is pruned when items stop being relevant. An agent that maintains a scratchpad can survive context compaction, because the scratchpad is carried forward while the raw history is summarised away.
What does not belong
Old transcripts, repeated tool outputs, and retrieved documents that were never used do not belong in working memory. Neither do facts the agent already knows from long-term memory, unless they are needed for this specific task. Every token spent re-reading stale material is a token that cannot be spent on reasoning about the next step.
Why working memory fills up
Working memory fills up for three reasons, and each has its own remedy. The first is simple accumulation: every turn adds messages and tool results, and nothing is ever removed. A task with fifty tool calls has fifty results in context unless something intervenes.
The second is verbosity. Tools that return long, unstructured output and agents that reply in paragraphs consume context quickly. Short, structured tool results and concise agent messages slow the growth dramatically.
The third is repetition. Agents often re-fetch information they already have, re-read documents they have already summarised, or restate the plan in full each turn. Each repetition costs tokens and adds nothing. A scratchpad and a compact plan exist precisely to break this cycle.
The consequences are not subtle. The agent slows down, loses track of the goal, repeats steps it has already done, or contradicts earlier decisions. Eventually it hits a hard limit, and the run fails or truncates. This is why state management that lets agents remember, resume, and stay safe treats working memory as a resource to be managed, not a bin to be filled.

Techniques that keep working memory useful
Several proven techniques manage working memory. They work best in combination, and all of them share one idea: keep the live context small, current, and focused on the next decision.
| Technique | How it works | Best for | Watch out for |
|---|---|---|---|
| Summarisation | Old turns are condensed into a short summary | Long conversations | Summaries that lose key details |
| Compaction | History is replaced by a compact state: plan, scratchpad, key facts | Very long tasks | Dropping context still needed later |
| Scratchpad | Agent keeps short, structured notes on conclusions | Multi-step reasoning | Scratchpad growing without pruning |
| Sliding window | Only the most recent turns are kept verbatim | Simple, linear tasks | Losing early decisions |
| Retrieval on demand | Detail is fetched from storage only when needed | Tasks with large reference material | Retrieval misses and extra latency |
Best for most teams: a scratchpad plus periodic summarisation. The scratchpad preserves decisions, summarisation keeps the transcript affordable, and together they let an agent run far longer than its raw context window would suggest.
For background on the psychology behind these ideas, see the overview of memory, including the working memory model. For how working memory connects to the other memory layers, see our guide to planning strategies that improve task success, which depends heavily on keeping the plan visible in working memory.
Working memory and long tasks
Long tasks are where working memory design is tested. A task that runs for an hour or more will accumulate far more history than any context window can hold, so the system must decide, repeatedly, what to keep and what to let go.
The practical pattern is checkpointing. At regular points — after each major step, or after a fixed number of turns — the agent writes its current state to durable storage: the plan, the scratchpad, and the key facts. If the session is interrupted, a new session can load the checkpoint and continue, instead of starting over. Checkpointing turns working memory from a fragile live state into something recoverable.
Compaction should happen at the same checkpoints. The raw transcript is summarised, the summary is checked against the scratchpad for missing decisions, and the compacted state becomes the new working memory. Teams that compact on a schedule, rather than waiting for the context to fill, get smoother behaviour and fewer surprises.
It is also worth setting explicit budgets. A per-task token budget for working memory, a maximum number of tool calls, and a maximum number of turns give the agent — and the team — a clear picture of how much room remains. An agent that can see its budget manages it; one that cannot will spend it blindly.
A working memory design checklist
Use this checklist when designing or reviewing how an agent manages its live context. It covers the decisions that determine whether long tasks stay on track.
- Explicit plan: the agent keeps a short, updated plan in working memory, with done, doing, and next steps.
- Scratchpad: intermediate conclusions are recorded in a short, structured scratchpad, pruned as they age.
- Concise tool results: tools return structured, minimal output, with full results stored outside working memory.
- Scheduled compaction: history is summarised or compacted at checkpoints, not only when the context fills.
- Budget visibility: the agent can see its remaining token, step, and time budgets.
- Checkpointing: plan and scratchpad are written to durable storage regularly, so work survives interruption.
- Write-out before exit: anything worth keeping is promoted to episodic or semantic memory before the session ends.
- Retrieval on demand: large reference material is fetched when needed, not loaded up front — a discipline shared with orchestration that coordinates multiple agents.
Frequently asked questions
Is agent working memory the same as the context window?
Almost. The context window is the model’s input: everything it sees in one call. Working memory is that, plus the explicit session state the agent maintains around the model — the plan, the scratchpad, and the variables.
How big should an agent’s working memory be?
As small as the task allows. A compact working memory is faster, cheaper, and easier for the model to reason over. Start with the goal, the plan, the scratchpad, and the latest results, and add material only when the task genuinely needs it.
What happens when working memory fills up?
The agent slows down, loses track of the goal, repeats steps, or hits a hard limit and fails. The remedy is compaction: summarise history, keep the plan and scratchpad, and move anything worth keeping into long-term memory.
Should the agent see its full conversation history?
Only for short tasks. For anything longer, a summary plus the most recent turns is better. Full history is expensive, and most of it is never needed again. The scratchpad should hold whatever from the history still matters.
How does working memory relate to episodic and semantic memory?
Working memory is the live layer; episodic and semantic memory are the durable layers. Information flows from working memory into long-term memory through a write-out step, and back into working memory through retrieval. Nothing persists automatically — promotion must be explicit.
Can working memory be shared between agents?
It can, through shared state, but sharing the whole live context is usually a mistake. Share the plan, the task status, and the key facts — the compact state — and let each agent keep its own working memory for its own reasoning. Shared everything becomes shared confusion.
Agent working memory is small by nature and precious by design. Treat it as the agent’s desktop, not its archive: keep the goal, the plan, and the latest results in view, clear away everything else, and write anything worth keeping into long-term memory before the session ends.







