What is context engineering?
Prompt engineering asks how to phrase an instruction. Context engineering asks what information should be in the window at all, in what order and at what size, for every step of a long-running agent.
What competes for the window
| Component | Typical size | Notes |
|---|---|---|
| System instructions | Hundreds to a few thousand tokens | Stable; cache if your provider supports it |
| Tool definitions | Grows with each tool | Load only tools relevant to the step |
| Conversation so far | Grows every turn | Trim or summarize older turns |
| Retrieved documents | k × chunk size | Tune k; deduplicate |
| Memory | Your recall budget | Current facts with dates and sources |
Why long runs are harder
Agents that run for many steps accumulate tool outputs and intermediate thoughts. Without pruning, relevant facts are buried and costs grow per step. Write important intermediate results to memory and recall them when needed, instead of carrying everything forward.
Four context operations
Select
Choose what is relevant to this step: recall, retrieval, tool subset.
Compress
Summarize or truncate long items.
Order
Put instructions and the most important facts where the model attends to them.
Isolate
Give sub-agents only the context they need.
Set a budget per component
Decide a token budget for each component and enforce it in code. For memory, pass maxTokens to recall; the token cost calculator shows what each choice costs per month.
Frequently asked questions
Is context engineering only about cost?
No — overfull windows also reduce answer quality and make behaviour harder to predict.
Where does memory fit?
It is the select step for anything that happened before this session.