Lesson 01.02 · Phase 01 · LLM Foundations for Agents
Tokens and the context window
Models don't read characters or words. They read tokens, and every limit and price you'll meet is counted in them.
Learning objectives
- Explain what a token is, and implement byte-level byte-pair encoding (BPE): training, encoding and decoding.
- Explain why real tokenizers split text into word-sized chunks before merging.
- Measure how many tokens different kinds of text cost (prose, code, JSON, numbers, other scripts, emoji) with a real tokenizer.
- Budget a context window: fixed costs, reserved output, and how much history still fits.
"The context window is 128K" sounds like plenty, until an agent's run fills it with tool results. Then you find out what a token is the hard way: the 4,000-character report is 1,000 tokens, the JSON is more than you'd guess, and the same question in Hindi costs three times what it costs in English.
Loading the full lesson…