AI Engineering from Scratch

Manuals

Each manual explains one subject at one exact version, from its purpose to each request and response. The examples come from recorded runs of a working system, and each rule links to the specification text that it comes from.

  • Read

    The web edition, with figures that play as you scroll.

  • Keep

    A PDF of the same text, attached to every release of the course.

  • Rerun

    A capture kit that regenerates every listing in the manual with one command.

Plate IOne planner, three remote agents
One planner, three remote agents The planner of the kit is a tall machine on the left with a slot for each of three lanes, in the order that the planner log records. In each lane the planner calls a remote agent, drawn as a machine with its port and skills, and the agent puts its task on a tray, one slip per state. test-runner completes with 13 passed, drawn as 13 cells on its top. code-reviewer asks which base branch to use, the planner answers main, and the task completes with one finding. deployer waits in TASK_STATE_AUTH_REQUIRED, the planner follows the task with SubscribeToTask, an operator outside A2A approves, and the task completes. CLIENT AGENT REMOTE AGENT THE TASK IT RUNS planner client agent reads 3 cards test-runner port 41241 skill run-tests SendMessage task 954267b7 TASK_STATE_COMPLETED summary.json: 13 passed code-reviewer port 41242 skills review-diff, answer-question SendMessage task 80bc7784 TASK_STATE_INPUT_REQUIRED TASK_STATE_COMPLETED review.json: 1 finding answer: main deployer port 41243 skill deploy bearer token required SendMessage task a31361b3 TASK_STATE_AUTH_REQUIRED TASK_STATE_COMPLETED build live on staging SubscribeToTask operator outside A2A approves Task ids shortened to 8 characters
The planner reads three cards and delegates three tasks: one completes at once, one after a question, and one after an operator approves. Lanes run top to bottom in the order of the planner log, and ids are shortened to 8 characters.
A2A protocol 1.0.1 · 3303592 · 2026-05-28 · Edition 2026.10

A2A 101

The Agent2Agent protocol, from its purpose to each request and response

How one agent gives work to another agent that it cannot see inside. Each request, response, and stream event in this manual comes from a recorded run.

  • The Protocol on One Page
  • AgentCard
  • Data Model
  • Operations
  • Bindings
  • Security and Extensions
  • Implementing A2A
7 parts · 28 sections · 31 figures
Plate IOne request wakes one actor
One request wakes one actor An isometric drawing of one request. A client terminal sends POST / through kubectl ate proxy. In the namespace ate-system, atenet-router with the Envoy mark calls ResumeActor on ate-api-server, which reads the actor row in Postgres and binds a worker. Below is the node kind-control-plane with the Kubernetes mark. On it are a worker pod drawn as an open frame, a gVisor sandbox inside it, atelet, and the object store as a bucket. atelet restores the golden snapshot into the sandbox, and the actor my-counter-1 goes from SUSPENDED, a dashed outline, to RUNNING, three solid layers for memory, file, and rootfs. The router then opens a tunnel to port 8443. The first request took 0.358 s, the next four took 0.062 s to 0.091 s, and a request after 900 s with no traffic took 0.080 s. THE REQUEST PATH · AGENT SUBSTRATE V1.0.0 my-counter-1 client curl -X POST kubectl ate proxy atenet-router Envoy dataplane ate-api-server control plane Postgres namespace ate-system actor row worker pod gVisor sandbox my-counter-1 memory file rootfs RUNNING SUSPENDED atelet object store rustfs bucket node kind-control-plane MEASURED AT THE CLIENT through kubectl ate proxy, x86 server guest after 900 s with no request: 60 of 60 samples RUNNING then a request took 0.080 s POST / 1 ResumeActor 2 read, bind 3 4 Restore 5 golden snapshot 6 tunnel, port 8443 7 first request 0.358 s next four 0.062 s to 0.091 s
On our test server, the first request to a suspended actor took 0.36 s, and the next four took 0.06 to 0.09 s. The router asked ate-api-server before each one.
Agent Substrate 1.0.0 · b34fbee · 2026-11-05 · Edition 2026.11

Agent Substrate 101

Install, run, connect, and debug stateful agent actors on Kubernetes, with a measured answer for each decision

