systemdesign.academyAI EngineeringFree lessonsSign inGet the course
  1. Home
Previous lessonMCP Security: Tool Poisoning, Rug Pulls, and the Confused DeputyNext lessonAgent Planning: ReAct vs Plan-and-Execute

System Design

  • Foundation
  • Intermediate
  • Advanced
  • Capstone

AI Engineering

  • Foundation
  • Data, RAG and Agents
  • Evaluation, LLM Ops and Security

systemdesign.academy

  • Home
  • Glossary
  • Interview prep
  • Reviews
  • About
  • Pricing
  • Privacy
  • Terms
  • Refunds
  • Delivery
  • Contact
AI Engineering: Data, RAG and Agents
  • Agents in Production
  • Context Rot: Measuring How Long Context Degrades Your Agent
  • AI Engineering · Agents In Production

    Context Rot: Measuring How Long Context Degrades Your Agent

    Free preview: the first 2 parts of this 15-part lesson.

    Already bought the course? Sign in to read the whole lesson.

    this lesson is part of

    AI Engineering

    Unlock this lesson and the 199 other paid lessons

    • 210 lessons in 16 chapters
    • 118 lessons built on a lab that really ran
    • An AI tutor beside every lesson that answers and draws
    • Lifetime access, every new lesson included

    $49 once, by PayPal

    See the AI Engineering course

    The rest of this lesson

    1. The Middle Is Where Facts Go to Hide
    2. What Needle-in-a-Haystack Actually Tests
    3. Why Your Task Rots Before the Needle Test Says It Should
    4. Distractor Density Is a Lever, Not Just Length
    5. Recall Falls Early, and It Falls Silently
    6. Four Things This Changes About Your Agent
    7. Put the Instruction Where the Model Reads Best
    8. Prune Tool Output Before It Enters the Transcript
    9. Collapse Finished Work So It Stops Competing for Attention
    10. Measure Rot on Your Traces, Not a Vendor's Grid
    11. Budget Context Like Memory, and Do the Arithmetic
    12. What the Sources Actually Say, and What They Leave Out
    13. Knowledge Check

    read the rest of this lesson in

    AI Engineering

    Unlock this lesson and the 199 other paid lessons

    • 210 lessons in 16 chapters
    • 118 lessons built on a lab that really ran
    • An AI tutor beside every lesson that answers and draws
    • Lifetime access, every new lesson included

    $49 once, by PayPal

    See the AI Engineering course

    Continue this lesson

    in Agents In Production

    This lesson is part of the AI Engineering course. Unlock the full course, a separate one-time payment, for lifetime access.

    One-time payment. Lifetime access. No subscription.
    Global
    $49/lifetime

    One-time payment by card or PayPal

    Get Lifetime Access
    Foundation lessons free, try before you buy
    India Special
    India
    ₹999/lifetime

    One-time payment: UPI, card or netbanking

    Get Lifetime Access
    Foundation lessons free, try before you buy
    Every ML Platform lesson, Foundation to Advanced
    Real architecture diagrams with real tool logos
    MLOps, LLMOps, and data engineering in depth
    Quizzes with instant feedback
    Built and reviewed by senior engineers
    Lifetime access, all future content included

    Foundation lessons of this course are free, no payment needed. Try them now

    The 200k Window That Got Worse at 80k

    A 200k token window does not give you 200k tokens of reliable reading. Recall starts sliding well before the window is full, long before any limit is hit, and the model gets measurably worse at the thing you are paying it for: it misreads tool results, forgets facts it was given earlier in the run, and reasons more loosely. Every call still returns. The advertised window is the size of the box. It says nothing about the fraction of the box the model actually reads well.

    The instinct is to blame the prompt, or the model, or a bad tool. The real cause is more uncomfortable, because it is a property of the model you cannot prompt your way out of: a long context is not free attention. As the window fills, the model reads it worse. Retrieval accuracy falls, reasoning gets sloppier, and a fact that is present in the context can still be effectively unread. The window size on the spec sheet tells you what fits. It says nothing about the length at which the model stops using what fits.

    This lesson is about measuring that. Not the architecture of memory, which the agent memory and context lesson covers, the tiers and what to store where. This is the measurement of the degradation itself: how it depends on how full the window is, how it depends on where in the window a fact sits, why the standard long-context benchmark makes the problem look smaller than it is, and how to build an eval on your own traces that tells you the fill level past which your agent rots.

    Context Is an Attention Budget, Not a Disk

    The mistake underneath most long-context surprises is a mental model. It is tempting to treat the context window like disk: free storage up to the limit, every byte as good as any other, the only failure being overflow. Under that model the fix for any gap is always the same, add more context, and a bigger window is strictly better.

    Two-panel mental model of a context window. The wrong model treats it like disk, a grid of identical token slots where an extra token costs nothing until the box overflows, predicting a fact reads as well in a full window as an empty one. The right model treats it as a fixed attention budget split across all tokens, with a bar chart showing the attention slice per token shrinking from 33 percent at 3 tokens to 0.8 percent at 120 tokens, predicting recall falls with length even though the fact is present

    A transformer does not read context like disk. It weighs every token against every other token, so attention is a fixed pool spread across the whole input. Add a token and you have added one more thing competing for that pool. An irrelevant token is therefore not free storage. It is a small tax on the model's attention to the tokens that actually answer the question. That is the mechanism behind the whole lesson: quality falls as the window fills because the same attention is stretched over more tokens, and the ones that matter get a thinner slice.

    Hold that model and the practical advice writes itself. You do not fill the window, you spend it. A million-token window does not mean you should send a million tokens, any more than a large bank balance means you should spend all of it. What you leave out matters as much as what you put in. This is the difference between an engineer who treats the window as capacity and one who treats it as an allocation problem, and it is the frame every mitigation later in the lesson depends on.