Which of the following are valid strategies for mitigating context pollution in a long-running agent?
Real mitigations actively shrink or filter the context: sliding window, summarisation, and pruning. A bigger window or disabling retries does not fix the underlying noise.
Imagine a detective's desk that fills with notes as a case drags on. Every lead, every dead end, every coffee-stained scribble piles up. Soon the desk is so cluttered the detective wastes time re-reading junk and misses the one note that matters. To stay sharp they can keep only the newest pages, rewrite the old ones into a tidy summary, or throw out notes that turned out to be irrelevant. What does not help is buying a bigger desk. The clutter just spreads to fill it, and the useful fraction stays just as low. An agent's context window is that desk. The fix is to manage what sits on it, not to make it larger.
Detailed answer & concept explanation~8 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 pollution as a noise ratio problem, name the three active mitigations with one tradeoff each, explain why a bigger window and disabling retries fail the test, then close with how production tiers these techniques and adds sub-agent isolation.
| Strategy | Mechanism | Main cost | Genuine mitigation |
|---|---|---|---|
| Sliding window | Keep recent N steps | Forgets early constraints | Yes |
| Summarisation | Compress old steps every K turns | Extra LLM call, lossy | Yes |
| Selective pruning | Drop low-relevance entries | Needs a relevance signal | Yes |
| Bigger window | More capacity | Noise still accumulates | No |
| Disable retries | Fewer failed calls stored | Breaks error recovery | No |
Real products, models, and research that use this idea.
- Claude Code compacts long sessions by summarising earlier turns into a condensed memory block once the transcript nears the window limit, then continues with that summary plus recent turns.
- LangGraph exposes a state reducer and trimming hooks so a ReAct loop can apply a sliding window or summarise old messages between iterations.
- Anthropic's Claude Opus 4.7 supports very large context, yet its own agent guidance still recommends summarisation and offloading because raw recall decays in the middle of long inputs.
- Cursor and Cline store full file contents and tool outputs outside the prompt, injecting only the slices the current edit needs to keep the coding agent's context lean.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you protect the original goal and hard constraints when using a sliding window that forgets early turns?
QWhen does summarisation hurt more than help in an agent loop?
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.
Assuming a larger context window solves pollution. It only postpones the overflow while the noise ratio keeps climbing, so the model still drowns in stale steps.
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.