How to install Agent Substrate, run actors that suspend and resume, control their network, connect kagent and agentgateway, and fix a cluster from the symptom. Measured on our own clusters with Agent Substrate v1.0.0.

  • Substrate on One Page
  • Start
  • Actors
  • Workers and Capacity
  • Identity and Access
  • Network
  • Integrations
  • Operate and Debug
  • Build
9 parts · 40 sections · 75 figures
Plate IOne agent, one microVM, one proxy
One agent, one microVM, one proxy The recorded docker-agent run --sandbox on the capture Mac, drawn as machines on a host bench above a glass microVM. On the host, docker-agent v1.149.0 stages the kit sandbox-kits/<hash>, writes the allowlist with models.dev and localhost:12434 into the proxy rules, and asks sbx and sandboxd v0.47.0 to create the sandbox, which becomes running. Below the Hypervisor.framework line, the microVM docker-agent-<hash> from docker/docker-agent-sbx-templates:latest holds docker-agent version main, its filesystem and shell tools, four workspace mounts, and an environment whose proxy is gateway.docker.internal:3128 and whose provider keys read proxy-managed. The model call goes up to host.docker.internal:12434, through the proxy on :3128, and on to Docker Model Runner on port 12434 with ai/qwen3:4b. The answer is: The working directory contains README.md with 1 line. HOST · MACOS 26.2 ARM64 docker-agent run --sandbox --exec files-sandbox.yaml docker-agent v1.149.0 Homebrew sbx, sandboxd v0.47.0 creates the VM proxy :3128 on the host applies the rules Model Runner ai/qwen3:4b port 12434 sandbox-kits/<hash> the kit docker-agent staged allowlist models.dev localhost:12434 create created, running Hypervisor.framework · kern.hv_support: 1 environment HTTP_PROXY gateway.docker.internal:3128 ANTHROPIC_API_KEY=proxy-managed docker-agent main commit 154b78f2 runs files-sandbox.yaml 4 workspace mounts repo-sandbox rw, agents ro sandbox-kits ro, cfg ro filesystem, shell tools that act on the mounts microVM docker-agent-<hash> · docker/docker-agent-sbx-templates:latest host.docker.internal:12434 through HTTP_PROXY :12434 The working directory contains README.md with 1 line.
The agent runs in a microVM that sbx creates, its model call leaves through the host proxy, and the provider keys inside are placeholders. Read top to bottom.
Docker Sandboxes (sbx) and Docker Agent (docker-agent) sbx 0.47.0, docker-agent 1.149.0 · bf4169c · 2026-10-07 · Edition 2026.10

Docker Sandboxes and Docker Agent 101

Isolated microVMs for coding agents, and the agent runtime that runs inside them, command by command

How to run an agent you do not trust on files you do. Every listing in this manual comes from a recorded run of sbx and docker-agent on one Mac.

  • The Two Products on One Page
  • sbx run
  • sbx policy, sbx secret, sbx mcp
  • Kits and sbxenv.yaml
  • docker-agent run and the Agent File
  • docker-agent serve and share
  • Operating It
7 parts · 33 sections · 34 figures
Plate IOne invoke, two model calls, one tool call
One invoke, two model calls, one tool call An isometric drawing of one create_agent run in one Python process. Above, on a LangChain layer, sit your code as a violet terminal, the chat model as a plum tower, and the tool add as a green unit. Below, the CompiledStateGraph from create_agent is an indigo shell with the LangGraph mark. It holds the model and tools nodes and the messages channel, drawn as four sheets. Your code calls invoke with What is 2 + 3? Model call 1 returns an AIMessage with the tool call add(a=2, b=3). The tools node runs add and returns a ToolMessage of 5. Model call 2 returns 2 + 3 = 5. The graph puts 5 checkpoints in InMemorySaver, steps -1 to 3, and the last has no next node. Off to the right, LangSmith is a dashed tower that gets 7 runs only when tracing is on. On the Mac, Apple M1 Max, with Qwen3 4B, create_agent spent 37.62 ms per run outside the model against 25.11 ms for a plain openai loop. ONE AGENT RUN · LANGCHAIN 1.5.0 · LANGGRAPH 1.2.22 · PYTHON 3.13 your code agent.invoke What is 2 + 3? 2 + 3 = 5. chat model call 1: tool_call add(a=2, b=3) call 2: 2 + 3 = 5. LangSmith outside the process POST 7, PATCH 7 tool add @tool, bound to the model LangChain model and tool objects CompiledStateGraph the Pregel loop from create_agent model tools messages HumanMessage AIMessage ToolMessage 5 AIMessage InMemorySaver thread memory-thread step -1 next __start__ step 0 next model step 1 next tools step 2 next model step 3 next () one Python process MEASURED ON THE MAC · APPLE M1 MAX outside the model: create_agent 37.62 ms per run, plain openai loop 25.11 ms +15.62 ms in the same round; with InMemorySaver 37.64 ms medians of 40 runs each, Qwen3 4B, a two-tool task with three model calls per run 1 invoke 2 call 1 3 add(a=2, b=3) ToolMessage 5 4 call 2 5 put 6 returns 7 7 runs, tracing on
One invoke of the kit's agent answers What is 2 + 3? with two model calls and one call of the add tool. InMemorySaver keeps five checkpoints, steps -1 to 3, and the last has no next node. With tracing on, LangSmith gets seven runs. On the Mac, with Qwen3 4B, create_agent spent 37.6 ms per run outside the model against 25.1 ms for a plain openai loop.
LangChain (Python): langchain, langchain-core, langgraph, deepagents, langsmith 1.5.0 · c2f4036 · 2026-11-11 · Edition 2026.11

LangChain 101

Build, run, persist, and debug agents with LangChain 1.5, LangGraph 1.2, and Deep Agents 0.7, with a recorded answer for each decision

How the LangChain Python stack turns a model, tools, and a prompt into an agent, and when you need it at all. A task suite with state checkers sets the plain loop, create_agent, LangGraph, and Deep Agents side by side on local and Claude models. Traces of real runs show the runtime inside, and a FastAPI service with Postgres and approvals runs it in production. Every listing comes from a capture of a real run with langchain 1.5.0, langchain-core 1.8.0, langgraph 1.2.22, and deepagents 0.7.38. Every measured number comes from a recorded run on a real model.

  • The decision
  • Inside the runtime
  • Models, messages, and tools
  • The agent, structured output, and middleware
  • State, memory, and durability
  • LangGraph control flow
  • Ecosystem
  • Operate
  • Production
9 parts · 60 sections · 102 figures
Plate IOne GRPO step on one GB10
One GRPO step on one GB10 One DGX Spark GB10 package drawn in iso: a Grace CPU die with 20 Arm cores and a Blackwell GPU die, both joined to one 128 GB slab of unified LPDDR5X memory at the center. An NVLink-C2C link joins the two dies. On the Grace die run the Ray head, the TrainerController and RolloutExecutor Ray actors, and the math reward. On the Blackwell die the FSDP trainer is active and the SGLang engine waits. Inside the shared slab the trainer state is the active footprint and the engine state is parked. The trainer onloads its state from the slab in 0.87 s, and the weight update from the trainer to the parked engine state takes 0.64 s. Below, one median step of 152.6 s to scale: rollout 47.5 s, log probabilities 23.4 s, GRPO update 77.0 s, weight update 0.64 s, and 4.2 s that the phase medians do not cover. Medians of 48 steps of a run made before we added the heat guard. ONE NVIDIA DGX SPARK · GB10 SUPERCHIP Qwen3-0.6B Ray head TrainerController RolloutExecutor math reward NVLink-C2C FSDP trainer FSDPTrainRayActor, active Blackwell GPU one die, shares the pool SGLang engine waits for new weights Grace CPU 20 Arm cores trainer state active footprint engine state parked in the pool LPDDR5X · 128 GB unified, one pool for both dies onload 0.87 s weight update 0.64 s ONE STEP TO SCALE · 152.6 S, MEDIAN OF 48 1 47.5 s 2 23.4 s 3 77.0 s 4 0.64 s 1 rollout, SGLang engine 2 log probabilities, trainer 3 GRPO update, Adam 4 weight update to the engine dashed end: median step minus the phase medians, 4.2 s. Trainer offload 0.76 s. Medians from the run made before the heat guard.
The SGLang engine and the FSDP trainer take turns on the Blackwell GPU. The one that waits stays parked in the same 128 GB pool. Medians of 48 steps on one GB10, from a run made before we added the heat guard.
Miles radixark/miles:latest, Miles main of 2026-10-15 · 08752a1 · 2026-10-15 · Edition 2026.10

