Level 8Lesson 72โฑ๏ธ 40 min

When Context Goes Wrong

Context engineering has its own canonical bug list. Learn to recognize each failure by its symptom - and apply the right fix

Symptoms, Not Mysteries

When an agent misbehaves, beginners blame the model and reach for a bigger one. Usually the real cause is one of a handful of context failures with recognizable symptoms. Learn the list and you'll diagnose problems in seconds instead of guessing.

The meta-fix for almost all of these: not more context, but better-targeted context. Keep that in mind as we go through the list.

The Three "Too Much" Failures

Context overload

Symptom: the agent gets slower, pricier, and somehow less accurate as you give it more. Cause: you dumped everything in "to be safe" and hit context rot. Fix: retrieve less but better - re-rank to a tight top-k.

Context distraction

Symptom: the agent fixates on something irrelevant that happened to be in the window. Cause: loud but off-topic material crowds out the signal. Fix: cut the irrelevant chunks; enforce a relevance threshold.

Context confusion

Symptom: the agent contradicts itself or wavers. Cause: the context contains conflicting signals pulling it different ways (two docs that disagree, an old rule and a new one). Fix: remove the stale/contradictory source; don't make the model referee a fight you can settle.

All three share one root cause: pushing past the budget without curating what's inside. The cure is never "less context" in the dumb sense - it's better-targeted context, with a re-ranker enforcing a hard cap.

Stale Retrieval

Symptom: the agent confidently uses something that's no longer true - calls a function that was deleted, quotes an old policy, references last quarter's number.

Cause: a pre-built index (Lesson 68) went stale. Your data changed; the embeddings didn't get refreshed. The agent reads a deprecated README and trusts it.

Fix: track freshness. Refresh indexes when sources change, or lean on just-in-time retrieval that reads the current file instead of a months-old snapshot. This is especially nasty for code, where stale info compiles and runs before it fails.

Lost in the Middle (Again)

Symptom: the crucial fact was in the context, but the agent acted like it never saw it. Cause: it was buried in the middle of a long block (Lesson 66). Fix: reorder - put the highest-signal material at the top or bottom - and shrink the block so there's less middle to get lost in.

Quick diagnosis:
  "The info was there but ignored"   โ†’ lost in the middle (reorder)
  "It used outdated info"            โ†’ stale retrieval (refresh)
  "It fixated on the wrong thing"    โ†’ distraction (cut noise)
  "It contradicted itself"           โ†’ confusion (remove conflicts)
  "Slow, costly, and worse"          โ†’ overload (re-rank, trim)

The Boring-but-Real One: Cost & Latency

Not every failure is a wrong answer. Sometimes the agent is right but too expensive or too slow to be worth it. Every extra retrieval, tool call, and re-rank shows up in the bill and the wait time. An agent that quietly uses 5ร— the context it needs is a real failure even when its answers are fine.

Fix: set per-task token and tool-call budgets, and alert when an agent class regularly blows past them - the same discipline as Level 7's "Cost per Accepted Change."

The Whole Level in One Checklist

Before you ship an agent, check its context:
  • Instructions at the right altitude - not brittle, not vague? (Lesson 67)
  • Retrieval targeted and fresh - not a dump, not stale? (Lesson 68)
  • Memory managed - compaction / notes / sub-agents for long tasks? (Lesson 69)
  • Tools few, clear, and non-overlapping? (Lesson 70)
  • A re-ranker enforcing a tight top-k, highest-signal at top/bottom? (Lesson 71)
  • A token budget tracked per task, with alerts? (Lessons 71, 72)
Tick all six and you're engineering context, not just hoping for the best.

Hands-On: Diagnose From Symptoms

Hands-on (10 min): Here are three real-sounding bug reports. Name the context failure and the fix for each: (1) "Our support agent got noticeably worse after we added the entire 200-page manual to its context." (2) "The agent keeps recommending a feature we removed six months ago." (3) "The key instruction is right there in the prompt but the agent ignores it on long chats." Write your answers, then check them against the diagnosis table above. If you can name these by symptom, you can debug real agents.
Lesson 72 Quick Reference
Context overload

Slower, costlier, less accurate as you add context - fix by retrieving less but better (re-rank)

Context distraction

Agent fixates on irrelevant material in the window - cut the noise, enforce a relevance threshold

Context confusion

Conflicting signals make the agent waver - remove the stale or contradictory source

Stale retrieval

Confidently uses outdated info from an old index - track freshness or read current files just-in-time

Lost in the middle

Info was present but ignored because it was buried - reorder to top/bottom and shrink the block

Cost & latency failure

Right answer, too slow/expensive - set per-task token budgets and alert on overruns

Meta-fix

Almost every context bug is solved by better-targeted context, not more context

โ† Assembling Context
Unlocks in ~10 min of reading