Context Engineering roadmap
Deciding what goes into the context window, what stays out, and what gets thrown away when it fills. The scarcest resource in any long-running AI system, and the one most teams manage by accident.
Deep dive10 stages129 topics
Short by design - ten sections, and padding it would be dishonest. This matters most for agents and long conversations, where a run goes forty turns deep and the window becomes the binding constraint on everything. If you only build single-turn features, read sections 2, 3 and 9 and skip the rest until you need them.
The Core Problem
Why this is a discipline and not just prompt length management. Understanding the failure shape determines every technique that follows.
Anatomy of the Window
Measuring and Budgeting
You cannot manage what you have not measured. Almost no team instruments this, and almost every team is surprised by what they find.
Just-in-Time Retrieval
Load when needed rather than preloading what might be needed. The single largest structural improvement available to most systems.
Compaction
Making history smaller without losing what the run depends on. Where most long-conversation systems either succeed or quietly break.
External State
The model does not need to hold what it can look up. Moving state out of the window is often better than compressing it inside.
Isolation and Sub-agents
Tool and Schema Economy
Tool definitions occupy the window on every single call, forever. They are the most consistently overlooked line item in the budget.
Caching
Failure Modes
How to recognise a context problem, which is rarely how it first presents.
Working the budget
When a long-running system starts degrading, work these in order. The instinct to reach for a bigger model or a longer window should come last, not first.
- Measure what's actually in there. Break the window down by section - system prompt, tool schemas, history, retrieved content, scratchpad. Most teams have never looked, and the answer is usually surprising.
- Cut what earns nothing. Tool schemas nobody calls, retrieved chunks nobody cites, boilerplate repeated every turn. This is usually the largest single win and it costs nothing.
- Move state out of the window. Files, a scratchpad, a database. Pass references instead of contents. The model does not need to hold what it can look up.
- Retrieve late instead of loading early. Fetch when needed rather than preloading everything that might be relevant.
- Compact the history. Summarise old turns, keep recent ones verbatim, preserve decisions and discard deliberation.
- Isolate with sub-agents. Give a subtask its own clean window and return only the result.
- Only now consider a longer window. More room is not better placement, and cost scales with everything you put in it.
Steps two and three usually recover more than the rest combined.
A context window is not storage. Everything in it competes for the model's attention, and adding a marginally relevant document makes the genuinely relevant one harder to use. The discipline is subtraction, not accumulation.