Context Window in depth
Planning a context budget
Treat the context window as a budget you allocate deliberately. For each request type, list what goes in and roughly how many tokens each part uses:
- System instructions and policies
- Tool definitions (agents with many tools can spend a large share here)
- Conversation history or agent step history
- Retrieved documents or records
- Room reserved for the model's output and any reasoning tokens
Measure these with the provider's token counting endpoint or tokenizer rather than estimating from word counts, especially for Hindi and other Indic scripts, which often use more tokens per word than English.
Example: a long-running support conversation
Example: a hypothetical support agent handles a customer who has been messaging for several days about a delayed replacement. Sending the full history every turn would grow cost and latency with each message and push early details into the middle of a long prompt. Instead the application keeps the last several turns verbatim, a running summary of earlier turns that records key facts (order number, promised dates, what was already tried), and fresh lookups from the order system on each turn. The stable system prompt and tool definitions sit at the start so prompt caching can reuse them.
Context engineering techniques
| Technique | Use it when |
| Retrieval instead of stuffing | The knowledge base is larger than a few documents; see RAG |
| Summarizing old turns | Conversations or agent runs are long |
| Tool result trimming | APIs return large payloads; keep only fields the task needs |
| Loading tools on demand | An agent has many tools but uses few per task |
| Sub-agents with fresh context | A sub-task needs heavy reading; return only its conclusion |
| Ordering | Put instructions and the question where the model attends well, not buried mid-prompt |
How to test long-context behavior
Do not rely on the advertised limit. Build evaluation cases where the needed fact sits at different positions and amounts of context, and check accuracy as the prompt grows. Measure cost and time to first token at each size. Often a retrieval approach with a smaller context matches or beats a full-document approach on accuracy while being faster.
Record token counts for each part of the prompt on every request, not just the total. When cost or latency rises, this breakdown shows immediately whether history, tool definitions or retrieved documents grew, which turns a vague complaint into a specific fix.
Common mistakes
- Sending entire documents "because the window is big enough", then paying for it on every request.
- Silent truncation: the application cuts history at the limit without telling anyone, and the model loses the customer's original problem.
- Forgetting that output and reasoning tokens share the same window.
- Assuming the same limits and behavior after switching models or versions.
The context window is measured in tokens, filled through chunking and retrieval, and shaped by prompt engineering. Our agent running cost estimator shows how context size drives spend. We design context strategies in AI cost optimization and AI-powered search.