The term replaced “prompt engineering” for a reason. A prompt is a static string. Context is everything the model sees on a given turn — system instructions, tool definitions, retrieved documents, history, tool outputs, memory — and in an agent you decide all of it again, every single turn.
Your agent is on turn thirty. The system prompt is still in the request. So is every tool schema, every document it retrieved back on turn four, and every tool result since. You are paying for the whole lot again, right now, on this turn.
That picture is the lesson. Context is a budget you re-pay every turn, not a container you fill once.
Anthropic’s definition is the one to use out loud. Context engineering is the set of strategies for curating and maintaining the optimal set of tokens during inference, including everything that lands there outside the prompt. The shift from “write a good prompt” to “decide what is in the window this turn” is the whole discipline.
Two claims carry the rest of the lesson. The first is arithmetic. The message array is rebuilt and resent on every turn. So context is a recurring cost with a slope, not a one-off allocation.
The second is measured. Model quality falls as input grows, and it falls well before the advertised window is full. A large window is a capacity spec. It is not a performance guarantee.
Each band is one request, drawn against a 200,000-token window, in the order the prefix is assembled: tools, then system, then messages. Nothing in the allocation changes between rows. Select a turn for what has happened to it by then.
The allocation never changes. Between turn 1 and turn 30 the share of the request that never changes falls from 72% to 38%, and the headroom falls from 119,500 tokens to 47,000. You did not do anything. You just kept going.
Two things here are hard to feel from prose. That is what the allocator below is for.
First, the front of the request and the back of it have different prices. A cache read bills at 0.1× base input tokens. Put a token in the wrong half and it costs ten times what it needed to.
Second, history is a slope. The allocation that feels fine at turn five is over the window at turn thirty. You can work out the turn it dies on in advance, rather than finding out during an incident.
Drag the allocations. The system prompt and tool schemas form the stable prefix, which a cache read bills at 0.1×; retrieved documents and history sit after the last breakpoint and bill in full. Everything is in billed input-token equivalents, so the numbers survive a price change.
Tool definitions are 12k tokens. The documented threshold for deferred loading is ten thousand tokens or thirty-plus tools — and selection accuracy degrades past roughly thirty to fifty tools regardless of cost.
The prefix is the cheap half only while it stays byte-identical. A timestamp in the system prompt, a tool list whose order varies, or JSON serialised without sorted keys moves every turn from the solid line to the dashed one — at this allocation, 1.4× the billed input, for a change nobody will spot in review.
tools parameter — names, descriptions and schemas — counts as input tokens, and so does every tool_use and tool_result block. Deleting an unused tool saves money and improves accuracy at the same time.The study to know is Chroma’s, and it is worth quoting exactly, because the headline usually gets mangled. Hong, Troynikov and Huber evaluated eighteen models in July 2025. They found that “models do not use their context uniformly; instead, their performance grows increasingly unreliable as input length grows”.
That is the sentence. It is not a cliff at a particular token count. Anyone quoting a specific percentage drop at a specific length is quoting something the report does not say.
Underneath the headline are three findings that change engineering decisions.
Distractors. Content that is semantically similar but irrelevant actively misleads, and a single distractor already reduced performance relative to the needle-only baseline. Four of them compounded it.
Similarity. Performance degraded faster at long inputs when the needle — the passage that holds the answer — was less similar to the question. So ambiguity and length multiply rather than add.
Focus. On LongMemEval, every model did significantly better on focused prompts than on full ones containing the same answer. Retrieving more can be worse than retrieving less.
Position is the other variable, and it has been known since 2023. Liu et al.’s Lost in the Middle found performance is highest when the relevant information sits at the beginning or the end of the context. It “significantly degrades when models must access relevant information in the middle of long contexts”.
So where you put a fact decides whether it gets used. That makes assembly order an engineering decision rather than an implementation detail.
The mechanism underneath all of this is dull. Transformer attention relates every token to every other token, so n tokens create n² pairwise relationships. The same attention gets spread thinner as the context grows. A larger window does not change that sum. It only raises the ceiling on how thin you are allowed to spread it.
Caching is a prefix match. Change one byte early in the request and everything after it is thrown away. The prefix is assembled in the order tools → system → messages, with up to four breakpoints. A change at one level invalidates that level and all the levels after it.
The prices decide the rest. Cache reads bill at 0.1× base input. Five-minute writes bill at 1.25×, one-hour writes at 2×. So the whole game is keeping stable content first and putting the varying question after the last breakpoint.
The Manus team, building a widely-used agent product, named KV-cache hit rate “the single most important metric for a production-stage AI agent”. Their average input-to-output token ratio was about 100:1.
That ratio is the reason. In an agent loop you are overwhelmingly paying to re-read, not to generate. So optimise the re-reading.
from datetime import datetime, timezone
import json
# BREAKS THE CACHE ON EVERY SINGLE TURN
system = f"You are an ops agent. Time: {datetime.now()}"
# ALSO BREAKS IT: a tool list whose order varies. Insertion order
# is not stable if plugins register concurrently, and tools sit at
# the very head of the prefix - so this invalidates everything.
tools = list(registry.values())
# ALSO BREAKS IT: unsorted JSON anywhere in the prefix.
context = json.dumps(config)
# FIXED: stable prefix, varying content after the breakpoint.
system = "You are an ops agent."
tools = sorted(registry.values(), key=lambda t: t["name"])
context = json.dumps(config, sort_keys=True)
now = datetime.now(timezone.utc).isoformat()
messages = [{
"role": "user",
"content": f"Current time: {now}\n\n{question}",
}]
# Verify from usage, never from code review. On a warm loop,
# cache_read_input_tokens should dominate, and cache creation
# should be roughly one turn's worth - not the whole conversation.
print(response.usage)Three techniques, solving three different problems.
Compaction takes a conversation nearing the limit, summarises it, and starts a fresh window from that summary. Keep the architectural decisions and the unresolved threads; drop the redundant tool output. One implementation detail bites people: append the full response content back, not just the extracted text. Get that wrong and you lose the compaction state, with no error to tell you.
Structured note-taking keeps state outside the window and re-reads it. A todo file survives a context reset. A conversation does not.
Manus describe the file system as “the ultimate context… unlimited in size, persistent by nature, and directly operable by the agent itself”. That lets an agent drop a page’s contents from the window while keeping the URL that can fetch it again. It is what allows a goal to survive thousands of steps and multiple resets.
Sub-agent isolation spawns a clean context for one focused piece of work and returns a condensed summary. Anthropic put those summaries at 1,000–2,000 tokens. The coordinator ends up holding conclusions rather than the exploration that produced them.
So parallelism here is a context-management strategy first and a speed strategy second. That framing is what makes it defensible rather than fashionable.
Context editing is a window tool, not a savings lever. The clear_tool_uses strategy defaults to a trigger of 100,000 input tokens and keeps the last three tool uses. The documentation is explicit that clearing “invalidates cached prompt prefixes” and that “you’ll incur cache write costs each time content is cleared” — hence the clear_at_least parameter. So set the trigger high and clear in a few large batches. I have not found a published measurement of the net effect, so treat the magnitude as unquantified: the mechanism is documented, the size of the win is not.
The cheapest item on this list has the best return of anything in this curriculum. The most sophisticated one is a genuine mistake at seed. What separates them is not effort. It is whether you actually have the failure the control prevents.
Nearly all guidance on this topic is written for one company size and then read by everyone. Pick yours — the list re-sorts, and what you should deliberately not build drops to the bottom.
No timestamps in the system prompt, tool lists sorted deterministically, JSON serialised with sorted keys, and the varying question after the last breakpoint.
At this stage · Same changes, now verified from the API's usage numbers rather than from code review — on a warm loop, cache reads should dominate input tokens.
Cache read and cache creation tokens tracked per agent, per version, alongside latency and cost.
At this stage · Now a real chart. A step change in cache creation tokens is the fastest way to detect that someone put a variable into the prefix — usually within an hour rather than at the end of the month.
How many tokens a turn costs at turn 5 and at turn 30, and the turn at which the allocation stops fitting.
At this stage · Per agent, checked when the allocation changes. Teams that cannot answer the turn-30 question are usually paying a growing bill without noticing.
A file, a todo list or a store the agent reads and writes, so a goal survives a context reset.
At this stage · Now structured, because it is what lets an agent hold a goal across resets rather than across turns — a different and more durable property than a longer window.
Summarise the conversation as it nears the limit and reinitialise on the summary, preserving decisions and open threads.
At this stage · Truncate the oldest tool results and say so in the placeholder. That is most of the benefit without a summarisation model in the critical path.
Nothing is optional at this stage. That is itself the finding — the cost of the control set is part of the cost of operating here.
Digital Green and Microsoft Research’s Farmer.Chat served over 15,000 smallholder farmers and answered more than 300,000 queries across four countries. Two things make the paper unusual. It publishes its retrieval quality — average context precision of 71%, meaning roughly three in ten retrieved passages were not relevant to the question. And rather than reporting one accuracy number, it classifies its own failures: of the unanswered quarter, 66% were content gaps, 23% out of context, 11% out of collection.
Read that 71% next to the distractor finding above and the engineering lesson is sharp. Those irrelevant passages are not neutral filler. Each one is a distractor, competing for attention with the passage that holds the answer, and a single distractor measurably costs you. Context precision is therefore a context-engineering metric before it is a retrieval one. The classified failure breakdown is what makes it actionable: a content gap is a corpus problem, out-of-context is a routing problem, and only the middle one is fixed by a better retriever. Most teams report neither number and debate the model instead.
The array is rebuilt and resent every turn, so a token added at turn three is paid for at every turn after it. Know what a turn costs at turn 5 and at turn 30, and the turn at which your allocation stops fitting.
Across eighteen models, performance grows increasingly unreliable as input grows — well below the advertised limit, faster on multi-hop reasoning than on retrieval, and worse when semantically similar distractors are present. A single distractor already costs you.
Cache reads bill at a tenth of base input, and the prefix is assembled tools → system → messages. A timestamp in the system prompt, an unsorted tool list or unsorted JSON moves the whole conversation to full price, and it does it invisibly. Verify from usage numbers, never from code review.
Compaction for the window, notes on disk for the goal, sub-agents for the exploration — the coordinator should hold conclusions, not the work that produced them. Clearing tool results is a window tool, not a savings lever: it rewrites the cached prefix each time.
Primary sources wherever one exists. Where a claim is contested or vendor-reported, the lesson says so at the point it is made.
Hong, Troynikov and Huber. Eighteen models: “models do not use their context uniformly; instead, their performance grows increasingly unreliable as input length grows”. The distractor result is the practically useful one — a single distractor already costs you, and four compound it.
Liu et al., 2023. Performance is highest when the relevant information is at the beginning or end of the context and “significantly degrades when models must access relevant information in the middle”. Position is an engineering variable, not an accident of assembly order.
Singh et al., Digital Green and Microsoft Research, September 2024. The rare deployment paper that publishes its retrieval quality — 71% average context precision — and then classifies its own failures rather than reporting a single accuracy number.
The definition worth using out loud: curating and maintaining the optimal set of tokens during inference, including everything that lands there outside the prompt. Also the mechanism — transformer attention creates n² pairwise relationships for n tokens — and the three long-horizon techniques, with sub-agents returning 1,000–2,000 tokens.
Yichao 'Peak' Ji. “The KV-cache hit rate is the single most important metric for a production-stage AI agent”, on an average input-to-output ratio of about 100:1. Also the two silent cache killers — a timestamp at the head of the prompt, and unstable JSON key ordering.
Measured context savings rather than asserted ones: 58 tools across five MCP servers is roughly 55K tokens before the conversation starts, and programmatic tool calling took average usage from 43,588 to 27,297 tokens on complex research tasks.
The arithmetic behind the allocator: cache reads bill at 0.1× base input, five-minute writes at 1.25× and one-hour writes at 2×. The prefix is built tools → system → messages, up to four breakpoints, and a change at one level invalidates that level and everything after it.
The lever the allocator's tool-schema slider represents. A typical five-server setup costs ~55k tokens in definitions before any work happens; deferred loading typically removes over 85% of that while keeping caching intact, because deferred definitions never enter the prefix.
clear_tool_uses_20250919, with a default trigger of 100,000 input tokens and keep of 3. The sentence that matters: clearing “invalidates cached prompt prefixes”, so “you'll incur cache write costs each time content is cleared” — hence clear_at_least, and hence batching.
The pricing section states it plainly: the tools parameter — names, descriptions and schemas — is billed as input tokens, alongside every tool_use and tool_result block. A tool nobody calls is still charged on every turn of every run.