Your Agent Is Acting on Two Versions of the Truth

Halfway through a long session the agent has read the order total twice, and the two reads disagree. Both numbers are still sitting in the window, nobody marked one as superseded, and the model quietly picks the wrong one.

Viral RuparelNo. 107 of 10710 min read

A team I was helping had a support agent that could look up an order, apply a refund rule, and draft a reply. It worked in the demo and failed in a way nobody could reproduce on command. Every so often it would quote a customer one total in the first sentence and a different total two sentences later, or compute a refund against a number that did not match the one it had just displayed. The logs showed no error. The tool calls all returned 200. The model was not hallucinating, because every number it used had genuinely come from somewhere real.

The cause was mundane once we traced it. Early in the session the agent fetched the order and saw a total of 142.00. Later, after the customer added an item, it fetched the order again and saw 163.50. Both reads were correct at the moment they happened. Both were still in the context. Nothing in the window said the second one replaced the first, so the model had two equally confident facts about the same field and no rule for which one was true now. It picked one essentially at random, and which one depended on where each number had landed in a context that was by then several thousand tokens long.

This is context clash, and it is a different animal from the failures teams usually look for first.

Two contradictory reads of one order total enter the agent context and a resolution layer collapses them to a single value before assembly
Figure. Context clash resolved to a single source of truth

Why clash is not the same as staleness

It is tempting to file this under staleness and move on. Staleness is real and worth fixing, but it is a one-dimensional problem: an observation describes a resource, the resource changed, and the old observation is now wrong. The fix is to notice the age and either drop it or re-read. I wrote about that mechanism in staleness-aware pruning for long sessions, and if your only problem is lingering old snapshots, that is the tool to reach for.

Clash is two-dimensional. The issue is not that one value is old. The issue is that two values of the same fact are present at once and nothing in the system marks which one wins. You can run aggressive staleness pruning and still have a clash, because both contradictory reads arrived recently, through different paths, and neither looks stale. The order total from a tool call and the order total mentioned in a retrieved email thread can both be minutes old and still disagree.

The research literature calls this inter-context conflict, one of three kinds of knowledge conflict catalogued in the survey of knowledge conflicts for LLMs: disagreement among the pieces of knowledge in the context itself, as opposed to a clash between the context and what the model learned in training. Their finding that matters for production is simple. Models do not resolve these conflicts in a stable, predictable way. They are swayed by position, by surface fluency, and by which claim is repeated more often, none of which correlate with which value is actually correct.

Where the contradictions enter the window

If you want to fix clash you have to know where the two versions come from, because the entry points are specific and each one is a place you can intervene.

The first is repeated reads of a mutable resource, the order-total case above. The agent reads something, the world or the agent itself changes it, the agent reads it again. Both reads persist.

The second is retrieval. This is the loudest source in any system that does retrieval-augmented generation, because retrieval is a machine for gathering many documents about one entity into a single window. A reranker orders them by relevance, not by authority or freshness, so a stale cached page and a current internal doc can sit side by side, both quoting a price, both confident. When the retrieval step itself is drifting, as I covered in query drift and recall collapse, you get even more near-duplicate passages that each assert a slightly different fact.

The third is compaction. When you summarize old turns to control the token budget, prose summaries blur exactly the structured fields that matter, a threshold, an owner, an amount. The summarizer writes "the order was updated" and drops the number, so now you have the vague old summary and a precise new read, and the model has to reconcile a sentence against a figure. If you compact, understand that it can manufacture clash as a side effect, which is one reason compaction needs an explicit policy rather than a blunt truncation.

The fourth is cross-session memory. A fact written to long-term memory three sessions ago can contradict what the agent observes today, and unless memory writes carry provenance and get reconciled on read, the agent treats a remembered belief and a live observation as peers.

Detecting a clash before the model averages it

The failure is invisible in the usual telemetry because nothing errors. So the first move is to make it visible. You cannot resolve a conflict you never detect.

The detection primitive is a fact, not a message. Instead of letting tool results and retrieved passages flow into the transcript as opaque text, extract the claims you care about into a small typed record: the entity, the field, the value, where it came from, and when. Two records with the same entity and field but different values are a clash, full stop. You do not need the model to find it.

