Skip to content

resource

Build a Python AI Agent: Textbook and Chapter Guide

Follow the twenty-one-chapter plan from a first model call to an unattended shop day. Find the drafted chapters, planned foundations and matching practice materials.

Edition: construction · Updated: 2026-09-09

Build Your Always-On AI Agent From Scratch follows one Python agent from its first model call to an unattended day in Lucy's ice cream shop. Read the chapters in order. Each introduces a problem, constructs a mechanism, reproduces a failure and explains the repair.

Start with the preface and setup and reader conventions, then Chapter 1. This directory contains the manuscript and its accompanying code. The Exercise Book holds learner assignments, the Solutions Book holds worked answers, and the Educator Guide holds classroom material. Chapter numbers and topics match across all four assets.

What is available

There is one twenty-one-chapter sequence. All twenty-one chapters contain substantial DRAFT manuscripts and executable checkpoints; Chapter 4's runs the learner's own store, and Chapter 8's the learner's own work queue on it. The construction roadmap records the remaining work and the integration commitments.

You can read the drafted chapters and run their supplied reference checkpoints now. Building the entire system solely from your own preceding chapter code remains a release requirement. The code ownership guide names the supplied components so a working demonstration cannot be mistaken for a completed from-scratch construction.

Contents

ChapterReadStatus
1What a model call is: tokens, probabilities and Lucy's first briefDRAFT
2Structured output and typed tools: what a schema guaranteesDRAFT
3The agent loop: why reliability compounds, and a loop that stopsDRAFT
4Build durable state with SQLiteDRAFT
5Memory and retrieval: what the model sees, and a memory that forgetsDRAFT
6Embeddings and vector search: when words are not enoughDRAFT
7In-context learning: why a skill's exact words must be testedDRAFT
8Build a durable work inbox and report outboxDRAFT
9Where the wait goes: prefill, decode and a phone channelDRAFT
10Events at random: queues, utilization and scheduled workDRAFT
11When to ask: calibration, oversight and spending permissionDRAFT
12Exactly one order: lost replies, retries and idempotencyDRAFT
13Slow or dead: leases, fencing and crash recoveryDRAFT
14External tools with MCP: the protocol connects, the application decidesDRAFT
15Prompt injection and isolation: words steer the model, boundaries holdDRAFT
16Evaluation as measurement: error bars and paired comparisonsDRAFT
17Optimizing against an evaluation: the winner's curse and preferencesDRAFT
18When a second agent pays: parallelism, errors and bounded delegationDRAFT
19What a model call costs, and a deployment that survivesDRAFT
20A whole day: reliability, honest reports and readinessDRAFT
21Context engineering: a budget for what the model seesDRAFT

The four parts are: 1–4, First useful construction; 5–9, Continuity and initiative; 10–14, Permission and external boundaries; and 15–19, Evaluate and operate.

Working beside the manuscript

Use runnable checkpoints to reproduce the recorded mechanisms. Save chapter-built tools and the loop under learner/; the included completed files provide a comparison. The optional field appendices explain Telegram identity setup, Linux maintenance, ZeoCore interoperability, reproducibility, and dated architectural comparisons.

The book uses a frozen Python environment from the repository root. Offline checkpoints need no model credentials, Telegram account, real purchasing account or private organizational service. Optional live exercises identify their extra facilities and keep their evidence separate. Return to the four teaching assets.

Find and share a file

Every teaching file starts with profrod-sovereign-agent, followed by its chapter, topic and role. Search for ch02 to find Chapter 2 or pydantic to find its typed-tool material. For example: profrod-sovereign-agent-ch02-a-pydantic-shop-tools-exercise.ipynb. The exercise, solution, educator-exercise and educator-solution endings distinguish files even when copied into one folder. Keep the original filename and source links when sharing. The matching Markdown uses the same filename with .md.

Keep building with Prof Rod

Found this material through a colleague, classroom or shared download? Get the complete book at profrod.ai/book and join the Prof Rod learner community. Bring one result, one question or one failure you learned from. Share this resource with another learner and keep its source links with it so they can find the full course and future updates.