What is context engineering?
Context engineering is the practice of deciding exactly what information goes into a language model's context window at each step: the instructions, conversation history, retrieved documents, tool definitions, tool results and saved memory. It extends prompt engineering from writing one good prompt to managing a limited, changing working memory across long tasks and agents.
The model can only use what is in front of it, and there is a limited amount of room in front of it. Context engineering is the discipline of filling that room with the right things, in the right form, at the right moment.
The term spread in mid-2025, when several well-known engineers argued that "prompt engineering" undersold the real work of building AI systems. Anthropic's engineering team later described context as a finite resource with diminishing returns, and context engineering as finding the smallest set of high-signal tokens that gets the job done.
How is context engineering different from prompt engineering?
Prompt engineering focuses on writing a good instruction. Context engineering covers everything the model sees on a call, much of which is assembled by code rather than written by hand.
| Part of the context | Who or what puts it there | Context engineering question |
|---|---|---|
| System prompt | Developer | Is every instruction here still needed? |
| Conversation history | The application | Should old turns be kept, summarised or dropped? |
| Retrieved documents | RAG pipeline | Are these the right passages, and only those? |
| Tool definitions | Developer or MCP servers | Does the model need all of these tools for this step? |
| Tool results | Tool calls | Can a large result be trimmed or summarised? |
| Memory | Memory system | Which saved facts are relevant now? |
Why does context engineering matter so much for agents?
Because an agent adds to its own context on every step. Each tool call appends a request and a result; after dozens of steps the context window holds file listings, search results and error messages, most of them no longer relevant. Performance tends to degrade as the context fills with noise, an effect people call context rot, which is related to the "lost in the middle" finding that models use information in the middle of long inputs less reliably. Costs rise at the same time, because every step re-sends the whole history.
What are the main context engineering techniques?
- 1SelectInclude only what the current step needs: the few relevant documents, the tools for this task, the facts that matter now.
- 2CompressSummarise old conversation turns and long tool results, keeping decisions and open questions.
- 3StructureLabel parts clearly with headings or tags, such as <document> and <tool_result>, so the model can tell instructions from data.
- 4Load just in timeGive the agent lightweight references, like file paths or search tools, and let it fetch details when needed instead of loading everything up front.
- 5Write notes outside the windowLet the agent keep a notes file or task list it can read back after its context is reset or compacted.
- 6IsolateHand a self-contained sub-task to a subagent with a clean context, and bring back only its summary.
These techniques trade off against each other. Aggressive compression saves tokens but can drop the one detail that mattered. Loading just in time keeps context clean but adds tool calls and latency. The right balance depends on the task, which is why measuring with evals matters.
What are common context engineering mistakes?
- Do: Log the exact, complete context sent on each call so you can see what the model saw
- Do: Keep stable content, such as the system prompt and tool definitions, at the start so it can be cached
- Do: Remove tools the model never uses for a given task
- Avoid: Load every document and every tool "just in case"
- Avoid: Let tool results of thousands of tokens stay in the history after they have been used
- Avoid: Summarise without keeping key decisions, file names and unresolved errors
Stable content at the start of the context also makes prompt caching effective, which cuts cost and latency on long agent runs.
Frequently asked questions
Is context engineering replacing prompt engineering?
It is better seen as a broader version of it. Writing clear instructions still matters, but in agents and long-running systems most of the context is assembled by code, so deciding what to include becomes the bigger job.
What is context rot?
Context rot is the decline in a model's performance as its context fills with long, noisy or outdated content. Relevant information gets used less reliably, so trimming and summarising the context helps.
Does a bigger context window remove the need for context engineering?
No. Larger windows let you include more, but models still use long contexts unevenly, and every extra token adds cost and latency. Choosing what to include still gives better results.
How do agents manage context over long tasks?
Common approaches are summarising or compacting old history, saving notes to a file the agent can re-read, fetching information with tools only when needed, and delegating sub-tasks to subagents that return short summaries.
Last checked for accuracy on . Written by the solidcoder team.