from dataclasses import dataclass
from time import time

@dataclass(frozen=True)
class Fact:
    entity: str          # "order:8841"
    field: str           # "total"
    value: str           # normalized string form
    source: str          # "tool:get_order" | "doc:kb-1920" | "memory"
    priority: int        # higher wins when timestamps tie
    observed_at: float

def clashes(facts: list[Fact]) -> list[tuple[Fact, Fact]]:
    by_key: dict[tuple[str, str], list[Fact]] = {}
    for f in facts:
        by_key.setdefault((f.entity, f.field), []).append(f)
    out = []
    for group in by_key.values():
        values = {f.value for f in group}
        if len(values) > 1:                 # same slot, disagreeing values
            group.sort(key=lambda f: f.observed_at)
            out.append((group[0], group[-1]))
    return out

Run clashes on every assembly, log a counter when it fires, and tag the trace. Now the thing that was unreproducible has a metric. In the support agent, turning this on showed clashes on roughly one session in twelve, concentrated on orders that had been modified mid-conversation, which told us exactly where to look. This is the same instinct as reading an action back before you commit to it: you check the state you are about to act on instead of trusting that it is coherent.

Pinning a single source of truth

Detection tells you a clash exists. Resolution decides the value the model is allowed to see. The rule that keeps this sane is that the model never arbitrates. Your code resolves the conflict deterministically, and the assembled context carries one value per field plus a short note on where it came from.

A resolution policy is just a function from a group of conflicting facts to a winner. Most teams need three strategies and a fallback.

def resolve(group: list[Fact]) -> tuple[Fact, str]:
    # 1. authoritative source always wins, regardless of age
    authoritative = [f for f in group if f.source.startswith("tool:")]
    if authoritative:
        best = max(authoritative, key=lambda f: (f.observed_at, f.priority))
        return best, "authoritative-source"
    # 2. otherwise newest observation wins
    newest = max(group, key=lambda f: (f.observed_at, f.priority))
    others = [f for f in group if f.value != newest.value]
    # 3. if a non-authoritative value is close in time, do not guess
    if others and abs(others[-1].observed_at - newest.observed_at) < 60:
        return newest, "ambiguous-escalate"
    return newest, "newest-wins"

The point is not these exact rules. The point is that the decision is explicit, logged, and testable. A live tool read of the order beats a quarter-old retrieved page every time, so pricing and totals resolve to the system of record. When two non-authoritative sources disagree and you genuinely cannot tell which is right, you return ambiguous-escalate and route to a human rather than letting the model flip a coin. That is the honest version of a human-in-the-loop approval gate: escalate the specific decision you cannot make safely, not every decision.

Then assembly uses only resolved facts:

def render_context(facts: list[Fact]) -> str:
    by_key: dict[tuple[str, str], list[Fact]] = {}
    for f in facts:
        by_key.setdefault((f.entity, f.field), []).append(f)
    lines = []
    for (entity, field), group in sorted(by_key.items()):
        fact, why = resolve(group)
        # one value per field, with provenance the model can cite
        lines.append(f"{entity}.{field} = {fact.value}  (via {fact.source}, {why})")
    return "FACTS (resolved, authoritative):\n" + "\n".join(lines)

The model now sees order:8841.total = 163.50 (via tool:get_order, authoritative-source) and nothing else about that field. There is no second number to drift toward. The provenance line is not decoration: it lets the model quote the source and lets you audit why a given value was used.

The parts that bite

The first thing that bites is normalization. "163.50" and "163.5" and "$163.50" are the same value, and if your clash detector treats them as different you drown in false positives. Normalize values to a canonical form per field before comparing, and expect to spend real time on dates, currencies, and enumerations. Over-normalizing is its own trap, because 142.00 and 163.50 must stay distinct.

The second is that resolution is not free of judgment, and a wrong policy is worse than none because it is confidently wrong. "Newest wins" is correct for an order total and dangerous for a legal clause where the authoritative version is not the most recently retrieved one. Pick the policy per field, not globally.

