ALLMAcademy

S2

Context Engineering: Curate, Don't Accumulate

14 min2 optional deep dives

Treat every turn as a fresh context assembly problem: write, select, compress, and isolate.

  1. 01Apply write / select / compress / isolate under a fixed token budget
  2. 02Explain why more tokens is not better (lost-in-the-middle, context rot, cost)
  3. 03Name the four context failure modes and their matching fixes
Narration — Context Engineering: Curate, Don't Accumulate
0:00 / 0:00

The four moves of context engineering

topic 2

Context is assembled fresh each turn. Four levers:

  • Write — persist to a scratchpad / memory so state survives the step.
  • Select — retrieve only the relevant docs, tools, and examples.
  • Compress — summarize or compact history to stay small.
  • Isolate — give side-quests their own windows (sub-agents).
The context window as a finite budgetInteractive · 2D

A fixed window bar. Step 1 dumps raw history and documents — signal is buried. Selecting, then compressing, then isolating reclaim space and push the signal-density meter up.

Loading diagram…
Text description

A fixed window bar. Step 1 dumps raw history and documents — signal is buried. Selecting, then compressing, then isolating reclaim space and push the signal-density meter up.

Why more tokens ≠ better

Standard self-attention compute grows ~quadratically with length; models get lost in the middle of long inputs (Liu et al., 2023); quality rots before the hard limit; and KV/prompt caching is ~an order of magnitude cheaper on cached input only if the prefix is token-stable.

Common MisconceptionBigger window = just dump everything in.

CorrectionYou still pay quadratic cost and suffer lost-in-the-middle, rot, and distraction.

Common MisconceptionPrompt caching always saves money.

CorrectionOnly token-stable prefixes hit the cache. Volatile content (timestamps, shuffled tools) early in the prompt busts it.

The four context failure modes (Breunig)

Name the mode → know the fix

  • Poisoning — a wrong fact enters context and gets repeated. Fix: prune it.
  • Distraction — history grows until it drowns the instructions. Fix: compact.
  • Confusion — too many tools/options muddy tool choice. Fix: scope the tools.
  • Clash — contradictory retrieved chunks collide. Fix: rerank / dedupe.

Production failure modes

  • KV/prompt-cache invalidation from a volatile prefix (timestamps, reshuffled tools).
  • Context poisoning: a hallucinated fact recirculates and compounds.
  • Tool confusion from too many registered tools.
  • Stale or contradictory RAG chunks producing a clash.
References & deeper reading (2)

Retrieval Practice

Check one idea at a time

Question 1 of 2

You move from an 8K to a 200K window and stuff in every document. Mid-context accuracy drops. Best fix?