# 1.4 Context window anatomy

System prompt, tool schemas and message history share one finite token budget.

1. One finite token budget; no hidden state outside it.
2. System prompt and tool schemas form a fixed prefix.
3. Each turn appends reasoning and tool_result tokens.
4. At saturation, the oldest turns are truncated: context rot.

- **Use when:** Budgeting tokens across prefix, history and output.
- **Avoid:** Eager schema loading and raw log dumps: context rot precedes the hard limit.

```
context = [
    system_prompt,      # always there
    *tool_schemas,      # always there
    *conversation,      # grows every turn
]

if count_tokens(context) > LIMIT:
    # drop, shorten or summarise the oldest turns
```

## References

- [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) (Anthropic)
- [Context windows](https://platform.claude.com/docs/en/build-with-claude/context-windows) (Anthropic)
- [Context Rot](https://www.trychroma.com/research/context-rot) (Chroma)
- [Lost in the Middle](https://arxiv.org/abs/2307.03172) (Liu et al.)
- [Context engineering for agents](https://blog.langchain.com/context-engineering-for-agents/) (LangChain)
