What is context pollution in agents, and how do you deal with it?
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Context pollution is the accumulation of low-value or actively misleading content in an agent's working context, degrading every subsequent decision. It matters because context isn't just storage - it's evidence the model conditions on, and models weight in-context content heavily. Pollution comes in escalating severity:
- Noise: bloated tool results, dead-end exploration debris, stack traces. Cost and attention dilution - relevant signal gets buried, and long-context degradation ("context rot") sets in well before the window limit.
- Staleness: a file read 40 turns ago that's since been edited; search results predating a state change. The model confidently acts on a world that no longer exists.
- Self-poisoning: the model's own earlier hallucination or wrong conclusion sits in context and becomes "established fact" - subsequent reasoning builds on it, and the error compounds. This is the mechanism behind correlated (worse-than-p^n) failure cascades.
- Adversarial poisoning: injected instructions from untrusted tool results persisting across turns - pollution as an attack.
Full worked answer
Context pollution is the accumulation of low-value or actively misleading content in an agent's working context, degrading every subsequent decision. It matters because context isn't just storage - it's evidence the model conditions on, and models weight in-context content heavily. Pollution comes in escalating severity:
- Noise: bloated tool results, dead-end exploration debris, stack traces. Cost and attention dilution - relevant signal gets buried, and long-context degradation ("context rot") sets in well before the window limit.
- Staleness: a file read 40 turns ago that's since been edited; search results predating a state change. The model confidently acts on a world that no longer exists.
- Self-poisoning: the model's own earlier hallucination or wrong conclusion sits in context and becomes "established fact" - subsequent reasoning builds on it, and the error compounds. This is the mechanism behind correlated (worse-than-p^n) failure cascades.
- Adversarial poisoning: injected instructions from untrusted tool results persisting across turns - pollution as an attack.
Countermeasures:
- Prevent: token-efficient tools, result caps, and subagent isolation - quarantine exploratory mess in workers so only distilled findings enter the main context. This is the strongest structural defence.
- Prune: clear or stub stale tool results (keeping a marker that the call happened); some platforms now offer context-editing/tool-result-clearing natively. Compaction that summarises decisions but drops noise and failed attempts - a compactor that faithfully preserves the garbage preserves the problem.
- Recover: when a trajectory visibly degrades - the agent re-asks answered questions, contradicts itself, fixates on a wrong premise - the cheapest fix is often restart with notes: have the agent write its validated learnings to a scratchpad, then start a fresh context seeded with those notes. Restarting discards the poison; the notes keep the progress.
- Verify before trusting: for load-bearing facts (does this function exist? is the config value X?), re-check against the environment rather than context memory - tools are ground truth, context is a cache.
What a good answer covers
- Context pollution is the accumulation of low-value or actively misleading content in an agent's working…
- It matters because context isn't just storage - it's evidence the model conditions on, and models weight…
- Noise: bloated tool results, dead-end exploration debris, stack traces
- Staleness: a file read 40 turns ago that's since been edited; search results predating a state change
- Self-poisoning: the model's own earlier hallucination or wrong conclusion sits in context and becomes…
Key terms: Noise · Staleness · Self-poisoning · Adversarial poisoning · Prevent · Prune · Recover · restart with notes · Verify before trusting
In the glossary: Attention · Context rot · Hallucination · Subagent · Compaction
Interviewer follow-ups to expect
How would you detect self-poisoning in traces automatically?
- Noise: bloated tool results, dead-end exploration debris, stack traces. Cost and attention dilution - relevant signal gets buried, and long-context degradation ("context rot") sets in well before the window limit.
- Staleness: a file read 40 turns ago that's since been edited; search results predating a state change. The model confidently acts on a world that no longer exists.
- Self-poisoning: the model's own earlier hallucination or wrong conclusion sits in context and becomes "established fact" - subsequent reasoning builds on it, and the error compounds. This is the mechanism behind correlated (worse-than-p^n) failure cascades.
- Adversarial poisoning: injected instructions from untrusted tool results persisting across turns - pollution as an attack.
What makes a compaction prompt good at dropping poison but keeping decisions?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep