Each notebook is a worked example you can read here or download and run. They all run offline with no API key (see Running the notebooks); set MODEL to repeat them against a real model.
| # | Notebook | What you build | Module |
|---|---|---|---|
| 01 | Notebook 1: The agent loop | A fixed workflow, then a 20-line agent loop built from scratch: tools, observations, budgets, and the trace. | Module 1 |
| 02a | Notebook 2a: Tokens and BPE from scratch | Build a byte-level BPE tokenizer, see how vocabulary size trades off against compression, and count what an agent’s prompts really cost. | Module 2 |
| 02b | Notebook 2b: A tiny language model, sampling, and constrained decoding | Train a character n-gram model, implement temperature, top-k and top-p sampling, and force valid tool-call JSON with a grammar mask. | Module 2 |
| 02c | Notebook 2c: The LLM client | Messages and statelessness, one client for every provider, validated structured output, concurrency, retries, caching and a cost budget, each built as a small layer. | Module 2 |
| 03a | Notebook 3a: Function calling from scratch | A tool call on the wire, schemas generated from Python signatures, argument validation, a registry whose errors become observations, a linter for tool definitions, and a search tool sized for a token budget. | Module 3 |
| 03b | Notebook 3b: MCP, a standard plug for tools | Build an MCP server with FastMCP, talk to it in memory, by hand over stdio, and with the SDK, then wrap its tools for an agent and check what you are trusting. | Module 3 |
| 04 | Notebook 4: The ReAct agent | ReAct as a text protocol and as native tool calls; an agent built from its parts (context, events, tools, run/step/think/act); stop rules; structured output; a mini benchmark. | Module 4 |
| 05a | Notebook 5a: Retrieval from scratch | Chunking a small handbook three ways, BM25 written from the formula, hashed vectors in a numpy vector store, hybrid search with reciprocal rank fusion, and recall@k on 24 labelled questions. | Module 5 |
| 05b | Notebook 5b: Agentic RAG | Retrieval as a tool the agent calls with its own queries, a multi-hop question, file tools that follow the corpus’s folders, tool callbacks that log, cache, guard and compress, and a human approval step before an email goes out. | Module 5 |
| 06a | Notebook 6a: Context management | What an agent stores against what it sends, counting tokens, a sliding window that does not break tool calls, compaction, summarisation, a replaceable rule for when to act, and four strategies compared on one long task. | Module 6 |
| 06b | Notebook 6b: Sessions and long-term memory | Sessions stored as JSON files that survive a restart, a paused tool call resumed in a new process, and long-term memory: structured extraction, de-duplication, a vector store per user, and memories injected into a later conversation. | Module 6 |
| 07 | Notebook 7: Planning and reflection | One multi-part expense question with a failing rate service, given to a ReAct agent, an agent with a plan tool, one with a reflection tool and one with both: what each tool adds to the context, what it fixes, and what it costs in steps and tokens. | Module 7 |
| 08a | Notebook 8a: CodeAct and a local sandbox | Build a layered sandbox for model-written code, wrap it as an execute_python tool, and compare CodeAct with JSON tool calls on the same task. | Module 8 |
| 08b | Notebook 8b: Workspaces and skills | Give an agent a folder, a shell and four file tools with a path check, then teach it new tasks with SKILL.md folders that load only when needed. | Module 8 |
| 09a | Notebook 9a: Workflows, agents as tools, and handoffs | Split a help-desk task across several agents three ways (a fixed workflow, an orchestrator calling agents as tools, and handoffs) and measure what each agent sees. | Module 9 |
| 09b | Notebook 9b: Agents over the network with A2A | Serve an agent over a small, faithful subset of the Agent2Agent protocol (an agent card and JSON-RPC message/send on 127.0.0.1), call it by hand, keep a remote conversation going, and let a local agent use two remote agents as tools. | Module 9 |
| 10a | Notebook 10a: Tracing an agent | Spans for every agent run, step, model call and tool call, with tokens, estimated cost and latency, a tree view, metrics, and a JSONL export. | Module 10 |
| 10b | Notebook 10b: Evals, graders and judges | A task suite with code-based graders, repeated trials scored with pass@k and pass^k, error analysis, a rubric judge checked against human labels, and a CI gate that blocks a regression. | Module 10 |
| 11a | Notebook 11a: The data flywheel and prompt optimisation | Turn production traces and feedback into a labelled dataset, then improve a prompt automatically with bootstrapped few-shot demos, random search and a reflective instruction search, scored on a held-out test set. | Module 11 |
| 11b | Notebook 11b: GRPO on a toy tool router | Write REINFORCE, a baseline, GRPO’s group-relative advantages, ratio clipping and a KL penalty in numpy, train a tool router with them, then fit a Bradley-Terry reward model to biased preferences and watch the policy exploit it. | Module 11 |
| 12 | Notebook 12: Prompt injection and guardrails | Watch a browsing agent leak a secret because a web page told it to, then stop it with layers that do not depend on the model: a permission policy, an egress allowlist, the quarantine pattern and taint tracking, and see why a heuristic detector is not enough. | Module 12 |
| 13 | Notebook 13: A mini coding agent | Build a bash-only coding agent that fixes a small repository until its tests pass, and engineer the harness around it: the tool’s output format, truncation, a step budget, a progress file that survives a context reset, and a sandbox. | Module 13 |