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

ComponentTypical sizeNotes
System instructionsHundreds to a few thousand tokensStable; cache if your provider supports it
Tool definitionsGrows with each toolLoad only tools relevant to the step
Conversation so farGrows every turnTrim or summarize older turns
Retrieved documentsk × chunk sizeTune k; deduplicate
MemoryYour recall budgetCurrent 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

  1. Select

    Choose what is relevant to this step: recall, retrieval, tool subset.

  2. Compress

    Summarize or truncate long items.

  3. Order

    Put instructions and the most important facts where the model attends to them.

  4. 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.