Article · Context engineering
What is context engineering?
Context engineering is choosing what a language model sees at each step: its instructions, the records it retrieves, the results of its tools and what it remembers. It also decides what stays out. A model works only with what is in its context window, and a fuller window is not a better one.
In short
Context engineering decides, for every call to a language model, which tokens it gets to read. Those tokens are the system instructions and the tool definitions. They are also the records a search returned, earlier tool results, notes the model kept and the conversation so far.
Prompt engineering is one part of it: writing the instruction well. Retrieval is another part: finding the records that might matter. Context engineering is the decision between them. Which of those records go in, in what form, next to what, and which earlier material is taken out again to make room.
From prompts to context
The term spread in June 2025. Simon Willison collected the posts that started it. Shopify’s Tobi Lutke liked that it names “the art of providing all the context for the task to be plausibly solvable by the LLM.”
The change in name follows a change in the work. A prompt for a single answer is written once. An agent runs in a loop: it calls a tool, reads the result and calls another, and each turn adds to what the model sees. The question stops being how to phrase the request. It becomes what the model should be looking at on turn 12.
Anthropic’s engineering team describes context engineering as what prompt engineering grows into once models work over many turns. Its guiding rule is to “find the smallest set of high-signal tokens that maximize the likelihood of your desired outcome.”
What competes for the window
Every model has a context window: a limit, in tokens, on what one call can read. Everything below shares it, on every call:
- Instructions: the system prompt, and the rules that hold for this task.
- Tool definitions: each tool’s name, description and parameters, sent whether or not the tool is used.
- Retrieved records: tickets, part records, supplier notices, pages of a manual.
- Tool results: what each call returned, from the first turn on.
- Memory: notes the model wrote earlier, or facts kept from past conversations.
- History: the person’s messages and the model’s own replies.
Each of these is a decision someone made, or forgot to make. A tool result left in the history after it was used still takes room on every later call.
How it works
One step, one window
A service engineer asks a question. Search finds far more than the model should read. Pick a step to stop the drawing and read it.
- 01
A question arrives
A service engineer asks whether pump P-7 has failed this way before. The window holds the instructions and the question.
- 02
Check access first
Search finds 40 tickets. 12 belong to teams the engineer is not on, so they never reach the model.
- 03
Keep what answers
Of the 28 left, 3 go in, as ids and short summaries. The rest stay in the graph.
- 04
Names, not bodies
Six skills go in as a name and one line each. A body is read only when the model asks for it.
- 05
The model answers
It answers from the ticket that matched and cites it. Nothing it did not need took up room.
Why more context is not better
Context windows now reach millions of tokens, so it is tempting to send everything. Chroma tested 18 models in July 2025 on tasks kept simple on purpose, changing only the length of the input. In one test the models answered questions about a long chat history. Given only the relevant parts, about 300 tokens, every model did markedly better than with the full history of about 113,000 tokens. The report found that performance “grows increasingly unreliable as input length grows.”
Position matters too. Liu and coauthors showed in 2023 that models use information best at the start or end of a long input. They use it worst in the middle. Anthropic’s post calls the general effect context rot: every added token draws on the model’s limited attention.
There is a plain cost as well. Every token in the window is sent again on every call of the loop, so a crowded window costs something on every turn.
The techniques that work
- Retrieve late, by reference. Keep ids, paths and queries in context, and let the model fetch a record when it needs it. Anthropic calls this just in time context.
- Return less from tools. A tool that returns ids and a few fields leaves room. A tool that returns a whole document fills the window with text the model may never use.
- Disclose step by step. Give the model names and one line descriptions up front, and the full text only when it asks.
- Compact long runs. Near the limit, clear old tool results and replace the history with a summary. Keep the latest result.
- Keep notes outside the window. The model writes progress to a file or a record and reads it back after a reset.
- Split the work. A sub-agent explores in a window of its own and hands back a short summary. Anthropic reports those summaries are often 1,000 to 2,000 tokens.
Over a long task
Filling up, then compacting
Each turn of an agent adds to the window. Compaction clears what the model has already used and keeps a summary in its place.
- 01
The window starts small
The instructions, the task and the result of one search.
- 02
Each turn adds to it
A second tool call and its result. Earlier results stay unless something removes them.
- 03
Near the limit
After three turns the window is almost full, mostly with results the model has already read.
- 04
Compact it
Old tool results are cleared, and the history becomes a short summary. The latest result stays.
- 05
Room to go on
The fourth turn runs with the summary, the latest result and room for the next step.
How it goes wrong
- Everything goes in. The answer was in the window, in the middle of 40 near matches, and the model picked a near match.
- Records the person may not open. Whatever is in the window can end up in the answer. The access check belongs before a record is added, which is what permission-aware retrieval means.
- Text read as orders. A ticket or a file in the window can carry instructions, and the model reads them like any other text. That is prompt injection.
- Stale memory. A note kept from last month states a fact that has since changed, with nothing to say when it was written.
- Compaction that loses the point. A summary drops the one detail that mattered three turns later.
- Overlapping tools. Two tools that do nearly the same thing cost room in every call and leave the model unsure which to use.
How to evaluate it
Six questions, asked of a real run rather than a demo:
- Can you see the exact context of any call: every instruction, record and tool result the model read?
- How much of that context did the answer use?
- Was every record in it one the person asking may open, checked before it went in?
- What happens at the limit: an error, silent truncation, or a summary you can read?
- Do tool results return ids and short fields, or whole documents?
- Does every remembered fact say where it came from and when?
The answers depend on the data underneath. A model can only be handed the right three records if something already knows which records relate to the question. That is the job of a context graph.
How Curiosity handles it
Curiosity Studio starts from records connected in one typed graph, from more than 70 systems, with the access rights of their source. The built in search and read tools run as the person who asked, so a record they may not open never reaches the window.
Skills follow the step by step pattern. The documentation describes how an assistant is told each skill’s name and one line description up front. It reads the body only when it needs it. The agent loop guide suggests tools that return ids and short fields rather than whole documents, and fewer than about 10 tools per agent.
The model is a setting, from any of the providers Studio supports. Each provider declares its context window. The chat uses it to decide how much history and context to send, as the custom provider page describes. The AI agents page has the developer view.
References
Sources and further reading
Effective context engineering for AI agents
Anthropic · September 2025
Context as a finite resource, and the techniques for long tasks: compaction, notes and sub-agents.
ReadContext engineering
Simon Willison · June 2025
Where the term came from, with Tobi Lutke’s and Andrej Karpathy’s posts.
ReadContext Rot: How Increasing Input Tokens Impacts LLM Performance
Kelly Hong, Anton Troynikov and Jeff Huber, Chroma · July 2025
Eighteen models tested on simple tasks, losing reliability as only the input length grows.
ReadLost in the Middle: How Language Models Use Long Contexts
Nelson F. Liu et al. · TACL 2023
Models use information best at the start or end of a long input, worst in the middle.
ReadSkills
Curiosity documentation
How an assistant is told each skill’s name up front and reads its body on demand.
ReadThe agent loop
Curiosity documentation
Keeping the loop tight: fewer tools, short tool results, a cap on turns.
ReadCustom Code LLM Provider
Curiosity documentation
The context limit a provider declares, which the chat uses to decide what to send.
ReadFAQ
Questions people ask
What is the difference between prompt engineering and context engineering?
Prompt engineering is writing the instruction. Context engineering decides everything the model reads on each call: instructions, tool definitions, retrieved records, tool results, memory and history. It matters most for agents, whose context changes with every turn.
Is a bigger context window better?
A bigger window raises the limit, not the quality. Studies such as Chroma’s 2025 report found models less reliable as the input grows, even on simple tasks. A small window holding the right records usually beats a large one holding everything.
What is context rot?
The loss of accuracy as a model’s context grows: the more tokens in the window, the worse the model recalls and uses what is in it. Anthropic uses the term, and Chroma measured the effect across 18 models in July 2025.
What is compaction in an AI agent?
Clearing what a long run no longer needs, such as old tool results, and replacing the history with a summary when the context window is nearly full. The agent then continues with the summary and its latest results.
Articles
Read next
What is a context graph?
Context graphs
Two meanings of a new term, decision traces and a permission-aware graph of records, where they meet, and where a knowledge graph ends.
ReadWhat is an AI agent?
AI agents
The loop an agent runs, how it differs from a workflow, and what an enterprise agent needs before it touches real records.
ReadWhat is permission-aware retrieval?
Permissions
Why an assistant may only read what the person asking may open, where the access check belongs, and how permissions go stale.
ReadYour data. Your infrastructure.