Context engineering combines several techniques applied on every inference cycle: (1) a system prompt at the right "altitude" — specific enough to steer behavior, flexible enough to leave the model heuristics; (2) a minimal, unambiguous tool set instead of bloated tool libraries; (3) diverse, canonical few-shot examples rather than exhaustive edge cases; (4) just-in-time retrieval — the agent keeps lightweight identifiers (file paths, URLs, queries) and loads data only when needed (progressive disclosure); (5) compaction — summarizing history before hitting the window limit while preserving architectural decisions and open threads; (6) structured note-taking / memory persisted outside the context window for long-horizon coherence; (7) sub-agent architectures with clean contexts that return condensed summaries (typically 1,000–2,000 tokens) to a coordinating lead agent.
It addresses the degradation of LLM-agent output quality caused by overloaded, poorly selected, or stale context. As the context window grows, "context rot" and the quadratic (O(n²)) attention cost increase and the model loses track of salient information; context engineering curates, prunes, and just-in-time delivers only the tokens that are needed.
Persistent instructions defining agent behavior, written at the right "altitude" — specific enough to steer, general enough to leave the model heuristics.
Official
A self-contained, unambiguous set of tools; bloated tool sets with overlapping functions should be avoided.
Official
Diverse, canonical examples illustrating expected behavior, rather than an exhaustive list of edge cases.
Official
The interaction so far, managed via curation strategies (pruning, compaction) to stay within the attention budget.
Information loaded at runtime from lightweight identifiers (file paths, URLs, queries) instead of pre-loading all context upfront.
Official
Durable notes and state persisted outside the context window, recalled on demand for long-horizon coherence.
Official
Overfilling the context window degrades the model's ability to accurately recall information.
Too many overlapping tools increases token count and tool-selection errors.
Information placed in the middle of a long context is recalled less reliably than at the start and end.
Aggressive summarization can drop details needed later (e.g. unresolved bugs, decisions).
Injecting erroneous or malicious content into context persists it across the agent's subsequent turns.
Placing examples in context as a way to steer the model — an early precursor of context curation.
Emphasis on wording a single prompt; the foundation that context engineering later generalized.
Dynamically injecting retrieved knowledge into context popularized managing the window's contents.
The term was popularized in mid-2025 (Tobi Lütke, Andrej Karpathy), and LangChain described it in "The rise of context engineering" (June 23, 2025).
Anthropic formalized the practices (right-altitude system prompts, just-in-time retrieval, compaction, note-taking, sub-agents) in a guide published September 29, 2025.
Time complexity: O(n² · d). Space complexity: O(n · d · L).
As context length grows, attention cost (quadratic) and KV-cache footprint (linear) rise, limiting the model's effective "attention budget".
Target token count kept in context; a lower budget reduces context rot at the cost of less information.
Choice between pre-loading context and just-in-time retrieval.
The window-fill level at which history summarization is triggered.
Number and granularity of tools exposed to the agent; too large a set causes bloat and selection errors.
How many canonical examples to place in context to calibrate behavior without wasting token budget.
How state and notes are persisted outside the context window and the rules for recalling them.
How many specialized clean-context sub-agents a lead agent coordinates.
Context contents are selected conditionally, depending on task state and query.
The agent decides at runtime which data to load and which parts of history to keep or summarize, instead of loading everything upfront.
Sub-agent architectures parallelize work, returning condensed summaries to a coordinating lead agent.
It is a software- and orchestration-level design practice, independent of any specific hardware.
Reducing context length lowers KV-cache footprint and attention cost on GPUs during inference.