Agent Engineering

Context Window

Also known as: context length, token window

Definition

The context window is the maximum number of tokens a model can attend to in one request — system prompt, conversation history, retrieved documents, tool definitions, tool results and the response combined. It is a hard budget, and everything an agent knows in a given turn must fit inside it.

Last reviewed · Part of the Architecture Glossary

In practice

A long window is not the same as effective use of it. Two effects push against naive stuffing:

  • Lost in the middle. Retrieval accuracy is highest for material at the start and end of the context and measurably worse in the middle. Ordering matters, so put the decisive material last.
  • Cost and latency scale with input. Prefill is roughly linear in input tokens; a 100k-token context costs real money and real time on every turn of a conversation, not once.

The budget for an agent turn, allocated deliberately:

SliceTypical shareNotes
System prompt + tool schemas5-15%Fixed cost per turn — cache it
Retrieved context20-50%Rerank hard; more chunks is not better
Conversation history20-40%Summarise or window it
Response headroomreserve itAn overflow at generation time is a failed turn

Prompt caching is the lever that makes long system prompts affordable: a stable prefix is cached, so only the changing suffix is billed at full rate.

When it matters

Any multi-turn agent, any RAG design decision about chunk count, and any cost model for an LLM feature.

Common mistake

Treating a bigger window as a substitute for retrieval quality. Filling 200k tokens with loosely relevant chunks lowers accuracy and raises cost simultaneously — see retrieval vs generation failure for how to tell which half is actually broken.

See also

Go deeper