Order these context elements from first to evict to never-evict when the budget tightens
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Evict consumed content first (stale tool results), then dilution (extra chunks), then content already preserved at a higher level (covered summaries), then the rolling summary, then recent turns.
Picture cleaning out a backpack before a trip when it is too heavy. First you throw out the trash you already used, like empty wrappers from snacks you ate. Next you take out the extra bottles of water when you have enough, because they are nice but not needed. Then you take out the old notes you have already copied into a clean summary, because the summary covers them. Then the summary itself, if it is still too heavy. Then some of the recent letters you wrote, only if it gets really desperate. The map and the trip itinerary stay no matter what, because without them you would not even know where you are going. That last pair is the system prompt and the current question.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
4 minutes: state the seven tiers in order, name the two sacred ones, explain why summary evicts before recent verbatim turns, and call out output token reservation as the precondition.
| Tier | What lives here | When it gets evicted |
|---|---|---|
| 1 (first out) | Stale consumed tool results | Almost immediately under any pressure |
| 2 | Retrieved chunks below top-3 | When retrieval is over-fetching |
| 3 | Level-1 summaries covered by level-2 | When the hierarchy has rolled forward |
| 4 | Rolling summary block | When the verbatim recent turns are more valuable |
| 5 | Recent verbatim turns (oldest first) | Only when truly desperate |
| 6 (sacred) | Current user turn | Never; reject the request instead |
| 7 (sacred) | System prompt and tool defs | Never; the agent is not the agent without it |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Evicting recent verbatim turns before the rolling summary. The summary is the duplicate; the recent turns are the original. Evict the lossy abstraction first when forced.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.