Key Takeaways
Context engineering is the practice of designing everything an AI model sees at inference — not just the prompt, but its tools, memory, and retrieved data. The same model gives wildly different answers depending on what fills its context window and how. Anthropic frames it as managing a finite ‘attention budget,’ while Drew Breunig maps the four ways context breaks down. This guide walks through the core idea and the Write-Select-Compress-Isolate playbook from scratch.
- Transformers compute n² relationships for n tokens, so the “attention budget” drains fast (Anthropic)
- Four failure modes break context: poisoning, distraction, confusion, and clash (Drew Breunig)
- Four strategies fix it: Write, Select, Compress, and Isolate (LangChain)
- The goal is the smallest set of high-signal tokens — not a context window stuffed to the brim
Ask an AI chatbot the same question twice and you may get a sharp answer once and nonsense the next. The model didn’t change between the two tries. What changed is what sat inside its context window at that moment — and shaping that is the job of context engineering. This is the discipline of deciding what an AI agent knows before it acts, and in 2026 it has quietly become the skill that separates agents that work from agents that flail.
Through 2025, a phrase kept circulating in engineering circles: prompt engineering is dead, long live context engineering. That’s an overstatement, but the direction is right. Teams building autonomous agents learned the hard way that polishing a clever prompt does almost nothing once the model is juggling tools, documents, and a sprawling history.
This guide explains context engineering for AI agents from the ground up: what it is, why context degrades, and the concrete strategies practitioners use to fix it. You don’t need to write code to follow along — by the end, you’ll understand why your company’s chatbot keeps hallucinating, and where to look first.

Why Prompt Engineering Hit a Wall
A few years ago, the marquee AI skill was prompt engineering. Phrase the question well and the answer improved dramatically. Adding a single line like “think step by step” could lift performance on its own.
That worked because the model saw only a tiny slice of text: your instruction. The trouble began when AI stopped answering one-off questions and started operating as an agent. An agent plans multiple steps, calls tools, and pulls in prior turns, documents, and search results as it goes. The payload feeding the model is no longer a one-line query — it’s a sprawling bundle of tens or even hundreds of thousands of tokens.
Andrej Karpathy captured the shift when he described context engineering as “the delicate art and science of filling the context window with just the right information for the next step.” The center of gravity moved from the question to the composition of the window itself. Prompting is still part of that composition, but it is now one layer inside a much larger problem.
So is prompt engineering dead? Not at all. It survives as a component — the instruction layer — inside the broader task of assembling context. That is precisely why Karpathy and Anthropic both describe it as the superset that contains prompt engineering, rather than its replacement.
AI Agent vs Chatbot vs LLM: The 2026 Complete Guide
What Context Engineering Is: The Attention Budget
Anthropic defines context engineering as curating and maintaining the optimal set of tokens a model sees during inference — system instructions, tools, external data, and message history all included. Where prompting asks “what should I tell the model,” context engineering asks “what does the model need to know to do this well.”
Why does that composition matter so much? Because of a hard constraint baked into the Transformer architecture. A Transformer computes relationships between every pair of tokens, which means n tokens create n² pairwise relationships. Double the tokens and you quadruple the work the model must spread its focus across.
Anthropic calls the consequence an “attention budget.” A model has a finite amount of attention to allocate on any given pass, and every token you push into the window spends a little more of it. The context window is not an infinite filing cabinet — it is a scarce resource that depletes with use.
Here is the counterintuitive part: a bigger context window is not automatically better. Anthropic points to “context rot” — the tendency for retrieval accuracy to decline as the window grows. It isn’t a sudden cliff. It’s a gradual erosion of precision the longer the context runs.

