# Chapter 5: Context

Part of the course “AI from Zero to Autonomous Agents” (https://llm.yoga/en). Page for humans: https://llm.yoga/en/05-kontext

*The model only knows what’s in the request. Context window, history, prompt techniques and context engineering, with a cost calculation for a conversation over 20 rounds.*

About 25 min to read · about 20 min hands-on exercise

**Start with the missions**

This chapter also comes as 4 short missions with a case, a decision and feedback, about 10 minutes each:

- [5.1 Why does the support chat get more expensive with every round?](https://llm.yoga/en/einsatz-5-1.md)
- [5.2 A million tokens, so put all 50 contracts in?](https://llm.yoga/en/einsatz-5-2.md)
- [5.3 Does “Think step by step” belong in every prompt?](https://llm.yoga/en/einsatz-5-3.md)
- [5.4 The bot forgot the beginning](https://llm.yoga/en/einsatz-5-4.md)

For agents, this page is split into 4 parts so that each part can be fetched in full. Read the parts the question needs.

## Parts

### Part 1: https://llm.yoga/en/05-kontext-1.md

- **Getting started**: Picture a very good consultant who forgets everything after each phone call.
- **The context window**: The context window is the maximum number of tokens a model can process in a single request.
- **What’s in the context**: A request to a chat model consists of several parts that go into the model together, in the order they appear, as one long token sequence.
- **Every request starts from zero**: Anthropic’s docs say it in one sentence: the Messages API is stateless, and you always send the complete conversation history along.

### Part 2: https://llm.yoga/en/05-kontext-2.md

- **Why long contexts are expensive**: A long context costs you in three ways, and all three grow with every round.
- **Why long contexts become unreliable**: You might think a window of a million tokens solves every problem: just dump everything in, and the model will find what it needs.
- **Context engineering**: A discipline of its own has grown out of these findings.

### Part 3: https://llm.yoga/en/05-kontext-3.md

- **Prompt techniques**: Within the context there are proven ways to pose a task.
- **Compaction and context editing**: At some point even the best history gets too long.
- **Prompt caching in brief**: The fixed beginning of a request, the system prompt and tool definitions, is the same in every round.
- **Exercise: watch the context grow**: Goal: you see how the input grows with every round and experience what happens when the context window is too small.
- **Common misconceptions**: The model remembers what I said earlier in the chat.

### Part 4: https://llm.yoga/en/05-kontext-4.md

- **Review questions**: 1. A conversation has a fixed part of 5,000 tokens, user messages of 100 tokens and answers of 500 tokens.
- **Go further**: Anthropic: Effective context engineering for AI agents (September 29, 2025).
