Context Rot: Why Your Agent Gets Dumber the Longer It Runs
If you’ve built an agent that runs for more than a handful of steps, you’ve felt this — even if you didn’t have a name for it.
Context Rot: Why Your Agent Gets Dumber the Longer It Runs
If you’ve built an agent that runs for more than a handful of steps, you’ve felt this — even if you didn’t have a name for it.
The first few turns are sharp. The agent reads the task, picks the right tool, makes good calls. Then, somewhere around turn twenty or thirty, it starts to drift. It forgets an instruction you gave at the start. It re-reads a file it already read. It “fixes” something that wasn’t broken. It confidently contradicts a decision it made five turns ago.
The model didn’t get worse. The context did.
This is context rot — the slow degradation of an agent’s performance as its context window fills up with the residue of its own work. It’s the single biggest reason long-running agents fail in ways that feel maddeningly random.
This is post two of three on context engineering. In the first post, we established the core idea: context is what the model knows, and your job is to engineer it. This post is about what happens to that context over time — and how to stop it from poisoning your agent.
Why more context can make things worse
The intuition that breaks people: we assume context is additive. Every fact you add can only help, right? Worst case, the model ignores it.
Wrong. Context is not additive. Past a certain point, it’s dilutive — and sometimes actively harmful.
Here’s the mechanism. A model decides what to do next by attending to everything in its window. When that window is 5,000 tokens of clean, relevant information, the signal is loud and clear. When it’s 150,000 tokens — 95% of which is old tool output, stale file contents, and abandoned reasoning paths — the few tokens that matter for this decision are drowning in noise.
The model is doing its best to find the signal. You’ve just buried it.
The three flavors of context rot
1. Context poisoning
A hallucination or error enters the context early — say, the agent misreads a function name or invents a file path — and because it’s now in the history, the model treats it as established fact. Every subsequent step builds on the wrong foundation. The lie compounds.
The dangerous part: the agent can’t distinguish its own past output from ground truth. A fact it hallucinated on turn 4 looks exactly as authoritative as the system prompt. Once poison is in the well, it spreads.
2. Context distraction
The window fills with so much accumulated history that the model starts over-weighting it and under-weighting its actual instructions. Instead of reasoning fresh about the task, it begins pattern-matching against its own transcript — repeating earlier actions, mimicking earlier phrasing, looping.
You’ll recognize this as the agent that keeps trying the same failed approach over and over, as if it can’t break out of the groove it dug. It’s distracted by its own past.
3. Context clash
Different parts of the context contradict each other. The user changed their mind on turn 10, but the original (now-wrong) instruction is still sitting there on turn 2. A tool returned stale data that conflicts with fresh data. The model now has to reconcile two truths — and it might pick the wrong one, or freeze.
Long conversations accumulate contradictions naturally, because the world changes while the transcript stays frozen.
A picture of rot

Same model. Same task. The only thing that changed is how much residue is sitting between the instructions and the current decision.
How to fight context rot
The good news: context rot is an engineering problem, not a model limitation. You don’t beat it with a bigger window — a bigger window just lets you rot more before you notice. You beat it by actively managing the context over the life of the task.
1. Compaction — summarize and reset
The most powerful tool. Periodically, compress the long, messy transcript into a tight summary: what’s been done, what was learned, what’s left. Start the next stretch of work from that clean summary instead of the full history.
This is how capable coding agents survive multi-hour tasks. When the window approaches its limit, they don’t truncate — they rewrite the context into a high-signal digest and continue. The agent keeps its conclusions and throws away the scratch work that produced them.
The art is in what you keep: decisions, facts learned, the current goal. Drop raw tool output, drop reasoning that led nowhere, drop files you’ve already extracted what you need from.
2. Sliding windows — let old turns fall off
For many agents you don’t need the entire history — you need the recent history plus persistent instructions. A sliding window keeps the system prompt and the last N turns, dropping the oldest as new ones arrive. Cheap, simple, and it caps rot by capping size.
The risk is dropping something that mattered — which leads to the next technique.
3. Externalize memory — get it out of the window entirely
The best place for information the agent might need later is not the context window. It’s a file, a scratchpad, a database — somewhere the agent can retrieve from on demand instead of carrying everything in its head at all times.
Instead of keeping a 2,000-line file in context “just in case,” the agent writes its key findings to a notes file and pulls them back only when needed. The window stays lean; nothing important is lost; it’s just stored somewhere that doesn’t cost attention on every single turn. (This is the heart of the next post — memory, RAG, and sub-agents.)
4. Fresh context for clean sub-tasks
When a task has a clear sub-problem — “go research X and report back” — don’t run it in the same polluted window. Spin up a sub-agent with a fresh context, let it do the focused work, and return only the result to the main agent. The main thread never sees the sub-agent’s messy intermediate steps. It just gets the clean answer.
This is how you keep a long, complex job from collapsing under its own weight: isolate the mess.
The mental model to take away
Stop thinking of context as a log that only grows. Think of it as working memory you are responsible for curating — turn by turn, step by step.
A poorly engineered agent dumps everything into the window and hopes the model sorts it out. A well-engineered agent asks constantly:
Is this still relevant? Is this still true? Do I need to carry this right now — or can I store it, summarize it, or let it go?
The model’s job is to reason. Your job is to make sure that, on every turn, what it’s reasoning over is clean.
Get that right and your agent stays as sharp on turn 100 as it was on turn 1.

Watched a long-running agent quietly lose the plot? Now you know why. Follow along for the fix. 👏
메타데이터
- post_id
- 2a46c9d74aa0
- slug
- context-rot-why-your-agent-gets-dumber-the-longer-it-runs-2a46c9d74aa0
- url
- https://medium.com/@maheshwari.vikash6702/context-rot-why-your-agent-gets-dumber-the-longer-it-runs-2a46c9d74aa0
- canonical_url
- https://medium.com/@maheshwari.vikash6702/context-rot-why-your-agent-gets-dumber-the-longer-it-runs-2a46c9d74aa0
- author_url
- https://medium.com/@maheshwari.vikash6702
- status
- ok
- fetched_at
- 2026-08-30 02:53:02