Skip to content

Lesson 2 of 6 · 4 min read

Context Rot

Free lessonReviewed By the AIAgentInterviews editorial team
Reading position
In this lesson

TL;DR: A model can have the right fact in its context and still miss it, and the chance grows with the length and noise of everything around it. Distractors that look like the answer and facts buried mid-context are the worst cases. Agents accumulate exactly that kind of context (stale results, near-duplicate records, long logs), so they degrade on long runs. Keep the window small and current, put what must hold at the edges, and measure the curve on your own task.

After this lesson, you should be able to explain why accuracy falls as context grows, recognise the kinds of agent context that make it worse, design an experiment that measures it for your task, and choose mitigations that address it rather than hide it.

Before you read

Commit to an answer now. The lesson that follows explains it, and having guessed first, even wrongly, makes the explanation easier to remember.

  1. 1An agent has the customer's current address in a tool result from turn 4. At turn 38 it ships to the old address, which appears in a result from turn 2. The window was only 40% full. What happened?

The fact was there, and the model still missed it

The intuition that "if it is in the context, the model can use it" is wrong in a specific, measurable way. Three effects compound as an input grows:

Attention spreads. The model has a finite capacity to relate tokens to each other. More tokens means each one, including the one that matters, gets a smaller share of that capacity.

Distractors compete. Irrelevant text is cheap to ignore; text that looks like the answer is not. Two addresses for the same customer, last week's test failure next to this week's, an order with an id one digit away from the right one: these are what make a long context hard, and agents produce them constantly.

Position matters. Liu et al. (2023), "Lost in the Middle", found models use information at the beginning and end of a long input more reliably than information in the middle. In an agent, the middle is where the early tool results sit by turn 40.

Benchmarks designed to test long inputs more realistically than simple needle-in-a-haystack retrieval, such as RULER (Hsieh et al., 2024), have found that models' effective context lengths are often much shorter than their advertised windows, and Chroma's 2025 "Context Rot" report found performance falling with input length even on simple tasks. The exact numbers change with every model; the direction has not.

Why agents are especially exposed

A chat assistant's context is mostly what people said. An agent's is mostly what tools returned, and tool output has every property that makes rot worse:

Context budget
The same fact, buried deeper each turn
23k of 200k tokens · 12%cached prefix 15k · hit
  • System prompt and tools15k
  • Conversation2k
  • Tool results6k
  • Current facts in notes0
1/4

Turn 3: the order is read

The current order record is one of a few results and easy to use.

Illustrative sizes. Quality falls with length and with look-alike facts, long before the window fills.
  • Stale versions. The order's status at turn 3 and at turn 25 are both there, and they disagree.
  • Near-duplicates. A search returns ten similar records; the right one differs by a field.
  • Volume without signal. A 4,000-line test log in which one line matters.
  • Superseded plans. The plan from turn 5, abandoned at turn 12, still reads as instructions.

Measure it on your task

Generic benchmarks tell you the direction; your own eval tells you the threshold that matters for your agent. The experiment is simple to describe:

take 100 tasks your agent solves reliably with a short context
for each, pad the context with REALISTIC noise from your own traces
  (old tool results, near-duplicate records, logs), at several sizes
measure success at each size, with several runs per task

illustrative shape of a result
  context  10k    success 94%
  context  40k    success 91%
  context  80k    success 83%
  context 120k    success 71%      window is 200k; only 60% used

Two details make it useful. Pad with realistic noise, not random text, because distractors are the dominant effect and random text has none. And run each task several times, because single runs cannot separate a 3-point drop from chance. The size at which success starts to fall is where your clearing threshold belongs.

What to do about it

The mitigations all reduce noise rather than add capacity:

  • Remove superseded information. When a newer result replaces an older one (a status, an address, a file version), clear the older result or mark it stale.
  • Keep results small and specific. Return the fields that matter; summarise logs into the lines that matter; paginate.
  • Put what must hold at the edges. Constraints that must never be forgotten belong in the system prompt or a pinned notes block near the end of the context, not in a message from turn 6.
  • Carry facts forward in notes. A short, current notes block ("customer address: X, confirmed turn 4") outranks a buried original.
  • Isolate exploration. Let a subagent read forty files and return the three findings, so the parent's context never contains the forty files.

A larger window is the one change that does not help with rot. It postpones the hard limit while leaving the noise, and the noise is the problem.

Say it in 30 seconds

"Context rot is accuracy falling as the input grows, even with the right fact present. It comes from attention spreading over more tokens, distractors that look like the answer, and facts buried in the middle, which 'Lost in the Middle' documented. Agents are exposed because tool output fills the window with stale versions, near-duplicates and logs. I measure it on my own tasks with realistic padding and repeated runs, set clearing thresholds where success starts to drop, and reduce noise: clear superseded results, keep results small, pin constraints at the edges, carry facts in notes and isolate exploration in subagents."

Check yourself

Answer aloud or on paper before revealing. Producing the explanation unaided is exactly what a panel listens for.

  1. 1Why pad with realistic noise from your own traces, not random text, when measuring context rot?

  2. 2A constraint ('never ship outside the EU') was stated in the user's first message and is ignored at turn 45. Where should it have been kept?

  3. 3Does a model with a 1M-token window remove the need for clearing old tool results?

Practise it as an interviewer asks it

Course lessons that teach this

Related lessons