Context pollution is when an agent's accumulated history of tool calls, observations, and thoughts crowds out the original task or the relevant signal, so the model loses focus or gets confused.
Imagine a tutor helping a student with one math problem. Every five minutes the tutor writes a fresh note: 'asked about fractions, then about decimals, then about negative numbers.' After two hours the notepad is full of side trips and the tutor can barely remember what problem they were originally solving. Context pollution is that notepad effect for an agent. Every tool call, every search result, every intermediate thought gets appended to the prompt. The original goal sits at the top buried under thousands of words of detours. When the model goes to take the next step, it spends most of its attention on the loudest noise nearby instead of the quiet original instruction.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Context pollution is the degradation of an agent's behaviour as its accumulated message history (intermediate thoughts, tool calls, tool results) crowds out the original task or the most recent useful signal. The model still receives every token; what changes is its ability to actually use them.
The phenomenon catches first-time agent builders because the symptoms look like a model regression. The agent worked beautifully on the first ten steps, then quietly started behaving as if it forgot the original goal. The fix is rarely a better model. It is almost always a better discipline about what to keep in the live prompt versus what to compress, drop, or move to retrieval.
This explanation builds the mental model in four steps: why a larger context window alone does not fix it, the two specific mechanisms that drive pollution, the four families of mitigation that production agents use, and a working set versus log mindset that separates a polluted agent from a clean one.
Why capacity is not the constraint
The first thing to internalise is that context pollution is not a context-window problem. Frontier models in 2026 ship with enormous windows: GPT-5.5 offers a million-token API context, Claude Opus 4.7 and Gemini 3.1 Pro support equivalent or larger working contexts. Yet long-running agents on those models still degrade after enough steps, often well before the window is anywhere near full.
The reason is that capacity and attention are different things. A model can read all of its context, but attention over that context is not uniform. The Lost in the Middle finding (Liu et al., 2023) showed that models attend most reliably to the start and end of the context, with measurably worse performance on information placed in the middle. As an agent's history accumulates, the original instruction stays at the top, the most recent step lands at the bottom, and everything in between, including older intermediate results the next step might need, falls into the lower-attention middle.
This is why buying a bigger model does not solve pollution on its own. You can fit more tokens, but the model still does not use them uniformly. Treat the window as a budget for relevant material, not as a free for all dump for everything the agent ever observed.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- LangGraph offers built-in checkpointing and a message-trimming policy so long-running agents can compress old turns rather than carry them indefinitely.
- Anthropic's agent guides recommend summarising prior tool results once their key fact has been extracted, to keep the active prompt focused.
What an interviewer would ask next. Try answering before peeking at the approach.
QA frontier model with a one-million-token context window still degrades on long agent runs. Why is capacity not enough?
Attention is not uniform across the window. Lost-in-the-middle shows models attend more to start and end positions than to middle. As context grows, important content gets pushed into the lower-attention middle, and salience competition between goal and recent noise grows. Capacity removes one cap; it does not remove these mechanisms.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Believing a larger context window solves it. Frontier models have a million-token context, yet attention degrades and signal to noise drops well before that limit. Pollution is a quality problem, not a capacity problem.
60 second bullets to scan on the way to the call.
Define context pollution as accumulated history crowding out the original task or recent signal.
Explain why a larger context window does not fully solve it.
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.