<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ashish Bagri</title>
    <description>The latest articles on DEV Community by Ashish Bagri (@ashishbagri).</description>
    <link>https://dev.to/ashishbagri</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4038179%2F8f1db18a-0e8c-478f-a82f-c5e0699c08d7.png</url>
      <title>DEV Community: Ashish Bagri</title>
      <link>https://dev.to/ashishbagri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashishbagri"/>
    <language>en</language>
    <item>
      <title>Your AI agent isn't hallucinating- it's reading garbage context</title>
      <dc:creator>Ashish Bagri</dc:creator>
      <pubDate>Mon, 20 Jul 2026 12:39:51 +0000</pubDate>
      <link>https://dev.to/ashishbagri/your-ai-agent-isnt-hallucinating-its-reading-garbage-context-278a</link>
      <guid>https://dev.to/ashishbagri/your-ai-agent-isnt-hallucinating-its-reading-garbage-context-278a</guid>
      <description>&lt;p&gt;Your agent isn't hallucinating. It's reasoning correctly over the wrong inputs.&lt;/p&gt;

&lt;p&gt;Here's a failure pattern every team running agents in production has hit: &lt;/p&gt;

&lt;p&gt;An alert fires. The agent investigates: pulls metrics, checks recent deploys, scans logs, proposes a fix. The fix is confidently, articulately wrong. Instinct says blame the model (bad reasoning, needs a better prompt, maybe a bigger model).&lt;/p&gt;

&lt;p&gt;Then someone reconstructs what the agent actually saw. The metrics query returned a 5-minute-old cached aggregate. The deploy list was fetched before the relevant deploy landed. The log window was truncated at 1,000 lines and the line that mattered was #1,014. Given those inputs, the agent's conclusion was reasonable. It just wasn't debugging the incident that happened.&lt;/p&gt;

&lt;p&gt;It's garbage in, garbage out, with a twist that makes it worse for agents than for any previous software. A dashboard shows you the garbage. A human sees a stale chart and might notice the timestamp. An agent consumes the garbage silently and &lt;em&gt;acts&lt;/em&gt; on it, with fluent reasoning layered on top. The output doesn't look like garbage; it looks like a confident, well-argued investigation. That confidence is what makes it dangerous.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why is this surfacing now
&lt;/h3&gt;

&lt;p&gt;For chatbots, context was mostly a retrieval problem over documents; mediocre retrieval meant a mediocre answer a human would shrug at. Three things changed with production agents:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Agents act.&lt;/strong&gt; A stale metric doesn't produce an off paragraph; it restarts the wrong service or pages the wrong team at 3AM. The cost went from cosmetic to operational.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The input surface exploded.&lt;/strong&gt; A production agent reads metrics, logs, deploy history, tickets, and chat from separate systems, each with its own latency, rate limits, caching, and clock. The "world" it reasons over is stitched together from partial snapshots, inside the model's reasoning loop, where nobody can inspect it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Errors compound.&lt;/strong&gt; A single wrong input gives a slightly wrong answer. A 20-step investigation where step 3's conclusion becomes step 4's premise turns a small input error into a confidently wrong remediation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Teams see the failure, file it as a reasoning problem, and reach for a bigger model or a longer prompt. The failure was upstream of the model the whole time.&lt;/p&gt;

&lt;h3&gt;
  
  
  Five ways context goes bad
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Stale:&lt;/strong&gt; true when fetched, then the world moved. Caches and polling intervals manufacture staleness silently.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Partial:&lt;/strong&gt; pagination limits, truncated log windows, retries that quietly gave up. The agent reasons over what arrived, not what didn't.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unordered:&lt;/strong&gt; events from six systems, six clocks, interleaved wrong. Causality inverts: the deploy looks like it followed the errors it caused.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lossy:&lt;/strong&gt; every transformation in the pipeline throws something away on purpose. Embeddings drop exact identifiers and word order. Summarization drops whatever seemed unimportant; the exact judgment the agent exists to make. Stack a few of these and the model ends up reading a paraphrase of a summary of a sample.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Unattributed:&lt;/strong&gt; the agent can't tell where a fact came from or when it was captured. Two contradictory data points arrive with equal authority, and the model just picks one.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these are model problems. A better model reasons more elegantly over the same bad inputs and arrives at the same wrong answer with nicer prose.&lt;/p&gt;

&lt;h3&gt;
  
  
  "Just wait for bigger context windows"
&lt;/h3&gt;

&lt;p&gt;Context windows are in the millions of tokens now. Why not pipe everything in raw and let the model sort it out? Three problems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Long context degrades.&lt;/strong&gt; The "lost in the middle" effect (Liu et al.) and the more general &lt;strong&gt;context rot&lt;/strong&gt; (Chroma's study, tested across 18 models) both show accuracy dropping as input length grows. A million-token window isn't a million tokens of reliable attention.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cost scales with tokens.&lt;/strong&gt; Every token is paid for on every reasoning step. For an agent running hundreds of investigations a day, "send everything" is a bad unit-economics decision.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The window can't fix what never arrived.&lt;/strong&gt; Freshness, completeness, ordering, and provenance are properties of the systems collecting the data. No model recovers a log line truncated upstream or un-stales a cached metric.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Context engineering is a systems discipline
&lt;/h3&gt;

&lt;p&gt;"Context engineering" has displaced "prompt engineering" for a reason. Anthropic's own guidance treats context as an engineering problem, not a wording problem. But even that's often applied narrowly, just packing the window better. The real discipline looks more like data infrastructure than writing.&lt;/p&gt;

&lt;p&gt;Good context is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Complete&lt;/strong&gt; over a defined window — "everything about service X in the last 30 minutes" is a guarantee, not a hope.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fresh&lt;/strong&gt;, with staleness measured, not accidental.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ordered&lt;/strong&gt;, on one clock, so causality survives.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lossless where it counts.&lt;/strong&gt; Structured and typed for cheap querying, but with original records preserved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Attributed:&lt;/strong&gt; traceable to a source and a moment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Replayable:&lt;/strong&gt; the property that matters most after something breaks. The postmortem question isn't "why did the model say that," it's "what did the model see." If context was assembled from live API calls, you can't answer that.  Τhe caches have rotated and the APIs have moved on. Treating agent context as a durable, ordered record turns forensics from guesswork into a replay.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The takeaway
&lt;/h3&gt;

&lt;p&gt;The industry has spent two years making agents better at thinking and almost no time making sure they're thinking about the right thing. The models are already good enough to be dangerous when fed garbage and fluent enough that the garbage stays invisible until the postmortem.&lt;/p&gt;

&lt;p&gt;Next time an agent fails in production, run the cheap experiment before reaching for a bigger model: reconstruct exactly what it saw, and ask if you'd have done better with the same inputs. Usually the answer is no. What looks like a reasoning failure is usually a context failure, and context failures are fixable with engineering today.&lt;/p&gt;

&lt;p&gt;I'm building &lt;a href="https://github.com/glassflow/navflow" rel="noopener noreferrer"&gt;NavFlow&lt;/a&gt;, open source and self-hosted, giving production agents one correlated read path across your systems — complete, fresh, ordered, lossless, and replayable — so the model's reasoning is the only variable left.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
      <category>mcp</category>
      <category>data</category>
    </item>
  </channel>
</rss>
