What Is Context Engineering? Definition and Techniques
Context engineering is the work of making sure an AI model has the right information, instructions and tools in front of it for each step of a task. Where prompt engineering is about how you word a request, context engineering is about everything else in the context window: the relevant documents, the conversation so far, the results of earlier tool calls, the company’s conventions and the tools available.
Why it matters
Most bad AI output comes from missing or wrong context, not a weak model or a badly phrased prompt. A model asked to draft a renewal email does far better when it already has the account history, the pricing rules and the tone the team uses.
Agents make this the main job. An agent working through a long task builds up context with every step, and its context window fills with tool output, old messages and dead ends. Deciding what to keep, what to summarize, what to fetch fresh and what to drop is what separates an agent that finishes the job from one that loses the thread halfway.
Context engineering vs prompt engineering
| Prompt engineering | Context engineering | |
|---|---|---|
| Focus | The wording of the request | Everything the model sees: documents, history, tool results, instructions, tools |
| When it happens | Once, when you write the prompt | At every step of a task, often automatically |
| Typical work | Phrasing, examples, output format | Retrieval, memory, compaction, tool selection, instruction files |
| Matters most for | Single questions and one-shot tasks | Agents and long, multi-step work |
They overlap: a good prompt is part of good context. For more, see context engineering vs prompt engineering.
What goes into a model’s context
- System prompt: the standing rules for the assistant or agent (system prompt).
- Instructions and memory files: project or team guidance such as AGENTS.md or CLAUDE.md, and notes saved from earlier work.
- Retrieved knowledge: documents, records and search results pulled in for this task (retrieval-augmented generation).
- Conversation history: what’s been said and decided so far.
- Tool definitions and results: which tools exist, and what they returned.
- The task itself: the request, with its constraints and what “done” looks like.
Techniques
- Retrieve, don’t preload. Fetch the documents a step needs instead of loading everything up front.
- Keep standing instructions short. They’re read every session; long ones cost tokens and bury the rules that matter.
- Compact long sessions. Summarize old history and tool output, and keep decisions and open questions.
- Write notes outside the window. Let agents save progress to files or to-dos and read them back later.
- Split work across agents. Subagents each get a clean, focused context and return only a summary.
- Offer fewer, clearer tools. Dozens of overlapping tools confuse the model and fill the window with their descriptions.
- Order and label. Put the most important material where the model will use it, and label sources clearly.
Context engineering for coding agents
Coding agents show the idea clearly. A good setup gives the agent a short instruction file with the build and test commands and the rules the code doesn’t show; lets it search the codebase rather than reading every file; sends broad exploration to subagents that return a summary; and starts a fresh session for a new task instead of carrying the last one’s history. When the agent keeps making the same mistake, the fix is usually in its context (a missing rule, a stale note, too much noise) rather than in the wording of the request. Much of this is set in the agent harness.
Common failures
- Too little: the model guesses at facts it should have been given.
- Too much: overloaded windows cost more and perform worse, a problem known as context rot.
- Stale: old instructions or outdated documents the model follows faithfully.
- Untrusted: text from web pages, files or emails that contains instructions the model shouldn’t follow (prompt injection).
Context across a team
Context engineering is usually discussed for one agent. On a team, the harder problem is that each person’s agent has its own context, and what one learns never reaches the others. Shared context, in the form of threads, files and decisions the agents can all read, keeps them working from the same picture.
How elvex relates
elvex Spaces hold a team’s threads, files and to-dos, and each person’s agent reads them with that person’s access, so agents from different people start from the same context.
Related
-
What is context engineering?
Designing what an AI model sees at each step of a task, including documents, history, tool results, instructions and available tools, so it has what it needs and nothing that distracts it. -
How is context engineering different from prompt engineering?
Prompt engineering is about wording a request. Context engineering covers everything else in the context window, and it happens at every step of an agent’s work, not just once. -
Why does context engineering matter for AI agents?
Agents build up context with every step. Without managing it, the window fills with old tool output and dead ends, and the agent loses track of the task. -
What are examples of context engineering techniques?
Retrieving documents only when needed, short instruction files like AGENTS.md, compacting long histories, saving notes outside the context window, and splitting work across subagents. -
Is more context always better?
No. Overloaded context windows cost more and often perform worse. The goal is the right context, not the most.