What Is Context Engineering? (The 2026 Shift)
Introduction
Foundations of AI Engineering has taught you to talk to a model: tokens and sampling, prompting, advanced techniques, structured outputs. Each of those lessons came down to one thing: what you put in front of the model. This last section names that skill and makes it the subject.
For years the craft was prompt engineering: wording an instruction, mostly by hand, mostly fixed. In September 2025, Anthropic put it this way: "After a few years of prompt engineering being the focus of attention in applied AI, a new term has come to prominence: context engineering." Systems now run for many steps, call tools, carry memory and pull in documents. There, the instruction you wrote is a slice of what the model sees, and the question becomes: of everything you could put in the window (instructions, history, retrieved documents, tool results, memory, state), what belongs there now?
That question is context engineering. The rest of this section, and much of RAG & Retrieval Systems and AI Agents & MCP, is about answering it.
You'll learn:
- how context engineering differs from prompt engineering, and why the shift came
- the parts assembled into the context window on every call
- why context is a finite resource, and what context rot is
- the one principle behind it all: the smallest high-signal set
- a map of the strategies, and where the course makes each concrete
From Prompt Engineering to Context Engineering
Prompt engineering is writing an effective instruction, the system prompt above all, for a task. It is still essential: two sections of this course, Prompt Engineering Fundamentals and Advanced Prompting Techniques, were about it. But it assumes an input you write once.
Context engineering is broader, and it changes call by call. Anthropic defines it as "the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference, including all the other information that may land there outside of the prompts." The question it puts in place of the right words: "what configuration of context is most likely to generate our model's desired behavior?", asked again turn after turn, as a system loops, retrieves and remembers.
The difference in one line: prompt engineering works on the words of an instruction; context engineering works on every token the model sees, assembled again on every call from many sources. Prompting is part of it.
What's in the Context?
On any call, the prompt the model receives is assembled from several sources, not typed by hand:
- System instructions: role, rules, output format.
- Tools and their descriptions: what the model can do; the definitions travel in the request, as tokens.
- Examples: few-shot demonstrations.
- Message history: the conversation so far.
- Retrieved data: documents pulled in by retrieval (RAG & Retrieval Systems).
- Memory and notes: facts carried across turns (Memory, State & History as Context).
- Current state: task progress, a scratchpad, intermediate results.
Context engineering decides what goes into the window, from each of these, every time.