Miles 101

Reinforcement learning on language models with Miles, from one GPU to a run you can trust

How to run GRPO with Miles on one GPU, choose a model that fits, and check that the run is correct. Every measured line comes from recorded runs on a DGX Spark.

  • Start
  • Size it
  • Recipes
  • Speed and stability
  • Check your run
  • Scale out
  • Debug
  • How Miles works
8 parts · 34 sections · 18 figures
Plate IOne function, four views
One function, four views The recorded run of rea function on ledger-arm64-O1 for _percent_change with the Ghidra provider, drawn as machines on one bench. You call rea 6.7.0, which hands the question to the BinarySession bound to ghidra, which calls the GhidraClient over bridge.sock, which launches Ghidra 12.1.4 as a headless JVM that imports and analyzes the artifact ledger-arm64-O1, a mach-o arm64 executable of 33872 bytes drawn as a stack of its file segments: __TEXT 16384 bytes, __DATA_CONST 16384 bytes, and __LINKEDIT 1104 bytes. The 24 bytes of _percent_change sit at 0x100000500 near the top of __TEXT. Three columns show the same function: the C you wrote in ledger.c, the pseudocode Ghidra decompiled with a second zero check the source never had, and the six instructions clang -O1 made from cbz w0 at 0x100000500 to ret at 0x100000514. The Evidence record ev_b492c85e at the bottom names the operation analyze_function, the provider ghidra 12.1.4, confidence observed, ten limitations, and the subject. FOUR VIEWS rea function ledger-arm64-O1 _percent_change --provider ghidra you ledger.c rea 6.7.0 the CLI BinarySession ghidra bound GhidraClient bridge.sock Ghidra 12.1.4 headless JVM ledger-arm64-O1 mach-o arm64 33872 bytes sha256 01b5d08b function execute call launch import _percent_change 24 bytes at 0x100000500 you wrote · ledger.c int percent_change(   int before, int after) {   if (before == 0)     return 0;   return (after - before)     * 100 / before; } Ghidra decompiled ulong _percent_change(   ulong param_1,int param_2) iVar2 = (int)param_1; if (iVar2 != 0) {   uVar1 = 0;   if (iVar2 != 0) {   uVar1 = ((param_2 - iVar2)     * 100) / iVar2;   param_1 = (ulong)uVar1; return param_1; clang -O1 made · 24 bytes 500 cbz w0, 0x100000514 504 sub w8, w1, w0 508 mov w9, #0x64 50c mul w8, w8, w9 510 sdiv w0, w8, w0 514 ret recorded Evidence ev_b492c85e for _percent_change operation analyze_function · provider ghidra 12.1.4 confidence observed · 10 limitations subject ledger-arm64-O1 · mach-o arm64
The C you wrote, the six instructions clang made, the pseudocode Ghidra returned, and the Evidence record rea wrote for them, from capture/out/06-function-percent-change.json.
rea (rea-agents) with the Ghidra provider rea-agents 6.7.0, Ghidra 12.1.4 · 27dc42d · 2026-10-18 · Edition 2026.10

Reverse Engineering 101

Reading a compiled program you built, from file bytes to evidence-backed pseudocode, with rea and Ghidra

How to read a compiled program without its source and prove what you found. Every listing comes from a recorded run of rea 6.7.0 and Ghidra 12.1.4 on programs written for this manual.

  • rea on One Page
  • Authority and Setup
  • The Artifact
  • The Ghidra Provider
  • Evidence
  • Scripted and Managed Code
  • Rebuild and Prove
  • Agents over MCP
8 parts · 26 sections · 37 figures
Plate IOne radix tree on one L4
One radix tree on one L4 The three SGLang processes run on the host CPU: the TokenizerManager, the Scheduler, and the DetokenizerManager, joined by ZMQ IPC. Below them is one NVIDIA L4 card with its SM array of 58 SMs and its 24 GB of GDDR6 drawn as one memory slab. In that memory the radix tree holds KV prefixes. The system prompt is one shared node of 2,998 tokens, and each repeated request attaches below it. A request with the id at the end attaches there too, with 2,986 of 3,033 tokens cached. A request with the id at the start shares only 6 tokens and starts its own branch. On our L4 the first request waited 2,143.9 ms for its first token, and the repeats waited 82.5 ms. HOST CPU · THREE SGLANG 0.5.22 PROCESSES Qwen3-8B TokenizerManager text to token ids Scheduler match_prefix, batches DetokenizerManager token ids to text ZMQ IPC x86_64 host NVIDIA L4 · GPU MEMORY SM array 58 SMs, Ada 24 GB GDDR6, six packages root system prompt node 2,998 tokens, shared id at the start: 6 of 3,032 cached, own branch match_prefix repeat request, round 3 1 new token, 2,998 of 2,999 cached id at the end: 2,986 of 3,033 ZMQ IPC TIME TO FIRST TOKEN ON OUR L4, SAME 2,999-TOKEN PROMPT first request 2,143.9 ms repeats 82.5 ms, median of 4 first request: 3 cached tokens, the system prompt was not yet in the tree
On our L4, the system prompt is one shared node of the radix tree, and each repeat request attaches below it. The repeats had 2,998 of 2,999 tokens cached, and the first token came after 82.5 ms instead of 2,143.9 ms.
SGLang 0.5.22 · baa9bef · 2026-10-13 · Edition 2026.10

SGLang 101

Serving language models with SGLang, from one request to a fleet, with the judgment the flag list leaves out

How SGLang turns GPU memory and time into tokens, why each feature exists, and which defaults to trust. Local listings come from recorded runs of SGLang 0.5.22.

  • Start
  • The Request Path
  • The KV Cache
  • Each Forward Pass
  • Measuring a Server
  • One Server Becomes a Fleet
  • Production and Training
7 parts · 29 sections · 63 figures
Plate IOne block pool on one L4
One block pool on one L4 The vLLM 0.31.0 API server and EngineCore run on the host CPU and talk over ZMQ. The Scheduler inside EngineCore builds one step under a token budget of 2,048 tokens: requests A and B decode one token each, and request C adds a prefill chunk. The block table of the KVCacheManager maps each request to blocks that are not all next to each other. Below is one NVIDIA L4 with its SM array of 58 SMs and 24 GB of GDDR6, where the KV cache is a grid of 16-token blocks: 1,506 blocks hold 24,096 tokens, and the grid shows 40 of them: the blocks of A and B, some of the blocks of C, and free blocks. HOST CPU · VLLM 0.31.0 PROCESSES API server HTTP, tokenizer EngineCore Scheduler KVCacheManager block table A · 2, 13, 31 B · 7, 8, 26, 38 C · 17, 18, 27, 28, 35, more ZMQ allocate_slots x86_64 host ONE SCHEDULER STEP budget 2,048 tokens A decode, 1 token B decode, 1 token C prefill chunk, 2,046 tokens The decode slivers are drawn wider. Decodes go first, then a prompt chunk fills the rest. NVIDIA L4 · GPU MEMORY SM array 58 SMs, Ada KV cache · 16-token blocks 1,506 blocks, 24,096 tokens 24 GB GDDR6, six packages in use free · 40 of 1,506 shown With 8 users the log read: GPU KV cache usage 77.2%, prefix cache hit rate 87.2%. Block ids show the mapping only. Pool, block size, and budget are from our L4 runs.
The Scheduler fills one step under a 2,048-token budget. The block table maps each request to blocks that are not all next to each other. On our L4 the pool held 1,506 blocks of 16 tokens.
vLLM 0.31.0 · db9527a · 2026-10-05 · Edition 2026.10

vLLM 101

Serve, size, tune, and debug open models with vLLM, with measured answers for each decision

How to install vLLM, fit a model on your GPU, tune it for your traffic, and fix it from a symptom. Measured on an NVIDIA L4 and a DGX Spark with vLLM 0.31.0.

  • Start
  • Size It
  • Tune for Your Traffic
  • Speed Features
  • Measure
  • Scale Out
  • Operate and Debug
  • How vLLM Works
8 parts · 44 sections · 26 figures