DEV Community

Cover image for How Context Drift Impacts Your AI Agents
Patrick Kelly for Google AI

Posted on Originally published at patrickjohnkelly.com on

How Context Drift Impacts Your AI Agents

Most people building with AI in late 2026 understand that the quality of your context determines the quality of your output. But what exactly determines the quality of your context?

First, let's break down all the different types of context:

  • One-off prompts that you type into chat conversations
  • Your base instruction files like AGENTS.md, injected automatically into each new session
  • Skill files, which are ideally custom procedural instructions, loaded dynamically as-needed in relevant situations
  • Word documents and spreadsheets in your Google Drive or similar system
  • Local markdown files in your code repo
  • Memories (usually automatically managed by your agent harness and generally not exposed to you visually)

With all these different sources, likely maintained by different people, there's a very high chance you have legacy process docs and out-of-date facts, metrics, decisions, and strategies.

So what happens if your agent finds the wrong information? Or if it finds conflicting information? Doc A says the refund policy is 14 days, Doc B says 30 days. Which one does your agent trust?

If the documents are clearly dated or the agent reads the metadata, it might figure it out, but we want better than a chance of factual correctness.

In search of a solution, I started wondering: what types of conflicts or issues create the biggest problems? I decided to run an experiment to answer this question.

Context rot vs. context drift

People often lump every context issue under context rot, a term coined last year to describe how an LLM's accuracy drops as a session grows too long and fills up with noise, dead ends, and distractors.

What happens across a real team's files is slightly different. Over weeks and months, your underlying sources (AGENTS.md, skills, docs, memories, and code) gradually fall out of sync, so your agent can get conflicting instructions on the very first turn of a brand-new session. That's really context drift.

To test both side by side, I built a realistic coding sandbox (a git repo with real files and terminal tools) and ran 470 tasks across Gemini 3.8 Flash and Gemini Pro, intentionally planting bloat, duplicate rules, stale docs, and direct contradictions.

