The Research Report
Context Engineering Is the New Prompt Engineering
LangChain formalizes the discipline that makes AI agents actually work — and it's not what you've been calling "prompt engineering"
The term "prompt engineering" has had a good run. For three years, it's been the catch-all phrase for everything from tweaking a ChatGPT instruction to building multi-step agent workflows. But as AI systems have grown from simple chatbots into autonomous agents that plan, reason, and collaborate, the discipline has outgrown its name.
Enter context engineering — a term originally coined by Andrej Karpathy and now formally defined by LangChain in a landmark blog post that reframes how we should think about building AI systems. The shift isn't just semantic. It's a fundamental change in what we optimize, what we measure, and what fails.
Because here's the uncomfortable truth: most agent failures aren't reasoning failures. They're context failures. The model didn't misunderstand the task. It was given the wrong context — too much, too little, or the wrong kind entirely.
LangChain's framework gives us a vocabulary and a playbook for getting context right. Let's dig in.
Why "Prompt Engineering" Doesn't Cut It Anymore
Prompt engineering implies a static, one-shot activity: write the instruction, tweak the wording, ship it. That made sense when LLMs were stateless chatbots. You crafted a prompt, got a response, and moved on.
But modern AI agents don't operate in a single turn. They maintain memory. They retrieve documents. They delegate subtasks to other agents. They use tools. Each of these interactions modifies the context the model sees. The "prompt" is no longer a string — it's a dynamic, evolving information environment.
Karpathy nailed this when he said the discipline should be called "context engineering," not "prompt engineering." The word engineering is the key: this is a systems problem, not a copywriting problem. You're designing an information pipeline, not writing a clever instruction.
LangChain's blog post takes Karpathy's insight and builds a full framework around it — four strategies, a failure taxonomy, and production case studies. It's the most coherent treatment of the topic so far.
The Four Strategies of Context Engineering
LangChain identifies four core strategies for managing context in AI systems. Each addresses a different dimension of the problem, and they compose together in practice.
1. Write: Scratchpads, Memories, and Structured Outputs
The write strategy is about giving the model a place to put information — not just receive it. When a model can write intermediate steps, it offloads working memory and reduces the chance of losing track of its own reasoning.
The classic example is the scratchpad pattern: instead of asking the model to produce a final answer in one shot, you let it write out its reasoning process first. Chain-of-thought prompting is the minimal version. More sophisticated implementations give the model an actual writable memory that persists across turns.
Then there's structured output — forcing the model to write in a schema (JSON, XML, a typed object) rather than free text. This isn't just about parseability. Structured output constrains the model's generation space, which reduces hallucination and makes downstream processing reliable.
Memories are the third write primitive. Short-term memory keeps conversation context. Long-term memory stores facts about the user, the task, or the world. The key design decision is what to write, when to write it, and how to evict stale entries.
The write strategy answers: Where does the model put things so it doesn't lose them?
2. Select: Retrieval, Filtering, and Relevance
The select strategy is about choosing what goes into the context window in the first place. This is where retrieval-augmented generation (RAG) lives, but it's broader than that.
At its simplest, select means filtering: given a set of candidate documents, messages, or tool results, pick the ones that are relevant to the current task. At its most sophisticated, it means multi-stage retrieval pipelines that query, rerank, and compress before anything reaches the model.
The critical insight: you can't just stuff everything into context and hope the model sorts it out. Every irrelevant token is a potential source of distraction or confusion. Selection is curation, and curation is engineering.
LangChain emphasizes that selection isn't just about accuracy — it's about efficiency. Every token you select costs inference time and money. Smart selection reduces both.
The select strategy answers: What information deserves the model's limited attention?
3. Compress: Summarization and Distillation
Even after you've selected the right information, it might be too verbose. The compress strategy reduces information to its essential form — summarizing a 50-page document into a paragraph, condensing a long conversation history into key decisions, or extracting just the action items from a meeting transcript.
Compression is where context engineering intersects with one of the hardest problems in AI: what matters? A good summary preserves causal structure, key facts, and decision-relevant details while discarding filler and redundancy. A bad summary loses the thing you needed.
The practical applications are everywhere:
- Conversation summarization — instead of passing the full chat history, pass a running summary plus the last few turns
- Document distillation — extract the core argument from a research paper before feeding it to an agent
- Multi-agent handoffs — when one agent passes context to another, compress to just what the downstream agent needs
Compression is also a defense mechanism against context window limits. As models get larger context windows, the temptation is to just throw everything in. But larger contexts don't mean better contexts. More tokens means more noise, more distraction, and more cost. Compression is the discipline of keeping the signal-to-noise ratio high.
The compress strategy answers: How do we reduce information to only what's necessary?
4. Isolate: Sandboxing and Scope Limits
The isolate strategy is the most underappreciated and the most important for production systems. It's about building walls: separating concerns, scoping permissions, and preventing context from bleeding where it shouldn't.
In a multi-agent system, isolation means each agent gets only the context it needs to do its job. The researcher agent doesn't see the coder agent's scratchpad. The planner doesn't see the executor's raw logs. This isn't just about efficiency — it's about safety and correctness.
Isolation prevents several classes of failure:
- Context leakage — one agent's internal state influencing another agent's decisions
- Prompt injection propagation — a malicious input in one context window spreading to other agents
- Scope creep — an agent gradually accumulating irrelevant context over long runs
The sandboxing pattern goes further: run untrusted components (tool calls, user-provided content, other agents' outputs) in isolated context windows with strict input/output contracts. This is how Cognition's Devin and Anthropic's multi-agent researcher handle complex, long-running tasks without context corruption.
The isolate strategy answers: How do we prevent context from causing harm — to itself or to other parts of the system?
Drew Breunig's Context Failure Taxonomy
LangChain's framework isn't just about what works — it's also about what fails. The blog cites Drew Breunig's taxonomy of context failures, which maps directly to the four strategies:
Poisoning
What it is: Malicious or incorrect information enters the context and corrupts the model's output.
Example: A user injects a prompt into a document that the agent retrieves, causing it to ignore its instructions.
Defense: Isolation (sandbox retrieved content), selection (filter out suspicious inputs), compression (summarize rather than include raw text).
Distraction
What it is: Too much irrelevant information in context causes the model to lose focus on the actual task.
Example: An agent with 100KB of retrieved documents spends its attention on tangentially related paragraphs and misses the one key fact.
Defense: Selection (aggressive filtering), compression (summarize before including), isolation (partition context into focused windows).
Confusion
What it is: Contradictory or ambiguous information causes the model to produce inconsistent or hedging outputs.
Example: An agent retrieves two documents that say opposite things about the same topic, and its response becomes incoherent.
Defense: Selection (prefer authoritative sources), write (require the model to note contradictions explicitly), compression (resolve contradictions before including).
Clash
What it is: Different parts of the context push the model in incompatible directions — often the system prompt vs. retrieved content vs. user input.
Example: The system prompt says "be concise," the retrieved documents are verbose, and the user asks for a detailed explanation. The model oscillates between styles.
Defense: Write (explicit prioritization rules in the prompt), isolation (separate concerns into different context windows), compression (normalize style before including).
This taxonomy is a practical debugging tool. When your agent produces bad output, ask: is this a reasoning failure or a context failure? If it's context, which failure mode — poisoning, distraction, confusion, or clash? The answer tells you which strategy to apply.
Production Proof: Cognition and Anthropic
LangChain doesn't just theorize — it points to real production systems that embody context engineering principles.
Cognition (Devin)
Cognition's Devin is an autonomous coding agent that can plan, write code, run tests, and debug — all in long-running sessions. The key to making this work isn't a smarter model. It's ruthless context management:
- Each subtask gets its own scoped context window
- Scratchpads track intermediate state so the model doesn't have to hold everything in working memory
- Tool outputs are compressed before being fed back to the model
- The system isolates untrusted inputs (user code, web content) from the model's instructions
Without these context engineering patterns, Devin would collapse under its own context within minutes.
Anthropic's Multi-Agent Researcher
Anthropic's published work on multi-agent research workflows demonstrates isolation in action. When you have multiple agents collaborating on a research task:
- Each agent operates in its own context window with minimal shared state
- Handoffs between agents use compressed summaries, not raw conversation logs
- The orchestrator maintains a separate "planning" context from the "execution" context
- Results are filtered and validated before being written to shared memory
This architecture makes the system robust. If one agent goes off track, it doesn't poison the others. If context gets too long, it's compressed at the handoff point. The system stays coherent over arbitrarily long research tasks.
The Disciplinary Shift
Here's the bottom line: prompt engineering is to context engineering as copywriting is to systems engineering.
Prompt engineering asks: "What instruction should I write?"
Context engineering asks: "What information environment should I design?"
This shift has practical consequences:
- The unit of work changes. You're not optimizing a prompt template. You're designing a pipeline that writes, selects, compresses, and isolates context at every stage.
- The failure modes change. The biggest problems aren't bad instructions — they're bad context. Poisoning, distraction, confusion, and clash are the demons you're exorcising.
- The skills change. You need retrieval systems design, information architecture, sandboxing strategies, and compression pipelines — not just clever wording.
- The metrics change. You're measuring context relevance, information density, isolation boundaries, and compression quality — not just "did the model follow the instruction."
LangChain's framework isn't the final word on context engineering. It's an initial map of a territory that's still being explored. But it's a map that's desperately needed, because right now most teams are stumbling through context failures with no vocabulary to describe what's going wrong.
Practical Takeaways
If you're building AI agents or multi-agent systems, here's how to start applying context engineering today:
- Audit your context. Before you add more to the prompt, ask: does every token in my current context earn its place? If not, remove it.
- Build retrieval before reasoning. The biggest wins come from better selection, not better prompts. Invest in your retrieval and filtering pipeline.
- Compress aggressively. Summarize conversation history, distill documents, and extract key facts before passing them to the model. Every token you compress is a token the model doesn't have to reason about.
- Isolate by default. In multi-agent systems, give each agent its own context scope. Share information through compressed summaries, not raw context dumps.
- Debug context, not reasoning. When your agent fails, first check the context it received. You'll find that most failures are context failures — the model never had a chance to reason correctly because it was working with bad inputs.
- Use the failure taxonomy. When something goes wrong, classify it: poisoning, distraction, confusion, or clash. The classification tells you which strategy to apply.
- Treat context as infrastructure. Build context management pipelines the way you build data pipelines — with tests, monitoring, and version control. Your agent's context is as critical as your database.
The Road Ahead
Context engineering is still early as a discipline. We don't have standardized benchmarks for context quality. We don't have well-understood design patterns for every scenario. We don't have good tools for visualizing and debugging context flows.
But the direction is clear. As AI systems become more autonomous and more complex, the bottleneck shifts from model capability to context design. The models are good enough. The question is whether we can give them the right information, in the right form, at the right time.
LangChain's framework is a starting point. The four strategies — write, select, compress, isolate — give us a vocabulary. Drew Breunig's failure taxonomy gives us a diagnostic. The production examples from Cognition and Anthropic give us proof that these patterns work at scale.
The next time someone tells you they're "prompt engineering" their agent, ask them: Are you writing a prompt, or are you engineering a context? The difference is the difference between a chatbot that works and an agent that doesn't.
Based on LangChain's blog post on context engineering, Drew Breunig's context failure taxonomy, and production architectures from Cognition and Anthropic.