Skip to content

Prof Rod’s bookshelf · free to read

Build Your Always-On AI Agent From Scratch

Tools, memory, permissions, and reliable operation in Python.

You may already use an agent product. Building a small one yourself shows you what any of them must do when the process restarts, a supplier stops answering or a purchase needs someone’s approval. You finish able to judge, configure and explain the agents you rely on.

Build Lucy’s agent in Python: give it tools and memory, put it on her phone, and let it handle work with permissions and recovery.

By Rod Rivera · 21 chapters, all in draft

Read and practice without an account. The agent you build is for learning, not production.

The Prof Rod library

Build Your Always-On AI Agent From Scratch

Prof Rod reading

Rod Rivera

Before you begin

A working system, one chapter at a time

Who it’s for

You already write code and want to put an agent in charge of real work without losing the ability to explain what it did and why. You can write Python functions and classes, use a terminal and read JSON. Basic SQL helps, and the chapters explain each query they rely on. No agent framework is assumed. Start with the preface and prerequisites.

What you’ll build

A model and tool loop, persistent memory, a Telegram adapter, scheduled work, approvals and recovery. Draft chapters explain the mechanisms; notebooks identify which runtime components are supplied.

Why build one

Four things every useful agent has to get right

A demo needs a model and a prompt. An agent you leave running needs these as well, whichever product or framework supplies them. The book has you build each one small enough to read in full.

Tools
A model can only propose. Tools are how a proposal becomes a stock lookup or a draft order, and their inputs and errors decide whether a wrong guess is caught or carried out.
Memory
A model keeps nothing between requests. What the agent knows tomorrow is what your code stored, selected and sent again, including the correction that replaced yesterday’s answer.
Permissions
A sentence in a prompt cannot reserve money or expire. Approval has to be a record tied to one exact proposal and checked again at the moment of sending.
Recovery
Processes stop and replies get lost. The agent has to find out what already happened from records and receipts before it acts again, or it buys the vanilla twice.

Two ways in

Start at the beginning, or start from a question

The question map

Find the chapter that answers your question

Every chapter here is a manuscript draft with runnable code, free to read without an account.

What survives an agent restart?

Whatever your application committed to storage and reloads. The conversation held in the process does not.

It assumes: Chapter 5 runs today on a database helper supplied with the book. Building that store yourself is Chapter 4.

How do you know whether an action actually completed?

From the other system's receipt, found again with a stable operation identity. A timeout or the agent's own sentence proves nothing either way.

It assumes: Chapter 12 continues from Chapter 11's approved order and still uses the book's supplied work queue; Chapter 8 has you build your own.

How do you require approval before an external change?

Approve one exact proposal, identified by a digest of its contents, and check that approval again at the moment of sending. A changed amount needs a fresh decision.

It assumes: Chapter 11 reuses the draft-order tools from Chapter 10 and still uses the supplied work queue; Chapter 8 has you build your own.

How does an agent recover after interruption?

A replacement worker claims the same durable assignment under a new generation, and every consequential write checks that claim. It reads records, not a summary, to learn what already happened.

It assumes: Chapter 13 follows directly from Chapter 12. Its checkpoint needs a Linux or macOS host because it stops a real process.

A short decision aid

Configure one, extend one, or build one to learn?

These are different jobs. The book serves the third, and makes you better at the first two.

Configure an existing agent

when the task is one the product already handles and its records, permissions and recovery meet your need.

Check first: can you see what it stored, what it sent and who approved it?

Extend an existing agent

when the product fits but lacks a tool, a data source or a rule that is specific to your work.

Check first: what authority does your extension get, and what happens to its work after a restart?

Build a teaching implementation

when you need to understand the mechanisms well enough to answer those checks, to evaluate a product or to explain a failure to someone else.

That is this book. The result is a small agent you can read in full, not a replacement for a maintained product.

Where the chapters compare their design with an open-source agent project, they name the exact commit inspected and the date, and say which part is documented and which is interpretation. See the project comparisons.

Textbook, exercises and solutions

Keep your first attempt before opening the worked answer. The 42 practice units pair construction with repair and a changed case. Each unit has a ninety-minute work plan; learning time varies.

The reading order

Inside the book

Begin with one model call, then build through four parts. Keep the matching checkpoint open beside the chapter you’re reading.

Read, run the example, then test what happens when it breaks. Original edition and labs

Report an error in the book ↗