The third is that compaction and conflict resolution fight each other if you are not careful. Resolve first, then compact the resolved facts, never the reverse, or you will summarize two contradictory values into one lossy sentence and destroy the signal you needed. This ordering matters as much as the policy itself, and it is part of treating context as a managed budget rather than a transcript, the theme running through context rot and token budgets.

The fourth is scope. You do not extract every fact, only the ones whose disagreement changes an action: amounts, identifiers, states, thresholds, owners. Vendor guidance now names context clash explicitly as a top production failure mode, and Splunk's write-up on context engineering in production puts contradictory accumulated information near the top of its list. But chasing every possible contradiction turns a correctness fix into a latency problem. Fix the fields that move money and state.

The takeaway

Context clash is the failure that looks like a model problem and is really a plumbing problem. Two true-at-some-point values end up in the same window, nothing marks which one is current, and the model picks for reasons that have nothing to do with correctness. You will not prompt your way out of it, because the thing you would be asking the model to do, reliably arbitrate between identical-looking facts across a long context, is precisely what the architecture cannot promise. The fix lives below the prompt: extract facts, detect same-slot disagreement, resolve to one value with an explicit policy, and assemble context from the resolved set. This is the same discipline that Anthropic describes as curating the smallest set of high-signal tokens, applied to the specific case where two tokens claim to be the same thing.

If your agent is occasionally confident and wrong in a way you cannot reproduce, and the numbers it uses are all individually real, you are probably looking at a clash rather than a hallucination. That distinction changes the fix entirely. If you want a second pair of eyes on where contradictions enter your agent's context and which fields deserve a resolution policy, I am happy to talk it through. Thirty minutes, no pitch.

ShareXLinkedInviralruparel.com/blog/agent-context-clash-single-source-truth

Questions this essay answers

01How is context clash different from stale context?

Stale context is one-dimensional: an old snapshot of a resource lingers after the resource changed, and the fix is to prune it or re-read. Context clash is two values of the same fact living in the window at the same time, and the problem is not that one is old but that nothing marks which one wins. You can prune every obviously aged observation and still have a clash, because both contradictory reads arrived recently through different paths, a tool call and a retrieved document, say. Staleness is about age. Clash is about reconciliation. A long-running agent usually suffers from both and needs a different mechanism for each.

02Can I just tell the model to use the most recent value?

Not reliably. The model has no trustworthy notion of which of two identical-looking facts was written later, and recency inside a long transcript is exactly the signal that degrades as the window fills. A contradictory value sitting in the middle of a large context can outweigh the correct one near the end. Worse, two numbers that both look plausible invite the model to average or to pick the first it attends to. The fix is to resolve the conflict in your code, before assembly, and hand the model a single value with a short note on where it came from, rather than hoping it arbitrates correctly.

03Does retrieval-augmented generation make context clash worse?

Yes, because retrieval is a machine for pulling many documents that mention the same entity into one window, and those documents often disagree. A pricing page cached last quarter and a fresher internal doc can both surface for one query, and the reranker orders them by relevance, not by which is authoritative or current. Unless you deduplicate by claim and attach a source priority, the model sees two confident answers and no rule for choosing. Treating retrieved passages as facts to reconcile, not just text to concatenate, is what keeps retrieval from amplifying the conflict.

04Where should conflict resolution live in an agent?

In a small layer between where facts enter the agent and where the context is assembled for the model. Every tool result, retrieved passage, or memory write lands in a fact store keyed by entity and field. On each read the store returns one resolved value using an explicit policy, newest wins, authoritative source wins, or escalate when it cannot decide. The assembled prompt then carries resolved facts, never the raw pile. Keeping this out of the prompt and in deterministic code is what makes the behavior testable and keeps the same conflict from being resolved differently on two runs.

Working on this in production?I help teams make agents like this reliable. Thirty minutes, no pitch.
Viral Ruparel

Generative AI consultant and full-stack architect. Ex-IBM, former Director of Engineering at a YC W20 startup. Writes about what breaks when agents meet reality.