Skip to content

Block 05 / 07

Context as the interface

The context window is the interface: its contents determine the next step.

Classical software has a request and a response. Language-model systems have a window. Everything the model can use must be tokens in that window: contract, tool schemas, retrieved evidence, dialogue, last observation. If it is not in the window, it does not exist for that hop. Context engineering is packing that interface on purpose.

Order is policy. Pin the contract first. Cache the stable prefix. Retrieve evidence per turn. Compact completed traces. Isolate untrusted text so a RAG chunk stays data. Stuffing is how you page out the schema.

Figure

Context window budget8,000Contract900, pinnedTools1,400, pinnedEvidence3,200 / 3,200History2,500 / 2,600Scratch0 / 1,100

Budget 8,000 tokens · moderate pressure, scratch is evicted and history is compacted

Drag the slider to change the token budget. Watch what gets compacted first, and what never does.

Five things compete for the same token budget: the system contract, tool schemas, retrieved evidence, conversation history, and scratch space for the current step. Contract and tools are pinned and never shrink, since without them there is no interface at all. Below the full total, tokens get cut in a fixed order: scratch first, then history is compacted toward a floor, then evidence is trimmed toward its own floor. If the budget falls below what even those floors need, the shortfall is shown directly rather than silently dropping the contract.

Algorithms

Packing the window on purpose is a set of concrete techniques, not one trick. The three below are the ones that show up in nearly every production agent.

Reference

In practice

The context window is a finite interface. Whatever the model uses on this hop must already be tokens in that window.

Laboratory

A deterministic context packer

Allocate system, tools, evidence, history, and scratch against 8K, 32K, and 128K caps. Implement a compaction order that never evicts the schema. Isolate one untrusted chunk. Cache a stable prefix (even if you only simulate the cache with a hash of the prefix). Overflow must be visible.