How Context Breaks: The Four Failure Modes
If context is a finite resource, how exactly does it get wasted or poisoned? Developer Drew Breunig sorted the ways long contexts fail into four categories: poisoning, distraction, confusion, and clash. Each one has a concrete, measured example behind it.
The first is context poisoning. A hallucination or error slips into the context and then gets referenced again and again on later steps, corrupting the model’s judgment. Breunig’s example is Gemini 2.5 playing Pokémon: a misread game state got etched into the agent’s “goals” section, and the agent began fixating on objectives that were impossible to achieve.
The second is context distraction. When the context grows too long, the model over-indexes on that history and neglects what it learned during training. Gemini 2.5 Pro supports a million-token window, yet in the Pokémon setup it began repeating past actions instead of forming new plans once it crossed roughly 100,000 tokens. A separate Databricks study found the accuracy of Llama 3.1 405b starting to slip at around 32,000 tokens.
The third is context confusion. Irrelevant material sits in the context and the model uses it anyway, dragging answer quality down. On the Berkeley Function-Calling Leaderboard, every model performed worse once it was handed more than one tool. In the GeoEngine benchmark, a quantized Llama 3.1 8b failed with 46 tools available — even though they fit inside a 16k window — but succeeded once the list was trimmed to 19.
The fourth is context clash. Conflicting information or tools pile up and the model loses the thread. A Microsoft and Salesforce study delivered the same information in “sharded” pieces across several messages instead of all at once. Performance dropped by an average of 39%, and OpenAI’s o3 fell from 98.1 to 64.1.
The common thread is uncomfortable but clarifying. In all four modes, adding more to the context actively hurt the model. What matters is not the volume of information but the signal-to-noise ratio — the same reason capable agents ace benchmarks yet crumble in the real world.
| Failure mode | What goes wrong | Measured example |
|---|---|---|
| Poisoning | An error lodges in context and is cited repeatedly | Gemini 2.5 Pokémon — fixated on impossible goals |
| Distraction | Over-indexing on a long history, ignoring training | Gemini 2.5 Pro slips past ~100k / Llama 405b at ~32k |
| Confusion | Superfluous info and tools get used anyway | Trimming 46→19 tools flipped failure to success (GeoEngine) |
| Clash | Conflicting information accumulates | Sharded delivery: -39% average, o3 98.1→64.1 |
AI Agent Benchmarks Are Breaking in 2026

The Four Strategies: Write, Select, Compress, Isolate
Now the fix. LangChain organizes the field’s practical toolkit into four strategies: Write, Select, Compress, and Isolate. Most production agents run on some blend of the four.
Write means storing information outside the context window. Instead of cramming everything into the window and blowing the attention budget, an agent parks what it doesn’t need right now. Anthropic’s multi-agent researcher saves its plan to memory — a scratchpad — once context risks getting truncated past 200,000 tokens. The way ChatGPT, Cursor, and Windsurf remember you across sessions is the same idea.
Select means pulling only what’s needed back into the window. The familiar technique of RAG (retrieval-augmented generation) lives here. Tellingly, applying retrieval to the tool descriptions themselves — so the agent only sees relevant tools — improved tool-selection accuracy roughly threefold. When Claude Code loads a project’s CLAUDE.md file, that too is a form of Select.
Compress means keeping only the tokens a task requires by summarizing the rest. As a long conversation nears the window’s limit, older stretches get replaced with a summary. Claude Code’s auto-compact triggers exactly this once the window hits 95% of capacity.
Isolate means splitting one large context into several so the parts can’t contaminate each other. The canonical form is a multi-agent setup. In Anthropic’s multi-agent researcher, each sub-agent burns roughly 15 times more tokens than a single chat, yet delivers better results by exploring in parallel. Crucially, each sub-agent hands the parent only a 1,000-to-2,000-token summary rather than its entire trail.
| Strategy | One-line definition | Real systems |
|---|---|---|
| Write | Store outside the window | Scratchpads (past 200k tokens), ChatGPT/Cursor memory |
| Select | Pull in only what’s needed | RAG, tool selection (~3× accuracy), CLAUDE.md |
| Compress | Summarize to save tokens | Claude Code auto-compact (at 95%) |
| Isolate | Split across sub-agents | Multi-agent (15× tokens, returns 1–2k summaries) |

