cCarebun Reading‹ All reading
Carebun Interactive/Agents whiteboardpattern catalogueglossary Study view

An interactive textbook

AI Agent Loops and Graphs
Novice to Ninja

Loop engineering and graph engineering for people who have used agents and want to build them: loops first, then graphs, then real problems. One small open-source library, agl, is the companion code.

Start readingOpen the whiteboard

19 chapters · about 3.4 hours · 6 interactives · no background needed

The library behind the book

agl

One loop. One graph. Everything measured.

agl is a small Python framework for AI agents: the OpenAI SDK against any model API, a loop you can read on one page, a graph engine that runs in waves, a memory plugin, hooks for everything else, and an exam you write for your own agent. About 1,200 lines. This book explains every one of them and shows how to bend them to your own problem.

Pick a problem shape and see the graph that fits it, in the six-line text form the library reads. Every pattern in the picker is built in Part III and applied in Part V.

How to read this book

  1. In order. Loops before graphs. Each chapter uses only what the earlier ones taught.
  2. With the code open. When a chapter names a file, open it: agl/loop.py is one page.
  3. With your hands. Step the loop, type a graph, pick a pattern before you read on.
  4. With your own problem in mind. Every example is a template. Part V shows five problems mapped to graphs; the sixth is yours.

Part I · Foundations

What an agent is, which problems suit a loop, and the anatomy of one.

Part II · Building loops

Your first loop, tools, evaluators, models and cost, and the problems every loop hits.

Part III · Building graphs

Why graphs, how the engine runs them, how to draw and design one, and the problems graphs hit.

Part IV · Around the loop

Plugins and tracing, memory, and the exam that keeps your agent honest.

Part V · Real world

A full case study, five problems mapped to five graphs, and shipping.

Appendix

Every term in the book, explained by analogy.