What broke (and what didn't)

I went in expecting context rot from pure bloat to cause obvious mistakes. Instead, injecting 50,000 tokens of unrelated chat history and duplicating agreeing rules across files caused zero rule violations, even on Gemini 3.8 Flash.

Context drift was a different story, and I only caught what was happening by reading the summaries of the model's internal thinking process (its private mental scratchpad).

In 73% of runs, the model explicitly noticed in its thinking that two sources disagreed. Yet across 110 unprompted runs, it mentioned that conflict to the user 0% of the time.

Instead of warning you, the model quietly picks a winner and moves on. On 95% to 100% of matching tasks, a task-specific skill file overrode the root AGENTS.md, even when AGENTS.md used strict MUST wording. If you update a repo-wide rule in AGENTS.md and forget to update a task-specific skill file that still has the old value, your agent will silently follow that stale skill file almost every time.

When Two Context Files Disagree: 95-100% followed task-specific skill over AGENTS.md, 73% noticed mismatch in private thinking, 0% warned in chat

Stale docs against live code were even sneakier. When a doc referenced an old test helper name that had already been renamed in the codebase, 9 out of 15 runs quietly wrote a one-line wrapper inside their new test file so pytest would still pass without mentioning the mismatch.

My guess is that this comes from RLHF training. Modern models are trained to be decisive and finish the job rather than pestering you with questions on every minor ambiguity, which is normally what keeps agentic workflows pleasant to use.

The only other measurable penalty was deliberation: when two peer skill files disagreed with no clear tie-breaker, the model spent 47% more thinking tokens debating the conflict across turns.

Giving the agent an escape hatch

Once I saw that the model was already spotting these conflicts in its thinking trace, I tried adding one line to AGENTS.md asking it to mention disagreements in chat. That worked on 100% of completed runs (16 out of 16).

Still, I didn't want my agent interrupting every coding session to complain about docs. So I turned it into a tool instead: a tiny read-only escape hatch called report_inconsistency, with two categories (conflict and stale).

(I originally tested a duplicate category too, though asking agents to log harmless repeats wasted extra turns on normal cross-references and pushed more runs into our sandbox's 34-turn limit, even though 95% still wrote the code, so I cut it.)

Because the model is already checking whether one file supersedes another while exploring, calling the tool takes almost no extra effort.

Even with no instructions added to AGENTS.md, simply having the tool available got the agent to log 98.7% of the conflicts it encountered across Gemini 3.8 Flash and Gemini Pro (150 out of 152 runs), with zero false alarms on Flash.

Passive Drift Logging: 0% surfaced without tool vs 98.7% logged with report_inconsistency MCP tool

Token cost stayed flat too. In our matched tests, total turns barely moved and thinking tokens dipped slightly (~19% on average, within normal run-to-run noise), so the real takeaway is simple: passive logging is essentially free.

Running it passively in practice

Moving this into my daily coding setup surfaced two quick catches worth knowing:

  • Logging replaces chat warnings: Once the tool exists, the agent stops mentioning conflicts in chat (0%) unless you add one line asking for both.
  • Keep the tool and file list visible up front: Larger models like Gemini Pro take far fewer exploratory steps than Flash, so they only catch drift in skill or memory files when summaries are listed in the prompt (and when the MCP tool is loaded eagerly rather than hidden behind tool search).

How you act on a logged conflict is up to you. You could pause the agent on the spot, though for everyday work I prefer keeping it passive: the agent logs the file paths, exact quotes, and which version it followed while finishing my task, and I review the cleanup queue later.

Plugging one tiny MCP tool into a local log file gives your agent a built-in sensor for context drift at zero extra cost. Within 24 hours of turning it on in my own setup, it had already caught a real spec-vs-code mismatch during a PR review without me asking.

Top comments (3)

Collapse
 
cleverhoods profile image
Gábor Mészáros • • Edited

The finding holds - we published it in August: the model notices the
contradiction and it picks one (dev.to/reporails/opus-5-the-cost-o...).

But the fix goes the wrong way. Drift bites because every source loads on turn
one and the model has to referee. The escape hatch adds more always-on context
(an AGENTS.md line, an eager MCP tool, files listed in the prompt) and still
only logs after the agent has picked a side.

Your own skill-beats-AGENTS.md result is the lever however, not the bug: the instruction
loaded later, closer to the task, wins. So give each rule one home and load it
at its moment: path/context-scoped rules, skills, a hook on the write. Route the hooks
through one event bus and you get a deterministic log of what entered context
and what fired, no model self-report needed, plus the option to block the write
instead of filing a ticket about it: dev.to/reporails/progressive-disclosure-claude-code-hooks-events-and-telemetry-1fh8

Then catch the structure before any session: npx @reporails/cli check flags
one topic living in two co-loaded files, cross-file duplication (the
"harmless" category you dropped, which is usually the place where contradictions live) and dead references.

Collapse
 
gde03 profile image
Giulio D'Erme •

The finding that the model notices a conflict and then says nothing, matches with my experience. But I went the other way, from a bigger AGENTS.md, to keep facts out of the instruction, files and inject them only when they are needed.

Injection. Each fact is one dated memo in RE-call. A hook on every prompt searches the store with the user's words and injects the top three summaries. Each summary carries the dates it states about itself, with a line saying the later claim wins. A second hook injects notes only before the shell commands they apply to. Those notes are proposed from an analysis of past failures and repeated mistakes, and none goes live until I approve it. Keeping all of this out halved my CLAUDE.md/agent.md (746 lines to 358), so I save context and spend it only when a fact is needed.

Supersession. A memo can declare supersedes: another. Search then ranks the old memo below its successor and returns it labelled superseded, naming the memo that replaced it. Your 14 days versus 30 days case is settled by the store, not by the model.

Your report_inconsistency is close to RE-call's recall_report_stale. The agent reports a stale memo while it is using it, and the report goes to a review queue; nothing is retired automatically. In one controlled test on my store, 36 of 38 reports pointed at a real supersession.

github.com/GiulioDER/RE-call

Collapse
 
innokentyb profile image
Kent Bodrov •

The passive report is useful for cleanup, but I’d separate two outcomes: a stale example can enter a review queue, while conflicting rules about authorization or an irreversible action should stop that action until the owner resolves it. I’d record which sources conflicted and which action was held, so the next run can recheck the decision rather than silently inheriting a guess. How would you choose which conflicts require a hard stop?