The Context Engineering Handbook
The map for everything after it: what fills a production window (system prompt, tools, examples, retrieved knowledge, history, memory and the request), why stuffing more in fails through attention, cost and behavioral drift, and the four operations of write, select, compress and isolate. Read it first for the vocabulary, then return at the end and check that you can work its quadratic-cost example yourself.
The Tokenizer
Before you can budget a window you need its unit, and this lab shows text shattering into sub-word tokens, races character, word and sub-word tokenizers, and has you run Byte-Pair Encoding merges by hand. It explains the practical surprises, such as why code, numbers and rare names cost more tokens than ordinary prose and why models stumble at counting letters.
Token Counter
Paste a real system prompt, document or code file and get an estimated token count, the input cost across several models, and how much of each window size from 8K to 1M it would fill. Use it to replace guesses with numbers, starting from the rules of thumb that hold for English prose, about four characters per token, and why code and some non-Latin scripts cost more.
Context Window Visualizer
Set token counts for the system prompt, tool definitions, retrieved context, chat history, the user message and an output reserve, then watch a stacked bar fill the chosen window and overflow. The overflow panel estimates how much compaction would have to remove, which trains two habits: reserving room for the answer, and spotting which band, usually history or retrieval, is crowding out the rest.
Context Budget & Cost Planner
The same segments, priced: model a conversation turn by turn and see peak context, total input tokens with history resent on every turn, and the cost per conversation, day and month at a chosen price tier. It makes the compress operation concrete, because you can shorten the history you resend and watch the monthly bill fall before you change any code.
Trim History to a Token Budget
Implement the simplest compress operation: given the token counts of a conversation's messages, keep the most recent ones that fit a hard budget, walking back from the newest and stopping at the first message that would overflow. Hidden tests cover edge cases such as a single message larger than the whole budget, and the result is the baseline any summarizing compaction has to beat.
The RAG Handbook
Retrieval is the select operation at its most common, and this handbook covers the two-phase pipeline, chunking and its token arithmetic, embeddings and vector search, hybrid retrieval, reranking for precision at the top, grounded generation with citations, and evaluation, ending with a whole pipeline in about 60 lines. It prepares you to decide how many retrieved tokens a turn deserves and how to check that the right ones arrived.
RAG Chunking Playground
Chunking decides what a single retrieved unit costs and what it carries, so try fixed, recursive, sentence and paragraph strategies on your own text and read the token count of each chunk. A few rounds here show why a few hundred tokens with modest overlap is a common starting point, and when prose or code calls for a different split.
Design an Agent Memory System
The write operation as a system: why stuffing history fails, a working set plus a persistent store, a write path that distills instead of dumping, vector and structured stores, a recall path that scores relevance, recency and importance, consolidation and forgetting, and the risks of stale, private or poisoned memories. It prepares you for the design question of how an assistant remembers a user across weeks without its prompt growing.
MemGPT
MemGPT treats the context window as RAM and external storage as disk, with the model managing its own memory through function calls: paging documents in, writing facts out, and summarizing before eviction when memory pressure raises an interrupt. Read it right after the memory design to compare a fixed retrieval policy with self-directed memory, and to explain what each approach trades away.
The Agent Skills Handbook
Skills are the isolate operation packaged: a folder whose SKILL.md body loads only when its one-line description matches the task, so dozens of playbooks cost little more than their descriptions until one is used. The handbook compares skills with tools, MCP and fine-tuning, shows how to write descriptions that actually trigger, and treats skills as dependencies with a security surface of their own.
The Loop Engineering Handbook
Context engineering shapes one run, while loop engineering shapes the system around many runs: when to compact, when to hand a subtask to a sub-agent with a fresh window, and how state recorded outside the model lets the next run resume. Read it for the failure modes that are context problems in disguise, such as quality decaying in a marathon context and every run starting from amnesia.
Self-Improving Agents
When an agent learns from its own runs, the lesson has to land somewhere: in the context, external memory, the tool set, the scaffold, the verifier or the weights. This long handbook compares all six, and its case that context is usually the cheapest and most reversible place is why it sits on this path, along with its guidance on which traces are worth keeping.
Design ChatGPT
The capstone shows context engineering in a large consumer chat product: a conversation store sharded on its access pattern, context rebuilt from scratch on every turn, a model router as the cost lever, and prefix caching that only pays off when the stable parts come first. It prepares you to explain cache-aware prompt ordering and how caching a shared prefix saves prefill work on every turn.