Principles for Building Good Context
Knowing the strategies is one thing; assembling context in practice is another. Anthropic offers a handful of working principles, and one idea runs through all of them: find the smallest set of high-signal tokens that maximizes the odds of the outcome you want.
First, write system prompts at “the right altitude.” A rigid wall of hardcoded rules fails, and so does vague, hand-wavy guidance. The target is language specific enough that a person reads it and knows what to do, yet open enough to leave room for judgment.
Second, keep the tool set minimal and non-overlapping. The confusion failure mode came straight from tool overload. The more tools with fuzzy, overlapping purposes an agent holds, the harder it is for the model to choose. A short, unambiguous tool list wins.
Third, use compaction and agentic notes for long jobs. When a session runs long, summarize aggressively — preserve the architectural decisions and drop the redundant output — and let the agent jot durable notes to an external file like NOTES.md, kept outside the window. That way a lengthy run doesn’t lose the thread.
Fourth, retrieve data just in time. Rather than front-loading every document into context, the agent holds lightweight identifiers and calls a tool to fetch the actual content only when it’s needed. It is the most direct way to conserve the attention budget.
These principles converge on a single mental model. Context is a budget, not a warehouse. The moment you start asking what to leave out rather than what to add, you’re doing context engineering.
Context Engineering vs RAG vs Prompt Engineering
By now the vocabulary can blur together. Prompt engineering, context engineering, and RAG are not competing alternatives fighting for the same job — they sit in concentric circles, each nested inside the next.
The innermost circle is prompt engineering — refining the instruction handed to the model, still a vital ingredient. The larger circle around it is context engineering, which designs the evidence, tools, memory, and retrieval that let that instruction actually work.
So where does RAG fit? RAG is one branch of the outer circle — the Select strategy, pulling relevant information into the window. It is a subset of the outer circle, not a rival to it. That circle also covers Write, Compress, and Isolate, none of which RAG touches.
Hold that map and the practical conversation gets sharper. “Should I refine the prompt” is an innermost-circle question; “which documents should I retrieve” is a Select question; “the history got too long, how do I trim it” is a Compress question. Placing a problem at the right layer is already half the solution.
| Concept | Scope | Relationship |
|---|---|---|
| Prompt engineering | The instruction given to the model | Innermost — one element of context |
| RAG | Retrieving and injecting external info | The Select strategy within context engineering |
| Context engineering | The full composition of tokens in the window | Outer circle — contains both |
The real move is a shift in perspective: from asking better questions to designing the information environment. That is what context engineering is really about, and it links naturally to the other pillars of the agent era — from reasoning models to prompt injection security.
Frequently Asked Questions (FAQ)
Q1. What’s the difference between context engineering and prompt engineering?
Prompt engineering refines how you instruct the model. Context engineering is the larger task of designing all the information a model sees — system prompt, tools, memory, retrieved data — so that the instruction actually works. Prompt engineering is one layer inside it, not a competitor.
Q2. Isn’t a bigger context window always better?
No. Because Transformers scale computation with the square of the token count, the “attention budget” drains quickly, and “context rot” erodes retrieval accuracy as the window grows. Gemini 2.5 Pro supports a million tokens yet degraded past roughly 100,000 in testing. What matters is loading the smallest set of high-signal tokens, not filling the window.
Q3. Is RAG the same thing as context engineering?
RAG (retrieval-augmented generation) is one branch of context engineering. It maps to the “Select” strategy in LangChain’s framework — pulling relevant information into the context window. The discipline is broader, also covering the Write, Compress, and Isolate strategies.
Q4. What exactly is the attention budget?
A Transformer computes relationships between every pair of tokens, so n tokens create n² relationships. As tokens grow, that computation balloons and each token gets a shallower slice of the model’s attention. Anthropic calls this finite pool the “attention budget,” and spending it wisely is the heart of the discipline.
Q5. How does context compaction work?
When a long conversation’s history nears the window limit, older material is summarized down to its essentials and the rest is dropped. Claude Code’s auto-compact runs automatically once the window reaches 95% of capacity. The principle is to preserve important information like architectural decisions while discarding redundant output.
Q6. Do I need to be a developer to care about context engineering?
If you use or evaluate AI agents, it helps. The same model produces very different results depending on what information it’s given and in what order. Understanding the four failure modes — poisoning, distraction, confusion, clash — gives you the instinct to diagnose why a chatbot keeps going off the rails.
References
- Anthropic — Effective context engineering for AI agents (2025-09-29) — definition, attention budget, context rot, finite-resource framing
- Anthropic — Effective context engineering for AI agents (2025-09-29) — right-altitude prompts, minimal tools, compaction, agent notes, just-in-time retrieval
- Anthropic — Effective context engineering for AI agents (2025-09-29) — sub-agents return 1,000–2,000-token summaries
- LangChain — Context Engineering for Agents (2025) — Karpathy definition; Write, Select, Compress, Isolate
- LangChain — Context Engineering for Agents (2025) — 200k-token scratchpad, ChatGPT/Cursor/Windsurf memory, CLAUDE.md
- LangChain — Context Engineering for Agents (2025) — tool-selection RAG ~3× gain, Claude Code auto-compact at 95%
- Drew Breunig — How Long Contexts Fail (2025-06-22) — four failure modes (poisoning, distraction, confusion, clash)
- Drew Breunig — How Long Contexts Fail (2025-06-22) — Gemini 2.5 Pokémon ~100k degradation, Databricks Llama 405b ~32k
- Drew Breunig — How Long Contexts Fail (2025-06-22) — Berkeley Function-Calling, GeoEngine 46→19 tools
- Drew Breunig — How Long Contexts Fail (2025-06-22) — Microsoft/Salesforce sharded delivery -39% average, o3 98.1→64.1
Stay Ahead of the Curve
Get the latest insights on AI, tech, and markets — delivered in both Korean and English.
Jugger | Backend Developer
A backend engineer working in enterprise solutions software since June 2021. The hands-on perspective from system design, API implementation, and production operations directly informs this site’s
AI, IT, and cloud infrastructure coverage.
For topics outside direct professional experience—blockchain and macroeconomics—analysis is built on primary-source citations such as SEC filings, whitepapers, institutional research, and government
statistics. Speculation is clearly separated from verified fact, and unverified claims are not published.
AI tools assist with drafting, but every article is reviewed, revised, and verified before publication. Errors are corrected with visible notes when discovered.
Contact: jjunggulee@gmail.com