How this book was made
This book was not written the usual way. It was generated by Claude, an AI model, working in Claude Code. It started from one prompt from its reader and followed a short conversation in which they steered it. That reader is also the person the book was written for. This page records that prompt, the steering, and how the chapters were produced and checked, so you can judge the text knowing where it came from.
The prompt
Everything that follows grew out of this request:
If you scan my org files […], Obsidian […], and github […], you can figure out what my technical proficiency is. I need a gitbook repo with a course on agentic AI engineering, starting from first principles.
Calibrating to one reader
The first step was reading the material the prompt pointed at: an org-mode notes tree, an Obsidian vault, and several hundred public GitHub repositories. The aim was to place the reader, not to summarize them. Three summaries came back, and they agreed with each other:
- Strong enough to skip:
- systems programming, mostly Go, then C and C++, with a long tail through Lisp, Haskell and Rust;
- applied cryptography and security engineering;
- distributed infrastructure: NixOS, podman, Tailscale;
- a habit of building tools from scratch: editors, Lisps, interpreters, a CA;
- hands-on operation of a local llama.cpp inference fleet;
- daily use of several agent harnesses.
- Thin, and therefore where the course should spend its time:
- transformer internals;
- writing a raw agent loop;
- formal evaluation design;
- prompt and context engineering as a discipline;
- MCP internals;
- retrieval and vector indexes;
- fine-tuning.
- Math: applied and self-taught. Intuition comes first, and no derivation step is skipped.
That profile is why the book never explains a for loop but derives the law of cosines one line at a time.
The steering conversation
The design was settled in a few exchanges. What the reader said, and what each answer changed:
- How deep “first principles” goes. The options were model mechanics, the API and loop, or the math. The reader chose the math. So Part I rebuilds vectors, matrices, probability, calculus and autodiff before any model appears.
- Language. A split: Python with only
numpyfor the math, the model and the model server, and Go, the reader’s strongest language, from the router onward. - How much to write. The whole course, written out in full, delivered one part at a time with a review between parts.
- The end state. “The end state is writing my own hermes or openclaw analog, if that helps steer the discussion. In order to do that, I want to understand the entire stack.” This turned a survey course into a build toward a persistent agent daemon. It added chapters on the daemon runtime, channel gateways, scheduling and autonomy, skills, a model of the user (owned by the memory-service chapter), code-execution sandboxes and a policy engine. It also added a chapter on how inference engines work inside.
- The reader’s own infrastructure. An inventory of the reader’s inference fleet was shared: which hosts serve which models, and the fetch, memory and gateway services. The course was then pointed at real endpoints instead of hypothetical ones. Its examples use the reader’s own systems: the web tools, the memory service, the Mattermost gateway and the routing roles.
Four more steers:
- “For the cloud target, I think z.ai might be cheaper.”
- “It would be useful to learn how to write my own routing model server.”
- “It would be instructive to build a toy vector database like honcho.”
- “I’m also fine with a local model … carrying the main loop, if that’s useful as well.”
These added a whole part on serving models, with your own inference server, constrained decoding, batching and a router. They also split the memory chapters into a vector database built from the HNSW paper and a memory service on top of it. Finally, which model runs the capstone’s main loop became a question for the evaluation chapters to answer, rather than an assumption.
- Housekeeping. Each completed part is rebased and fast-forwarded onto
master. The title and cover were the reader’s. - Putting the agent to work. Partway through Part II, the reader asked: “Would it make sense to do a chapter (or more) on using the agent we build to work effectively as a ‘modern’ software engineer in an AI-first world?” That added Part X, after the capstone. It takes this book’s own production pipeline, described below, as its case study.
- The rest of the model zoo. At the end of Part II, the reader asked whether the book covered mixture-of-experts, reasoning models and other model types, then said: “The not covered topics listed above, I would like coverage of them.” That added mixture-of-experts, reasoning models, distillation and a guide to reading a model’s name to chapters 11, 13 and 14. It also added two chapters: one on encoders, state-space models and text diffusion, and one on multimodal models. The reader’s notes on decision models (typed, calibrated answers in one forward pass) added a chapter that builds a small one, used as a gate by the agent’s router and policy engine.
- An outside review. The reader also had another model review the syllabus against the reader’s profile. Its gap list became the design document’s cross-part obligations: traces before observability, crash-safe tool calls, approval as a protocol, injection through memory, trajectory evals, and a named owner for the user model. A few of its suggestions were declined, and the design document records why.
- A sibling. On the day Part II was published, the reader announced a counterpart in progress, The Hearthwright’s Primer: “If this Primer teaches you how to build an intelligence, the Hearthwright’s Primer teaches you how to house it.” The two share a shape, conventions and a reader. This book gained one optional joint, a
wardsandbox backend for the daemon’s tool runs, which refuses until the sibling’swardexists, and a discussion of where a small decision model should run. The joint is optional in both directions. - Calibration on its own. Written out, the decision-models chapter held two subjects: honest probabilities, and the models that produce them. The reader agreed to a split: “If it makes sense to have a separate calibration chapter and/or to save the material relevant to the audit section for later, that’s fine.” Calibration became its own chapter, just before decision models, and the long design of the optional run on the reader’s own history was set aside as notes for the secrets and audit chapter.
The resulting syllabus has 55 chapters in eleven parts. It is recorded, with every decision above, in the repository’s design document. The reader’s decisions continued through every part (which hosts and models a capture may touch, what to measure, what to defer), and the decisions log records each with its date.
How the chapters were produced
Each part went through the same pipeline.
- A written plan. Each task gets exact file paths, the reference code in full, the tests that pin it, and an outline of the chapter that goes with it.
- Implementation by a fresh agent per task. Tests are written first and the code follows them. Every listing of the reference code in the chapters’ walkthroughs is pulled from the source files by a small tool, and the build fails if the two ever disagree. Program output shown in the text is copied verbatim from real runs.
- An independent review of every task. A different agent checks the work against the plan and the writing standards. For chapters it also re-derives the mathematics and recomputes every number the chapter prints.
- Fix rounds after each review, re-reviewed until the review comes back clean or, for some chapter fix rounds, closed on the controller’s reading of the gate log; then a review across the whole part by a different model, one fix wave and a re-review. Chapter 55 counts what the record shows of these rounds.
The reviews caught real errors in Part I before they reached this text:
- A rank argument named the wrong matrix.
- Gibbs’ inequality was applied to the wrong entropy. The stated conclusion held only by coincidence.
- A chain-rule derivation skipped its remainder terms.
- Book citations described chapters that cover something else.
Lessons like these were written into a standing rulebook, kept in the repository, that later chapters are held to. Every commit an agent wrote names the model that wrote it; three of the reader’s own commits carry no trailer.
What that means for you
The prose, derivations and code were machine-generated under human direction, and then checked by machine: tests, gradient checks, recomputation and cross-review. That process catches a lot, but it does not replace your own scrutiny. The book asks you to derive things yourself and to run the labs against your own code, and that stance is also the right one toward the book. Where it is wrong, the tests and your own derivations are how you will find out, and fixes are welcome.