Context Engineering
Category: Grounding & context
Context engineering is the discipline of curating everything in the model's context window — instructions, examples, retrieved data, tools, and history — so the right information is present, relevant, and not crowded out.
What it is
Context EngineeringContext engineering broadens prompt engineering from "wording a single instruction" to designing the entire context a model sees on each call: system instructions, few-shot examples, retrieved documents, tool definitions, conversation history, and memory. As applications became agentic and long-running, what fills the finite context window — and in what order and proportion — became as important as the phrasing of any one instruction.
The goal is to supply the smallest set of high-signal tokens that lets the model succeed: relevant, current, well-structured information, without noise or overflow. It treats the context window as a scarce, curated resource and manages retrieval, compaction, and selection to keep it that way.
When to use
- Building agents or multi-turn apps where context accumulates over time.
- Combining instructions, retrieved data, tools, and history into one call.
- Long contexts degrade quality or exceed the window and must be curated or compacted.
- You need to decide what information to include, exclude, and prioritize per request.
How it works
- Inventory everything competing for the context window: instructions, examples, retrieved data, tools, history.
- Select only the highest-signal, most relevant information for the current step.
- Structure and order it so key material is prominent and unambiguous.
- Compact, summarize, or drop stale content to stay within the window and avoid distraction.
Illustrative structure
The structure is a budgeted assembly of the context, not a single sentence: [concise system instructions] + [a few well-chosen examples] + [only the retrieved passages relevant now] + [needed tool definitions] + [compacted history] — each part sized to fit the window and kept relevant.
Pitfalls
- Overstuffing the window buries key information and can degrade quality ("lost in the middle").
- Irrelevant or outdated context distracts the model as much as missing context starves it.
- Naively appending full history eventually overflows the window and inflates cost.
- Poorly ordered context — critical instructions late or scattered — reduces adherence.
Frequently asked questions
What is Context Engineering?
Context engineering is the discipline of curating everything in the model's context window — instructions, examples, retrieved data, tools, and history — so the right information is present, relevant, and not crowded out.
When should you use Context Engineering?
Building agents or multi-turn apps where context accumulates over time. Combining instructions, retrieved data, tools, and history into one call. Long contexts degrade quality or exceed the window and must be curated or compacted. You need to decide what information to include, exclude, and prioritize per request.
What are common pitfalls of Context Engineering?
Overstuffing the window buries key information and can degrade quality ("lost in the middle"). Irrelevant or outdated context distracts the model as much as missing context starves it. Naively appending full history eventually overflows the window and inflates cost. Poorly ordered context — critical instructions late or scattered — reduces adherence.
Sources
Related techniques
← All prompt engineering techniques
Apply Context Engineering with Prompeteer, the Agentic Contextual AI Platform →