Contents5 of 15
Download the PDF (892 KB)Before You Blame the ModelPart I · The Room: what the model actually sees
Chapter 04State and memory
What your agent forgets
Every agent forgets. The only question is whether you chose what it forgets, and whether anything tells you when it happens.
There are three common ways to give an agent a memory, and each one forgets something different:
| Strategy | How it works | What it forgets |
|---|---|---|
| Transcript | Keep every turn and send the whole conversation | Nothing, until the window fills. Then it forgets whatever gets cut, all at once. |
| Summary | Squash old turns into a model-written recap | Whatever the summarizer thought didn't matter. And the summarizer is the same model that's struggling. |
| Rebuilt state | Keep facts in your own records and rebuild a fixed-size prompt each turn | Whatever your code decides to leave out to stay inside the budget. |
The transcript feels safest, but longer isn't free even when it fits. Models are measurably worse at using information buried in the middle of a long input than at the start or end (Liu et al., "Lost in the Middle", 2023). Chroma found that model performance shifts significantly as input length grows, even on simple tasks (Chroma, "Context Rot", 2025). So "keep everything" isn't neutral. It's a choice to bury things.
Forgetting on purpose can help. In the SWE-agent study, keeping only the last five tool results instead of the full history raised the solve rate from 15.0% to 18.0% (Yang et al., 2024; GPT-4 Turbo on SWE-bench Lite). A JetBrains team found that simply hiding old tool outputs cut cost roughly in half against an agent that kept everything, and across their tests it held its own against model-written summaries, which cost a model call every time (Lindenbauer et al., "The Complexity Trap", 2025).
I went the third way on one of my agents: a prompt rebuilt from records each turn, with a hard budget. Over a 300-request run the biggest prompt was 32,159 tokens against a 33,344-token budget. It never grew. That was an early version, before it kept the ledger of open work I describe below.
But it still forgot. On one long task I checked whether files the model had read were still in view when it needed them. At request 11, none had dropped out silently. By request 30, 30% had. By request 61, 45%. Some of that wasn't the budget at all. It was bugs: my code was dropping files the model had already read, and nothing announced it. A fixed budget doesn't remove forgetting. It moves the decision into your code, which means it's now your bug when the wrong thing gets dropped (Chapter 8 is about exactly that).
#The split that makes any strategy better
Whatever you pick, separate two kinds of memory. Facts are things your code can know for certain: which tests are failing, which files were read and what they contained, which requirements are still open. Decisions are the model's job: what to try next and why. Facts should live in records your harness writes, not in the model's recollection of a conversation. That way summarizing or trimming never erases them, and the model never has to remember what your code already knows. My agent now keeps a running ledger of what's still owed, every requirement not yet met, and it's never trimmed.
@dataclass
class Facts: # written by the harness, never by the model
failing_tests: list[str]
files_read: dict[str, str] # path -> content hash
still_owed: list[str] # requirements not yet met
def trim(view, budget):
while size(view) > budget:
dropped = view.pop_lowest_priority() # never facts, never the task
if dropped is None: # nothing left that may go
raise OverBudget(size(view), budget) # fail loudly, don't send
emit("context_dropped", item=dropped.name) # forgetting is an event