Context engineering
Choosing all a language model gets to see for a task - instructions, fetched documents, tool results, notes - not just the wording.
Draft - this entry has not been reviewed yet.
Formal
The practice of deciding, for each step of an AI system, what goes into the context window and in what order - system prompt, retrieved documents, tool results, saved notes and earlier messages - within the limit on tokens.
In plain English
Like packing a small suitcase for a trip - what you leave out matters as much as what you put in, and what sits on top gets used first.
In practice
At a Danish software house, a developer sets up a coding agent to load only the task notes and the three most relevant files, and to swap long test output for a short summary before each next step.
Why it matters
In long agent tasks, answers go wrong less from badly worded requests than from missing, stale or cluttered material in view, and untrusted material in view can also steer the agent.
Technical deep dive
The term gained currency in mid-2025 as agent builders argued that "prompt engineering" undersold the problem: in a multi-step agent, most of the tokens the model sees are not written by a human at all but assembled by the harness from tool definitions, retrieved documents, tool outputs, memory files and prior turns. Anthropic's engineering post "Effective context engineering for AI agents" (29 September 2025) frames the goal as finding the smallest set of high-signal tokens that maximises the likelihood of the desired outcome, treating context as a finite resource with diminishing returns.
The underlying constraint is that model performance degrades as context grows, even well inside the nominal window. Anthropic calls this context rot; related measurements include the "lost in the middle" effect and long-context benchmarks that show effective length below advertised length. Irrelevant or contradictory material also distracts the model, and stale tool output can be mistaken for current state. Cost and latency scale with input tokens on every step of an agent loop, so an agent that re-sends a growing transcript pays quadratically over a long run unless prefix caching is exploited.
The main techniques are well defined. System prompts should sit at the right altitude - specific enough to guide behaviour, general enough not to hard-code brittle rules - and be organised into clearly delimited sections. Tool sets should be minimal and non-overlapping, with tool outputs designed to be token-efficient (paginated, truncated, filterable). Just-in-time retrieval keeps lightweight references such as file paths, queries or URLs in context and loads content only when needed, instead of pre-loading everything. Compaction summarises a conversation nearing the limit and restarts with the summary; a lighter form clears old tool results that will not be needed again. Structured note-taking persists progress, decisions and to-do lists outside the context window, to be re-read later. Sub-agent architectures give focused tasks to helpers with clean contexts that return only condensed results to a coordinating agent.
Ordering matters for both quality and cost: stable material (system prompt, tool definitions, reference documents) first so that prompt caching can reuse it, volatile material last, and the current question near the end where recall is strongest. Context engineering also has a security dimension that prompt engineering lacks. Every automated source - search results, fetched pages, repository files, other agents' outputs, persisted notes - is a channel for indirect prompt injection, and memory that persists between sessions can carry an injected instruction forward. Provenance labelling, separating trusted instructions from untrusted data, least-privilege tools and review of what is written to long-term memory are part of the discipline, not an add-on.
What to learn first
Everything this builds on, foundations first.
- Token
- →Context window
- →Context engineering
Relationships
- Consists of
- Agent instructions file
- Requires
- Context window
- Don't confuse with
- Prompt engineering
Sources & further reading
Official documentation
- Anthropic Engineering - Effective context engineering for AI agents (2025) · Anthropic
Where this data comes from
This entry was drafted by an AI from the sources above and has not yet been checked by a person. Treat it as a starting point, and check anything important against the sources.
See the review queueSuggest a correction on GitHubThis term as JSON
Check yourself
Loading…