- 01Prompt engineering optimises the words you write. Context engineering optimises everything the model sees.
- 02The window is a budget, not a container. The goal is the smallest context that holds what the task needs.
- 03Prefix stability is an economic property: a cached prefix is served cheaply, an invalidated one is recomputed in full.
- 04So a timestamp in the system prompt is not untidy — it is a line item, silently billed on every request.
- 05More context is not more quality. Attention is uneven, and the middle of a long window is where information goes to hide.
The shift, and why it happened
The discipline changed because the artefact changed. A single-shot classification prompt is something you write by hand and tune word by word — prompt engineering, done. But an agent on its tenth turn is looking at a context nobody wrote: an assembled document of prior actions, tool results, retrieved passages and a system prompt, most of it generated at runtime. You cannot word-tune a document you did not author. You can only decide what goes into it.
“You cannot hand-tune a context you did not write. Once the window is assembled at runtime, the skill stops being wording and starts being allocation.”
| Prompt engineering | Context engineering | |
|---|---|---|
| Unit of work | The instruction text | The whole window |
| Authored | By hand, word by word | Assembled at runtime |
| Optimises for | Instruction-following | Relevance, order, and cost |
| Fails as | The model misunderstands | The window fills with noise, or costs too much |
| Native to | Single-shot tasks | Agents and multi-turn systems |
This is not a claim that prompt engineering is obsolete — the instructions still have to be good. It is a claim that for any agentic system, instruction wording is now a small part of a larger problem, and the larger problem has different rules.
The window is a budget, not a container
The reframe matters because “we have a million-token window” invites the wrong instinct — fill it. But every token is paid for on every request, and, as the degradation section below shows, marginal tokens canlower quality. A large window is permission to include what matters, not an obligation to include everything.
- The allocation question
- For each request, ask of every block: does the task need this, here, now? Instructions almost always yes. Full history rarely — a summary usually serves. Ten retrieved documents when two would do, never. The window is spent, not filled.
Why prefix stability is money, not tidiness
This is the mechanism that turns a style guideline into a cost model, and it is the single most valuable thing to understand in this article. “Don’t put a timestamp in the system prompt” is not advice about cleanliness. It is advice about a recurring charge.
- KV cache
- The key-value cache holds the model’s internal representation of tokens it has already processed. On a cache hit, a repeated prefix is read rather than recomputed — dramatically cheaper and faster. The rendering order is tools, then system prompt, then messages, so a change anywhere early invalidates the cache for everything that follows.
# ✗ Volatile-first. The timestamp changes every request, so the ENTIRE
# prompt after it is recomputed every time. Cache hit rate: ~0%.
system:
Current time: 2026-07-30T14:32:07Z ← changes every request
[8,000 tokens of stable instructions] ← recomputed every request anyway
# ✓ Stable-first. The instructions are byte-identical across requests, so
# they are served from cache. Volatile content moves after the breakpoint.
system:
[8,000 tokens of stable instructions] ← cached after the first request
messages:
[conversation, with the timestamp injected HERE if needed]The diagnostic is equally concrete: the usage figures on every response report cached versus uncached input tokens. If your cache-read count is zero across requests that look identical, something in the prefix is changing — a timestamp, a session ID, a non-deterministically serialised object, a tool list that varies by user. Find it and move it after the stable prefix.
For the placement rules in full, and the economics of the different cache tiers, the mechanics are the same ones that govern why semantic caching rarely fires inside an agent loop — prefix stability is the thread connecting both.
The four consumers of the window
| Consumer | Size | Strategy |
|---|---|---|
| Instructions | Small | Keep first, keep byte-stable, so they cache |
| Tool schemas | Moderate | Defer-load when the library is large; keep the set stable |
| History | Unbounded | Compact or clear as it grows; do not carry raw forever |
| Retrieved content | Largest, most variable | Filter hard before it enters; bring back on demand, not upfront |
The order of attention should follow cost times variability, not size alone. History and retrieval are where the waste is, because they grow and because their usefulness is uneven — a retrieved passage that turned out to be irrelevant cost the same as one that answered the question.
Retrieval is the hard part, and it is upstream
Two failure modes bracket the retrieval decision. Over-retrieval fills the window with marginally-relevant passages that dilute attention and inflate cost. Under-retrieval starves the model of the fact it needed. The window between them is narrower than it looks, and it moves per task.
The deeper point is that retrieval quality is decided before retrieval runs. If your chunks break mid-argument or strip their heading context, the embeddings represent nothing precisely and no retrieval strategy recovers a good answer from them. That is why teams who “fix retrieval” by changing the vector store are usually disappointed — the problem was upstream, in the splitting, as developed in choosing the data layer.
Retrieve on demand, not upfront
The context-engineering move that most reduces both cost and noise is to give the agent retrieval as a tool rather than pre-loading documents into the window. Pre-loading pays for everything on every turn whether or not it is used; a retrieval tool pays only when the agent decides it needs something, and puts only that in the window. The tradeoff is a round trip, which is usually worth it.
Long context degrades — plan for it
This is the finding that most contradicts intuition and most changes design. The instinct behind a large window is “include more, get better answers”. The reality is a curve that rises, plateaus, and then falls as the genuinely relevant content is drowned by the merely plausible.
| Position in a long context | Recall reliability |
|---|---|
| Start (the instructions, the framing) | High |
| End (the most recent turn, the question) | High |
| Middle (buried in a long history or dump) | Lower — this is where facts hide |
The practical instructions that follow: put what matters at the edges, not the middle; prefer a short curated context to a long comprehensive one; and when a critical fact must be present, place it near the question rather than trusting the model to find it three thousand tokens back. A long context is a place to lose information, not a place to store it safely.
Compaction and clearing
| Mechanism | What it does | Cost |
|---|---|---|
| Compaction | Summarises earlier turns when the window fills | Fidelity — detail is lost in the summary |
| Context editing | Clears stale tool results and finished reasoning | The content is gone; it cannot be referenced later |
| Retrieval | Brings back specific detail on demand | A round trip, and it has to have been stored |
The three compose into the right shape for a long-running agent: clear what is definitely finished, compact what is probably finished, and rely on retrieval to recover the specific fact that turns out to matter after all. Designing that flow — what to keep verbatim, what to summarise, what to evict and re-fetch — is context engineering at its most concrete.
One handling detail worth stating because it silently breaks things: compaction returns a block the model needs on subsequent turns, so the full response content must be preserved and passed back, not just the extracted text. Dropping it loses the compaction state and the window rebuilds from scratch.
The discipline, in one page
The reason this replaced prompt engineering as the load-bearing skill is simple: for a single prompt, the words are almost everything. For an agent, the words are a small, stable header on a large, dynamic document — and the document is where the cost lives, where the quality is won or lost, and where the actual engineering is. The instructions still matter. They are just no longer the hard part.
Where this sits relative to everything else an agent needs — and why the context layer is one of seven — is laid out in the seven-layer stack.
Frequently asked questions
What is context engineering?
Context engineering is the practice of deciding what goes into a model's context window on each request, and in what order, to get the best result at the lowest cost. Where prompt engineering focuses on the wording of instructions, context engineering treats the whole window — instructions, history, retrieved data, tool schemas — as a finite resource to be allocated.
What is the difference between context engineering and prompt engineering?
Prompt engineering optimises the words you write; context engineering optimises everything the model sees, most of which you did not write by hand. As applications became agentic and multi-turn, the context stopped being a single crafted prompt and became an assembled document — history, retrieval, tool results — and managing that assembly is a different skill.
Why does the order of content in a prompt matter for cost?
Because model providers cache the computed representation of a prompt prefix, and any change to the prefix invalidates everything after it. Stable content placed first can be served from cache cheaply on later requests; volatile content placed first forces the whole prompt to be recomputed every time, which is slower and more expensive.
What is the KV cache and why does it matter for agents?
The key-value cache stores the model's internal representation of tokens it has already processed, so a repeated prefix does not have to be recomputed. For agents, whose context grows every turn with a large stable head, exploiting the cache is the difference between paying full price for the whole history each turn and paying it once.
Does putting more in the context window improve results?
Not linearly, and often not at all. Models attend unevenly across a long context and can lose information in the middle, so adding marginally relevant material can lower answer quality while raising cost. The goal is the smallest context that contains what the task needs, not the largest context the window allows.
How do you manage a context window that keeps growing?
Two mechanisms: compaction, which summarises earlier turns into a compact form when the window fills, and context editing, which clears stale tool results and completed reasoning outright. Compaction preserves meaning at some fidelity cost; clearing removes content entirely. Long-running agents usually need both, plus retrieval to bring back detail on demand.
Sources
- 01Prompt caching — Anthropic, 2026
- 02Context editing and compaction — Anthropic, 2026