Context engineering is the practice of assembling the right information for a model at each step. It extends prompt engineering from wording to the whole contents of the context window.
What Goes Into Context
- System instructions.
- Examples.
- Retrieved documents.
- Tool definitions and results.
- Conversation history.
- Memory and user preferences.
Principles
- Relevant over exhaustive: more context isn't always better; irrelevant material distracts models and adds cost.
- Structured: separate sections with clear labels.
- Fresh: include up-to-date information via retrieval and tools.
- Prioritised: put the most important information where it will be noticed.
Techniques
- Retrieval to fetch relevant knowledge on demand.
- Summarising long histories.
- Removing old tool output.
- Loading detailed instructions only when relevant tasks arise.
For Agents
Over many steps, context accumulates. Managing it deliberately is key to long-running agent performance.
Measure
Evaluate changes to context composition just like prompt changes.