The model never sees sources: it sees one flat stream of tokens that your code joined. Here is that assembly made literal; it runs with no API:
def assemble_context(system, memory, retrieved, history, user_msg):
parts = { # the sources this call draws on, in the order they are sent
"SYSTEM INSTRUCTIONS": system,
"MEMORY / NOTES": memory,
"RETRIEVED DATA": retrieved,
"CONVERSATION HISTORY": history,
"USER MESSAGE": user_msg,
}
# only the parts that have something in them: curation starts here
return "\n\n".join(f"## {name}\n{text}" for name, text in parts.items() if text)
context = assemble_context(
system="You are a concise support agent.",
memory="Customer: Jane, Pro plan since 2024.",
retrieved="Refund policy: refunds post within 5-7 business days.",
history="Jane: Where is my refund?",
user_msg="It's been 3 weeks!",
)
print(context)
print(f"\n{len(context.split())} words from 5 sources, sent as one string")It prints:
## SYSTEM INSTRUCTIONS
You are a concise support agent.
## MEMORY / NOTES
Customer: Jane, Pro plan since 2024.
## RETRIEVED DATA
Refund policy: refunds post within 5-7 business days.
## CONVERSATION HISTORY
Jane: Where is my refund?
## USER MESSAGE
It's been 3 weeks!
45 words from 5 sources, sent as one stringFive parts, one string. Labels are tokens too: counted with GPT-2's tokenizer, the string is 85 tokens, and the same five texts joined without their headings are 50. Headings can earn their place: Anthropic recommends "using techniques like XML tagging or Markdown headers to delineate these sections, although the exact formatting of prompts is likely becoming less important as models become more capable." On a context this small they are 35 of its 85 tokens.
Once you see context as something you assemble, the question follows: every token competes for limited space and attention, so you cannot include everything.
Context Is a Finite Resource: Context Rot
It is tempting to read a window of a million tokens as room for everything. Don't. Context Length: Long-Context Models & Their Limits showed models losing what sits in the middle of a long input. Anthropic names the wider effect context rot: "as the number of tokens in the context window increases, the model's ability to accurately recall information from that context decreases." And of the models it has seen: "While some models exhibit more gentle degradation than others, this characteristic emerges across all models."
Why, in Anthropic's account: attention lets every token attend to every other, "n² pairwise relationships for n tokens", so attention is stretched thin as the context grows; and models learn their attention patterns from training data "where shorter sequences are typically more common than longer ones." Its conclusion: context is "a finite resource with diminishing marginal returns."
Chroma measured the effect on 18 models in July 2025: "their performance grows increasingly unreliable as input length grows." One of its tests gave the LongMemEval questions two ways: focused prompts of about 300 tokens that held only the relevant parts, and full prompts of about 113,000 tokens of chat history, most of it beside the point. Its result: "Across all models, we see significantly higher performance on focused prompts compared to full prompts."
More tokens can make answers worse, slower and dearer at once (Latency vs Cost vs Quality — The Iron Triangle). So the goal is not to fill the window.
The Core Principle: The Smallest High-Signal Set
Anthropic's guiding rule is finding "the smallest possible set of high-signal tokens that maximize the likelihood of some desired outcome." Curate rather than hoard: each token should raise the odds of a good answer, and tokens that don't are noise that thins attention and feeds context rot.
This changes much of what you'll build. Good retrieval fetches the few right passages, not the most documents. A good agent carries a summary and what matters now, not its whole history. The mindset is an editor's: strict about what makes the cut.
The Strategies (a Map)
How do you keep context small and high in signal? The toolkit, and where you meet each part of it:
- Select and compress the window: pick what is relevant and summarize the rest (Managing the Context Window (Selection & Compression)).
- Memory and note-taking: write lasting facts outside the window and bring them back when needed (Memory, State & History as Context).
- Just-in-time retrieval: instead of loading everything up front, Anthropic's agents keep "lightweight identifiers (file paths, stored queries, web links, etc.)" and load the data with tools when they need it (AI Agents & MCP); retrieval itself is RAG & Retrieval Systems.
- Compaction: "taking a conversation nearing the context window limit, summarizing its contents, and reinitiating a new context window with the summary" (Short-Term vs Long-Term Memory, in AI Agents & MCP).
- Sub-agents: agents that do the deep work in clean windows of their own and return a short summary, in Anthropic's post "often 1,000-2,000 tokens" (Why Multiple Agents? (And Why Not)).
Each spends a finite token budget well. What you read here is the why; those are the how.
Pitfalls & Mental-Model Corrections
- "A bigger window means add everything." Context rot makes recall drop as you fill it. A large window is a budget, not a target.
- "Context engineering is just RAG." Retrieval is one source of context; memory, tools, history and state are others, and context engineering coordinates them all.
- "It's prompt engineering with a new name." Prompting crafts an instruction; context engineering curates every token across many turns. Prompting is part of it.
- "More context is safer." More context is more cost, more waiting and more room to fix on the wrong thing; in Chroma's runs the focused prompts scored higher for every model.
- "The model sees my sections." It sees one stream of tokens you assembled. Chroma's conclusion: "Whether relevant information is present in a model's context is not all that matters; what matters more is how that information is presented."
Try It Yourself
Open a prompt you have built, or the extraction prompt of Hands-On: Extract Structured Data from Unstructured Text, and audit its context like a budget. List every distinct thing you send (system instructions, examples, history, retrieved text, the user's message) and mark each one high-signal or low-signal for the task. Cut or compress two low-signal items, run it again, and see whether the answer holds.
Then the real question: with half the tokens, what would you keep? That ranking, what earns its place, is context engineering. Then test yourself:
Context, a budget
1 / 6Multiple choice
Multiple choice
Multiple choice
Multiple choice
Multiple choice
Multiple choice
Key Takeaways
- Context engineering curates and maintains the set of tokens the model sees during inference: prompt engineering grown into systems that run many turns, call tools and carry memory.
- The window is assembled on every call from many sources: instructions, tools, examples, history, retrieved data, memory and state. Labels and formatting are tokens too.
- Context is a finite resource. Context rot means recall drops as tokens grow (attention stretched over n² pairs, training on shorter sequences); in Chroma's runs the focused prompts beat the full ones on every model.
- The guiding rule is the smallest set of high-signal tokens that gets the outcome you want.
- The strategies (selection and compression, memory, just-in-time retrieval, compaction, sub-agents) come next; what you read here is the why.
Next: Managing the Context Window (Selection & Compression): the techniques for choosing and compressing what goes into that budget.