Read our operating thesis — Machines work better in tandem
JOURNALARCHITECTURE · JULY 2026

Context engineering: the discipline that replaced prompt engineering

Prompt engineering is writing good instructions. Context engineering is deciding what occupies a finite window and what it costs — and once you understand the KV cache, prefix stability stops being a style choice and becomes an economic one.

WRITTEN BYTandem Machines
Coordinated Intelligence
PUBLISHED
READING TIME17 minutes
SHARE
LinkedInX
KEY TAKEAWAYS
  • 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

Prompt engineering is the craft of writing instructions a model follows well. Context engineering is the craft of deciding what occupies the context window — instructions, conversation history, retrieved documents, tool schemas, memory — and in what order. The first is about wording; the second is about allocation of a finite resource.

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 engineeringContext engineering
Unit of workThe instruction textThe whole window
AuthoredBy hand, word by wordAssembled at runtime
Optimises forInstruction-followingRelevance, order, and cost
Fails asThe model misunderstandsThe window fills with noise, or costs too much
Native toSingle-shot tasksAgents and multi-turn systems
THE SAME MODEL, THE SAME INSTRUCTIONS — THE DIFFERENCE IS WHAT ELSE IS IN THE WINDOW

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

A context window has a fixed size, and everything in it competes for the same space and costs the same per token. Treating it as a container to fill until full is the beginner’s error; treating it as a budget to allocate against the task is the discipline. The target is the smallest context that contains what the task needs.

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

Providers cache the computed representation of a prompt prefix — the KV cache — so a repeated prefix is not recomputed. But the cache is a prefix match: one changed byte invalidates everything after it. So the order of your context is an economic decision. Stable content first is served cheaply on later requests; volatile content first forces a full recompute every time.

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.
The same content, two orders, very different bills
# ✗ 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 FIX IS FREE — IT IS THE SAME TOKENS IN A DIFFERENT ORDER

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.

SILENT CACHE INVALIDATORS TO GREP FOR
01now() in the system promptA timestamp at position zero
02Unsorted JSONKey order varies, so the bytes vary
03Per-user tool setsTools render first; a varying set caches nothing across users
04Request IDs in instructionsUnique per call, so unique prefix per call
EACH ONE SITS EARLY IN THE PREFIX AND CHANGES EVERY REQUEST

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

Four things compete for context, with very different value density: instructions (small, stable, load-bearing), tool schemas (moderate, static), history (grows without bound), and retrieved content (largest and most variable in usefulness). Each needs a different management strategy, and confusing them is how windows fill with noise.
ConsumerSizeStrategy
InstructionsSmallKeep first, keep byte-stable, so they cache
Tool schemasModerateDefer-load when the library is large; keep the set stable
HistoryUnboundedCompact or clear as it grows; do not carry raw forever
Retrieved contentLargest, most variableFilter hard before it enters; bring back on demand, not upfront
MANAGE EACH BY ITS OWN STRATEGY — A SINGLE 'TRIM THE CONTEXT' RULE FAILS ALL FOUR

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

The most valuable context-engineering skill is deciding what to retrieve and when. Loading everything potentially relevant is expensive and lowers quality; loading too little forces the agent to guess. And the quality of what you retrieve is set upstream by how documents were split — a retrieval problem is usually a chunking problem wearing a costume.

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

Models do not attend uniformly across a long window. Information placed in the middle of a large context is recalled less reliably than the same information near the start or end, and marginal tokens can reduce answer quality rather than raise it. A full window is not a well-used window.

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 contextRecall 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

Two mechanisms keep a growing context in bounds. Compaction summarises earlier turns into a compact form when the window approaches full, preserving meaning at some fidelity cost. Context editing clears stale content — old tool results, completed reasoning — outright. Compaction keeps a lossy memory; clearing removes it. Long-running agents need both.
MechanismWhat it doesCost
CompactionSummarises earlier turns when the window fillsFidelity — detail is lost in the summary
Context editingClears stale tool results and finished reasoningThe content is gone; it cannot be referenced later
RetrievalBrings back specific detail on demandA round trip, and it has to have been stored
THE THIRD ROW IS THE ESCAPE VALVE — WHAT COMPACTION DROPS, RETRIEVAL FETCHES BACK

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

Context engineering is a small set of habits: keep the stable prefix stable so it caches, spend the window rather than filling it, retrieve on demand rather than upfront, put what matters at the edges, and compact or clear history before it dominates. None is difficult; the difficulty is remembering that the window is a budget every single request.
THE CONTEXT-ENGINEERING CHECKLIST
01Prefix stable?Cache-read tokens non-zero across similar requests
02Window spent, not filled?Every block earns its place for this task
03Retrieval on demand?A tool, not a pre-load of everything plausible
04Critical facts at the edges?Not buried in the middle of a long context
05History bounded?Compaction and clearing configured before it grows
RUN THESE AGAINST ANY AGENT WHOSE COST OR QUALITY IS DRIFTING

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

  1. 01Prompt caching Anthropic, 2026
  2. 02Context editing and compaction Anthropic, 2026
Tandem Machines
Notes on coordinated intelligence — one essay a month
Subscribe