What Is Context Engineering vs. Prompt Engineering?
Context engineering manages everything an AI agent sees, memory, tools and retrieved data included. Prompt engineering only writes the instructions.

Context engineering is the practice of deciding exactly what information an AI model sees before it generates a response, not just how the instruction to it is worded. Where prompt engineering tunes a single message, context engineering manages everything else sitting in the model's context window: system instructions, tool definitions, retrieved documents, memory, and the running history of an agent's own actions. The term has spread quickly through AI engineering teams in 2026 because autonomous agents, which call tools and run for many steps, break down when that surrounding information is sloppy, even if the prompt itself is well written.
Context engineering, quickly
- Context engineering manages the full set of tokens a model sees: prompt, tools, memory, retrieved data and conversation history.
- Prompt engineering is one part of context engineering, focused only on the wording of instructions.
- Anthropic's engineering team frames it as finding the smallest set of high-signal tokens likely to produce the desired outcome.
- Core techniques include write, select, compress and isolate, a framework popularized by LangChain.
- It matters most for AI agents, which accumulate tool outputs and history across many steps and can suffer "context rot" as the window fills.
What Is Context Engineering?
Context engineering is the discipline of curating and maintaining the right information inside a large language model's context window at every step of a task, rather than treating the prompt as the only lever. Anthropic's engineering team, which published one of the most widely cited explanations of the practice, describes it as the set of strategies for "curating and maintaining the optimal set of tokens (information) during LLM inference," with the goal of finding the smallest set of high-signal tokens that makes a desired outcome likely.
That framing matters because a model's context window, the block of text it can attend to at once, is a finite and shared resource. Every system instruction, tool description, retrieved document, and prior message competes for the same limited space and for the model's attention. Context engineering is the ongoing job of deciding what goes in, what gets left out, and what gets removed once it is no longer useful.
Context Engineering vs. Prompt Engineering
Prompt engineering and context engineering are related but not the same job. Prompt engineering is the practice of wording a single instruction well: choosing phrasing, adding examples, specifying a format, or asking a model to reason step by step before answering. It treats the request as a discrete, one-time task. Context engineering is broader and ongoing. It covers the prompt, but also the tool definitions an agent can call, the documents retrieved for it, its memory of earlier steps, and the trimmed or summarized history of everything it has already done. Because an agent calls tools and re-enters the model in a loop, that surrounding information has to be curated again at every turn, not just set once.
| Aspect | Prompt Engineering | Context Engineering |
|---|---|---|
| What it manages | Wording of a single instruction or system prompt | The entire context window: prompt, tools, memory, retrieved data, history |
| When it happens | Mostly upfront, before the task starts | Continuously, at every step of an agent's run |
| Typical techniques | Few-shot examples, chain-of-thought instructions, output formatting | Retrieval, summarization, memory files, sub-agents, tool curation |
| Main risk if done poorly | Model misunderstands a single request | "Context rot," wasted attention budget, and compounding errors across a long run |
| Best suited to | Single-turn Q&A and simple generation tasks | Multi-step AI agents, long conversations, and tool-using workflows |
In short, prompt engineering asks the right question. Context engineering makes sure the model has the right information available to answer it, at every point in a longer task, not only the first one. LlamaIndex's engineering team frames the practice even more simply, describing its two central challenges as selecting the right context for a task and then fitting that context inside the model's window.
Why Agentic AI Made Context Engineering Necessary
The idea of a context window is not new, but it stayed mostly invisible to users as long as models were used for single-turn questions and answers. That changed with the rise of AI agents: systems that use a model in a loop, calling tools, reading their outputs, and deciding on a next action, sometimes across dozens or hundreds of steps. Every tool call and every result the agent reads gets added to its running context. Left unmanaged, that history grows until it crowds out the information the model actually needs.
Anthropic's engineering team calls the resulting failure pattern "context rot": as the number of tokens in a context window grows, a model's ability to accurately recall and use information from that context tends to decrease. The team attributes this partly to how transformer attention works, since every token can in principle attend to every other token, and partly to the fact that models see proportionally less training data made up of very long sequences. The result is a performance gradient, not a hard cutoff: more context does not reliably mean better answers, and past a point it can mean worse ones.
Agentic systems are especially exposed to this because they cannot simply discard their history the way a single chat turn can. An agent debugging code, researching a topic, or orchestrating other tools needs to remember earlier decisions while still leaving room to reason about its next step. That tension, long-running memory versus a limited, performance-sensitive window, is the practical reason context engineering has become its own discipline rather than an afterthought of prompt writing.
The Four Core Techniques: Write, Select, Compress, Isolate
LangChain's engineering team has proposed a widely used way to group context engineering techniques into four categories, based on patterns seen across production agents.
- Write: Save information outside the active context window so it can be retrieved later, such as a scratchpad file or a long-term memory store that persists across sessions.
- Select: Pull only the relevant pieces of saved information back into the context window when they are actually needed, rather than loading everything at once.
- Compress: Reduce what is already in the context window to the tokens that still matter, through summarization or by trimming older, less useful content.
- Isolate: Split work across separate context windows, for example by handing a sub-task to a sub-agent, so unrelated information does not crowd the main agent's working context.
These four moves map closely to the techniques Anthropic documents in practice. Compaction, where an agent summarizes a nearly full context and restarts with that summary, is a form of compress. Structured note-taking, where an agent writes a to-do list or notes file outside its context and reloads it later, is a form of write. Just-in-time retrieval, where an agent keeps lightweight references such as file paths or stored queries and loads the underlying data only when needed, is a form of select.
Memory and Retrieval: Giving Agents a Working Memory
Most context engineering guidance splits memory into two kinds. Short-term memory covers the current session, the back-and-forth of one task, and is typically managed by summarizing older exchanges or keeping only the most recent messages. Long-term memory persists facts, preferences, or project context across separate sessions, often stored in a file or database the agent can read back from later.
Retrieval-augmented generation, or RAG, is one well-established technique for bringing outside information into context without hardcoding it into the prompt. Rather than training a model on every fact it might need, the system searches a knowledge base at run time and inserts only the most relevant passages. Search infrastructure vendors such as Elastic describe several refinements that improve what gets retrieved: hybrid search that combines keyword and vector matching, chunking that keeps related text together, and reranking that re-scores a shortlist of candidates so the most useful passages land where the model is most likely to attend to them.
Anthropic's engineering team describes a related but distinct pattern it calls just-in-time retrieval: instead of embedding and loading data before a task starts, an agent keeps lightweight identifiers, such as file paths, database queries, or links, and uses tools to pull the underlying content only at the moment it is needed. This mirrors how a person works through a large codebase or filing system rather than memorizing it in advance, and it depends on the same kind of structured, tool-callable access to external context that protocols like MCP were built to standardize.
Tool Outputs and Sub-Agents
Tool definitions and their outputs are a major, easy-to-overlook source of context bloat. An agent with dozens of overlapping tools has to carry the description of every one of them in its context just to decide which to call, and a vague or duplicated set of tools can confuse an agent the same way it would confuse a person asked to choose between two similarly named options. Anthropic's guidance for building agents recommends keeping tool sets small, self-contained, and unambiguous, and clearing old tool results out of history once they are no longer relevant, which it describes as the lightest form of compaction.
Sub-agents are a more structural fix for the same problem. Instead of one agent accumulating an ever-growing history, a lead agent delegates a bounded piece of work, such as a research question, to a sub-agent that runs in its own clean context window and reports back a short, distilled summary rather than its full working history. This keeps the lead agent's context focused on coordination rather than on every intermediate step a sub-agent took to get its answer. The pattern is one reason agentic coding tools can work through large, multi-file tasks without exhausting their context window; it is also part of how systems like Claude Code manage long sessions, pairing sub-agent delegation with automatic compaction once a conversation approaches its context limit.
Common Context Engineering Failure Modes
Teams building agents have converged on a short list of ways that a poorly managed context window produces bad output, independent of how well the underlying prompt was written.
- Context rot: Recall and accuracy degrade as the context window fills, even when every individual piece of information in it is technically relevant.
- Poisoning: A hallucinated or incorrect detail enters the context early in a task and gets treated as fact in every later step, compounding the error.
- Distraction: So much accumulated history is present that the model leans on repeating past patterns instead of reasoning freshly about the current step.
- Confusion: Irrelevant or redundant information in context, such as unused tool descriptions, gets drawn into a response where it does not belong.
- Clash: Two pieces of information already in context directly contradict each other, and the model has no reliable way to decide which one to trust.
None of these are solved by rewording the prompt. They are solved by actively managing what stays in the context window and for how long, which is the core job context engineering describes.
Context Engineering in Practice
The clearest public examples of context engineering come from coding agents and research agents, because both run long, multi-step tasks where an unmanaged context window fails quickly and visibly. Agentic coding tools commonly load a small, curated project file at the start of a session, covering conventions and architecture, then explore the rest of a codebase on demand with targeted file reads and searches rather than loading every file upfront. That hybrid of some context loaded upfront and the rest fetched just in time is one of the patterns Anthropic highlights as suited to less dynamic domains, where a small set of core facts rarely changes.
The same ideas extend beyond coding. Research agents that need to explore many sources in parallel typically isolate that exploration into sub-agents and keep only condensed findings in the main thread. Long-running assistants that need to remember user preferences across sessions typically write that information to a persistent memory file rather than repeating it in every prompt. In each case, the underlying move is the same: treat the context window as a limited, actively managed resource, not a place to accumulate everything a task has ever touched.
What's Next for Context Engineering
Context engineering is still a young, fast-moving discipline, and its boundaries are not fully settled; different vendors group its techniques slightly differently, even when they agree on the underlying problem. What is consistent across the major write-ups is the direction of travel: as models get better at handling longer contexts and at deciding for themselves what information they need, the amount of manual curation an engineer has to do is expected to shrink, while the underlying judgment about what belongs in a model's context, and what does not, stays relevant. For anyone building or evaluating AI agents in 2026, understanding context engineering is becoming as basic a skill as prompt writing was a few years earlier.
Frequently asked questions
What is context engineering in AI?
Context engineering is the practice of curating and maintaining everything a large language model sees before it responds: the prompt, tool definitions, retrieved documents, memory, and conversation history. Anthropic's engineering team describes it as finding the smallest set of high-signal tokens likely to produce the desired outcome.
How is context engineering different from prompt engineering?
Prompt engineering focuses on wording a single instruction well. Context engineering is broader and ongoing: it manages the entire context window, including tools, memory, and retrieved data, and has to be curated again at every step of a multi-step agent task, not just once upfront.
Why do AI agents need context engineering?
Agents call tools and accumulate history across many steps, and that history competes for the same limited context window as everything else. Without active curation, the window fills with low-value information and the model's accuracy tends to drop, a pattern Anthropic calls context rot.
What are the four main context engineering techniques?
LangChain's engineering team groups techniques into write (saving information outside the context window), select (pulling relevant information back in when needed), compress (keeping only the tokens that still matter), and isolate (splitting work across separate context windows, such as sub-agents).
What is context rot?
Context rot is the term Anthropic's engineering team uses for the tendency of a model's recall and accuracy to decrease as the number of tokens in its context window grows, even when all of that information is technically relevant.
Does context engineering replace prompt engineering?
No. Prompt engineering is considered one part of context engineering, specifically the wording of instructions. Context engineering adds management of tools, memory, retrieval, and history around that prompt, especially for AI agents running multi-step tasks.
Sources
Theo Park runs the AI desk at Pandromeda. He follows model launches from the frontier labs and the open-weight community, tracks the assistants and developer tools built on them, and explains what each release changes on pricing, capability and safety. His reporting leans on primary sources: model cards, technical reports, API documentation and the companies' own announcements.
