Glossary // Context engineering
What Is Context Engineering? Definition, Techniques and Examples (2026)
Updated
Context engineering is the practice of deciding everything a language model sees on each call, so that the task is solvable with the fewest, most relevant tokens. That includes the system prompt, examples, tool definitions, retrieved documents, memory, conversation history, and the results of earlier steps. A model has no knowledge of your situation beyond what is in its context window; context engineering is the work of putting the right things there and keeping the wrong things out.
The term spread in June 2025. Shopify's CEO Tobi Lütke wrote that he preferred it to "prompt engineering" because it names the real skill: providing all the context for the task to be plausibly solvable by the LLM. Andrej Karpathy agreed, describing it as "the delicate art and science of filling the context window with just the right information for the next step." The shift in wording tracks a shift in practice: once models started running as agents for dozens of steps, the instruction became a small part of the input, and everything around it started to decide the outcome.
Context engineering versus prompt engineering
Prompt engineering is a subset. It is about the instruction: the role, the task, the constraints, the output format, the examples. Context engineering treats the whole window as the thing being designed, usually by code rather than by hand, and across every turn of an agent harness rather than one message.
A rough way to see the difference is to count tokens in a long agent run. The instruction might be 500 tokens. The tool definitions might be 5,000. Retrieved files, earlier tool results, and conversation history can fill the next 100,000. Rewriting the 500 matters, but most of what the model attends to is the other 99%, and that is where most agent failures start.
What goes into a context window
It helps to list the parts, because each one is a separate decision:
- Instructions. The system prompt and standing rules, such as a CLAUDE.md or AGENTS.md file in a coding agent.
- Examples. Few-shot demonstrations of the output you want.
- Tools. The names, descriptions, and schemas of every tool the model can call, including every tool from every connected MCP server.
- Retrieved knowledge. Documents, code, or records pulled in for this step (the retrieval in RAG).
- Memory. Facts carried over from earlier sessions; see agent memory.
- History. The conversation and the agent's own earlier actions and their results.
- Output contract. The format the next step or the parser expects.
Every token in that list competes for the same finite window and for the model's attention.
The four core techniques
LangChain's Lance Martin grouped the practical techniques into four moves, and most real systems use all of them:
- Write: keep information outside the window. Save plans, notes, and intermediate results to files or a scratchpad the agent can reread, instead of carrying everything in the conversation. A coding agent that keeps a running todo file and rereads it each step is doing this.
- Select: pull in only what this step needs. Retrieve the three relevant files rather than the whole repository, load memory entries that match the task, and expose only the tools the current step could use. Retrieving just in time, when the agent asks for something, usually beats loading everything up front.
- Compress: shrink what has to stay. Summarise long tool outputs before they go back in, trim old turns, and run context compaction when the window fills. Compression is lossy, so decide in advance what must survive it: the goal, constraints stated once, and exact error strings.
- Isolate: split work across separate windows. Give a subagent a narrow task and a clean context, and take back only its conclusion. The main agent never sees the twenty files the subagent read, only the answer.
How context fails
Drew Breunig named four failure modes that are worth checking against any agent that misbehaves on long tasks:
- Poisoning. A wrong fact or a hallucination enters the context and the model keeps building on it, because everything in the window looks equally true.
- Distraction. The history grows so long that the model leans on repeating earlier actions instead of reasoning about the current step.
- Confusion. Irrelevant material, such as forty tool definitions for a task that needs three, pulls the model toward the wrong tool or the wrong detail.
- Clash. Two parts of the context disagree (an old instruction and a new one, two retrieved documents) and the model picks one silently.
Underneath all four is context rot: accuracy falls as input length grows. Chroma tested 18 models in 2025 and found performance degrading with longer inputs on simple tasks, long before the advertised limits. Anthropic's engineering guide on context engineering frames the same point as an attention budget: aim for the smallest set of high-signal tokens that makes the desired outcome likely. A million-token window is a ceiling, not a target.
Untrusted text is a fifth problem. Anything an agent reads (a web page, an issue, a document) becomes part of its context, which is how prompt injection works. Treat retrieved content as data and keep it clearly separated from instructions.
Cost and the cache
Context engineering is also a cost discipline. Providers discount input tokens that repeat an earlier request's prefix: on Claude Sonnet, cached input costs $0.30 per million tokens against $3 uncached, a tenfold difference. The team behind the Manus agent called the cache hit rate the single most important metric for a production agent, and their rules follow from it: keep the start of the prompt stable (no timestamp at the top), append to the context instead of editing earlier turns, and hide unavailable tools rather than deleting their definitions mid-session, since any change early in the window invalidates the cache for everything after it.
A worked example: a data analysis agent
Take an agent that answers questions about a sales database. A naive version loads the full schema of 60 tables, every past message, and the raw output of each query. After ten questions it is slow, expensive, and starts confusing column names from different tables.
The engineered version keeps a short system prompt with the analysis rules, retrieves only the schemas of tables whose names or descriptions match the question, summarises each query result to the rows and totals that answered it, writes confirmed definitions ("active customer means an order in the last 90 days") to a notes file it rereads, and hands exploratory work to a subagent that returns one paragraph. The prompts in our Claude data analysis pack are written to slot into that structure: the profiling prompt runs once and its summary, not the raw output, stays in context.
A prompt for auditing a context window
Dump the full input your agent sends on a bad step (system prompt, tools, retrieved material, history) and run this against it:
You are auditing the context window an AI agent received on one step.
<context>[paste the full input the agent received]</context>
<task>[what the agent was supposed to do on this step]</task>
1. Estimate the share of tokens spent on instructions, tool definitions, retrieved material, memory, history, and tool results.
2. List every item the task did not need, and say whether to drop, summarise, or move it to a file the agent can read on demand.
3. List anything the task needed that is missing or buried after a large block of irrelevant text.
4. Point out contradictions between parts of the context, and any instruction-like text inside retrieved data.
5. Rewrite the context plan for this step as a short list: what to load, in what order, and what to summarise.
Run it on two or three failing steps and the pattern usually shows up quickly: too many tools, raw tool output kept verbatim, or a rule stated once at the start of a long session and lost by step forty. Measure the fix with a small eval on the same tasks before and after, since a cleaner context should show up as fewer wrong tool calls, not just a shorter prompt.
Context engineering in the news
READY TO ASCEND
Get prompt-engineering insight by email
New terms, prompt packs, and the news that changes how you prompt. No noise.
Questions
What is context engineering in simple terms?
It is deciding what goes into the model's context window, and what stays out, on every call. A prompt is one piece of that. Context engineering also covers which tools the model can see, which documents are retrieved, what memory is loaded, how much conversation history is kept, and how tool results are summarised before they go back in.
What is the difference between context engineering and prompt engineering?
Prompt engineering is writing the instruction. Context engineering is designing the whole input the instruction arrives in, usually by a system rather than by hand, and across many turns of an agent rather than one message. In a chat, the two are nearly the same thing. In an agent that runs for fifty steps, the instruction is a few hundred tokens and the rest of the window, often over 100,000 tokens, is what context engineering manages.
Who coined the term context engineering?
It spread in June 2025 when Shopify CEO Tobi Lütke wrote that he preferred it to prompt engineering because it describes the core skill better: providing all the context for the task to be plausibly solvable by the LLM. Andrej Karpathy agreed days later, calling it the delicate art and science of filling the context window with just the right information for the next step. Anthropic, LangChain, and agent builders such as Manus then published practical guides under the name.
What is context rot?
Context rot is the drop in a model's accuracy as its input gets longer, even when the task stays the same and the needed information is present. Chroma's 2025 study of 18 models found performance degrading with input length on simple retrieval and reasoning tasks, well before the advertised context limit. It is the main reason a bigger context window does not remove the need for context engineering.
Is RAG part of context engineering?
Yes. Retrieval-augmented generation is one context engineering technique: choosing which external documents enter the window for a given question. Context engineering is the broader discipline that also decides how many chunks to include, in what order and format, what memory and tool output sit next to them, and what gets dropped when the window fills.
Related terms
Glossary
Context compaction
Context compaction is when an AI agent nears its context window limit and replaces older conversation turns with a model-written summary so the session can keep going.
Glossary
Agent memory
Agent memory is the information an AI agent stores outside its context window, in files, databases, or indexes, and reads back later so it can remember across steps and sessions.
Glossary
MCP (Model Context Protocol)
MCP, the Model Context Protocol, is an open standard for connecting AI applications to tools, data, and prompt templates, so one server works in any app that speaks the protocol.
Prompt packs for this
Coding // Claude
Best Claude Prompts for Coding (2026)
13 Claude prompts for coding in 2026: debugging, refactoring, adversarial review, failing-test-first fixes, flaky tests, and instructions for Claude Code agent runs.
Data Analysis // Claude
Best Claude Prompts for Data Analysis: 20 Copy-Paste Templates (2026)
The best Claude prompts for data analysis, as 20 copy-paste templates: SQL against a long schema, CSV profiling and cleaning, trend and cohort reads, significance checks, and stakeholder summaries. Copy, fill the brackets, run.
Agent Reliability // Claude
Silent Agent Failures: 8 Failure Modes and 10 Prompts to Catch Them (2026)
Silent agent failures (silent failures in AI agents) are runs that end in success while the work is wrong. The 8 failure modes behind them, the trace checks that catch them, and 10 prompts for reviewing agent transcripts.