Context Contamination
"Availability is influence."
Today's harnesses and standard practices are very good at the additive side of context engineering: retrieving context relevant to the task at hand. But they are very bad at removing bloat and contamination. Contamination in particular seems to be the most prominent source of agent failure today. The fact that contamination is largely hidden from human practitioners and compounds over time makes the problem particularly insidious.
The best models today are even more capable than most people think when handed a promperly currated context.
Types
Contents within context that hurt performance because they are irrelevant, contradictory, confusing, etc.
"Change of Plans"
Residue from plan reversals, abandoned approaches, interrupts, repeated corrections, renegotiated requirements, unexpected roadblocks, etc.
Even if the model has decided a new course of action, all of the tokens pointing to the discarded approach are still influencing output.
"Existential Crisis"
aka "Meta Analysis"
This usually occurs when you have a session evaluate itself, you criticize the model or its work, or tell it what not to do instead of what to do.
The model spends a bunch of tokens deliberating why it should do something vs it shouldn't. The extra thinking creates bloat and derails the model but also no matter what it chooses for each decision it will have tokens in its context with reasoning against that decision since it had to weigh the pros and cons.
- be careful of conditional instructions where the condition depends on self-evalutation
- "Instructing claude to continuously do meta analysis about churn levels literally creates churn where it otherwise wouldn't be. Contradicting the harness system prompt is also a churn source, since it causes claude to have moral-dilemma internal dialogues."
Context Poisoning
malicious insertion into context designed to align the agent to alternative goals
Contamination Transfer
aka Cross Contamination
Memories
An "aligned" memory today may be a "misaligned" memory tomorrow. We humans change our minds about things and overestimate the universality of our own rules.
- turn memories off if you care more about performance than convenience
- memories that come from criticizing are usually the worst offenders of damaging performance
- simple rules that don't require self-analysis are fine
- pointers to information are fine
Briefs
Brief contamination: failure to exclude everything but the problem statement to a subagent, in a case where the purpose of delegating the task is to optimize the context for that task. Instead of simply presenting the problem and allowing the agent to take an unbiased approach, claude poisons the subagent context with its own opinion and directives about what should be done.
FileSystem
files on the filesystem which contain contaminated context.
- includes code which drifts from good design or drifts from user's intention
- very common in agent-maintained documentation
FileSystem Contamination is essentially equivalent to codebase entropy, aka slop accumulation. Progress will grind to a halt on a codebase where vibe-coding is used too liberally. Entropy accumulates and compounds to the point where every bug fixed merged produces two more.
How it Relates to Subagents
There usually 3 reasons for a coordinator to create a subagent:
reason 1: currate the subagent's context for a given task
- This is the case where the coordinator must take extreme caution in avoiding brief contamination
reason 2: prevent context contamination and bloat in the coordinator's context
- In this case, brief contamination is acceptable as long as the there is reason 1 does not also apply
reason 3: cost-performance tradeoff optimization
- The coordinator may call a less advanced model to save cost on an easy task
- brief contamination is not a concern here
- The coordinator may call a less advanced model to
- avoid brief contamination in this case
Using this Information
- This file/information should not be given directly to a coordinator in hopes that it will make better decisions about briefing subagents based on this knowledge
- this would cause "existential crisis" contamination
Avoiding Brief Contamination
An external-evaluation approach is necessary. possible options:
- when coordinator spawns a subagent, a quick eval helper agent cleans up the brief if necessary
Also use external evaluation to determine contamination levels, so that you can make a more informed decisions about when to discard a session and resume with fresh context.
- also to identify sources of contamination
Avoiding Filesystem Contamination
-
in practice fs contamination is very hard to avoid. your #1 defense is diligence.
-
more on this later