By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
On Tuesday, the support agent handled a refund correctly. On Thursday, it approved $349 without asking for approval. No code changed, no prompt line changed, and the model did not change. The only difference was that Thursday's session ran longer. The rule that caps a refund at $200 ended up 11,000 tokens away from the question.
That gap is a context problem, not a wording problem. Rewriting the sentence fixes the wrong thing, and the failure returns next week.
A context window is the maximum amount of text, measured in tokens, that one request can carry. A token is a fragment of a word; as a rough guide, 1,000 tokens is about 750 English words. Everything shares that budget: the system prompt, the examples, retrieved documents, tool results, earlier turns and the current question.
Most teams track the total and stop there. The useful number is the split, because some layers are fixed and others grow on their own.
| Layer | Grows per turn? | Harm when oversized |
|---|---|---|
| System prompt | No | Almost none. This is the layer worth protecting. |
| Few-shot examples | No | Cost, plus attention spent on text that only shows format. |
| Retrieved documents | Yes, when you re-retrieve | Competes with the rule and adds text that may not apply. |
| Tool results | Yes, sharply | Raw payloads crowd out decisions and facts. |
| Earlier turns | Yes, on every turn | Old mistakes get read as established fact. |
| Current question | No | If it is tiny, the model barely sees what you asked. |
Drift means behaviour that slowly moves away from the instruction you set. The model is not ignoring you. It is reading a lot of newer, more specific text, and that text competes with your rule.
Two forces drive it. The first is distance: a rule 10,000 tokens back has 10,000 tokens of newer material between it and the question. The second is accumulation: once an earlier turn states something as fact, later turns read it as settled, even when it was a guess.
Drift has a signature. The model starts precise and ends vague, repeats a phrase from earlier, or answers the question from three turns ago.
The transcript below is short enough to read in two minutes. Read it once without stopping, then look at the two marked lines.
# Northwind Supply support agent, one session, 14 turns.
# Token counts are approximate, as a tokenizer reports them.
[system 910] You are a support agent for Northwind Supply.
Refunds over $200 need a human approver.
Never promise a delivery date.
[turn 1 user 41] My order A-4471 arrived damaged. I want a full refund.
[turn 2 tool 1880] get_order({"id": "A-4471"})
-> full record: 38 fields, nested items, address, carrier
[turn 3 asst 96] I am sorry. Let me check the damaged-goods policy.
[turn 4 tool 2140] search_policy({"topic": "damaged goods"})
-> nine paragraphs of policy prose
[turn 5 asst 180] Damaged goods qualify for a refund or a replacement.
[turn 6 user 62] A refund. The vase was a gift and it is cracked.
[turn 7 tool 4100] get_customer({"id": "C-88"})
-> 41 past orders, loyalty notes, three open tickets
[turn 8 asst 140] You have been with us since 2019. I am sorry about it.
[turn 9 user 55] I want the full amount back today.
[turn 10 tool 3600] get_shipping_status({"id": "A-4471"})
-> carrier events, 22 scan records, exception codes
[turn 11 asst 210] I can refund the full $349 to your card now.
^ DRIFT: the $200 cap is now 11,000 tokens back
[turn 12 user 34] Great, do it.
[turn 13 asst 88] Refund issued.
^ no approval step, no escalation
[turn 14 -- 0] nothing was ever inserted to remind the modelThe rule never changed. It moved. By turn 11, the newest sentence about money is the customer saying 'I want the full amount back'. The model follows the nearest strong signal. The tool results, which hold no rule at all, take 87% of the window.
Bloat means tokens spent on text that cannot change the answer. Three sources dominate.
The third one is your bug. If attempt one returned malformed JSON, sending it plus a correction gives the model two objects and no reason to prefer either. Replace the attempt; do not stack it.
You cannot prune a layer you have not counted. Count tokens per layer for one real session. Approximate counts are enough, because the ranking is the point.
BUDGET = 13_000
session = {
"system": 910,
"tool_results": 11_720,
"assistant": 714,
"user": 192,
}
total = sum(session.values())
for name, tokens in sorted(session.items(), key=lambda item: -item[1]):
print(f"{name:<13}{tokens:>7} {100 * tokens / total:>5.1f}%")
print(f"{'total':<13}{total:>7} {100 * total / BUDGET:>5.1f}% of BUDGET")Tool results take 86.6% of the tokens here and the model's own words take 5.3%. Prune a tool result first; compacting the conversation would free almost nothing.
Take the longest agent session you can find from the last month. Count tokens for each layer and write the four-line split, the way the snippet above does. Then answer two questions in one sentence each. Which layer could lose half its tokens without losing a single decision? Which sentence in the session must never be removed?
Key takeaways
A context window is a budget; the split between layers matters more than the total.
Drift is distance: newer, more specific text competes with the rule you set.
Bloat comes from raw tool output, re-retrieved documents and retries you appended.
Measure tokens per layer before you prune anything.
Truncating the oldest turns drops the rule and keeps the biggest payloads.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.