Context Engineering
Context engineering is the discipline of designing what information a large language model (LLM) receives at each step of a task: which instructions, data, history, tools and memory go into its limited context window, in what form, and when. The aim is to give the model what it needs to succeed at each step, and little else.
How Context Engineering Works
A model's output depends on everything in its context window, not only the user's latest message. Context engineering treats that whole input as something to design. Anthropic describes it as the set of strategies for curating and maintaining the optimal set of tokens during inference. The material it works with includes:
- Instructions: system prompts and standing project rules.
- Knowledge: retrieved documents, requirements, code and data.
- History: earlier turns of the conversation and the results of past actions.
- Tools: the definitions of available tools and the outputs they return.
- Memory: notes and state stored outside the window and loaded back when relevant.
LangChain groups the main techniques into four strategies:
- Write: save information outside the window, such as notes, plans or decisions, so it can be reused later.
- Select: pull only the relevant pieces into the window for the current step, often through search or retrieval from stored agent memory.
- Compress: keep only the tokens the task needs, for example by summarizing long histories through context compaction.
- Isolate: split work across separate contexts, such as sub-agents that each handle a focused task and return a short summary.
Anthropic adds that agents can load data just in time: they keep lightweight references, such as file paths or links, and fetch the full content only when needed.
Why Context Engineering Matters
More context is not always better. Anthropic's research notes that as the number of tokens grows, a model's ability to recall information accurately decreases, an effect called context rot. Every token draws on a limited attention budget. Stuffing the window with everything available can bury the one rule that matters.
Context engineering matters most for AI agents, which run for many steps, accumulate tool output and must keep track of goals across a long task. Many agent mistakes are context failures rather than model failures: the agent never saw the requirement, saw an outdated version, or lost it in a crowded window. Fixing the context often fixes the output without changing the model or the prompt wording.
For product teams, this turns product knowledge into an engineering input. Clear requirements, decision logs and specifications are what context engineering selects from. If that material is vague or scattered, no retrieval technique can fix it.
Context Engineering Example
A product team builds an assistant that drafts user stories from their PRDs. Their first version pastes the entire PRD, the full backlog and the last fifty chat messages into every request. Outputs are slow, costly and frequently use outdated rules.
They redesign the context. The system prompt holds the team's story format. For each request, the system retrieves only the PRD sections tied to the selected feature, the three most related existing stories, and the current version of any business rule those sections reference. Long chat histories are summarized. Decisions confirmed by the product manager are written to a decision log that future requests can retrieve. The model is unchanged, yet the stories become shorter, consistent with current rules and cheaper to generate. A practical treatment of these steps for coding agents is in context management for AI coding agents, and the input-structuring side for product managers is covered in prompt engineering for product managers.
Context Engineering vs. Prompt Engineering
Prompt engineering focuses on writing effective instructions, usually a single prompt. Context engineering covers the entire information state across many turns: instructions plus retrieved knowledge, tools, memory and history. Shopify CEO Tobi Lutke and AI researcher Andrej Karpathy popularized the term in mid-2025, with Lutke calling it the art of providing all the context needed for a task to be plausibly solvable by the LLM. Prompt engineering is now generally treated as one part of context engineering.
Context engineering is also related to context management. Engineering is usually framed as designing what the model should see; management is keeping that information stored, pruned and current as work continues.