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.
Detailed answer & concept explanation~7 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Define context pollution as growing history crowding out the original task or recent signal. Explain why it is a signal to noise problem, not a capacity problem. Describe two mechanisms: lost-in-the-middle attention skew and goal versus noise salience competition. Close with the four mitigation families and the working set versus log mindset.
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.
- Cursor's coding agent truncates large file contents to the specific symbols and lines the next step needs, rather than carrying every read file in full.
- Devin and other long-horizon coding agents use a separate scratchpad or notes file that lives outside the main message thread to avoid polluting the active context.
- Production support agents typically summarise the ticket plus the last three exchanges and drop earlier verbose tool output once it has been distilled.
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?
QWhat is the failure mode of overly aggressive summarisation?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes 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.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.