Build an agentic AI system#
A hands-on course. You will build a thing that reads bank transactions, gets a lot of them wrong, and then improves itself overnight without anyone writing code.
It takes about two hours. You need Node 18 or newer. You do not need an API key for chapters 1 to 6: the model's part is canned so the whole loop runs offline, and chapter 4 shows you how to swap a real one in when you want to.
Everything runs from learn/mini/, which is 500 lines of dependency-free JavaScript. The chapters then point at the same idea in the production system in this repo, where each of those 500 lines is a few thousand.
The question you should be asking#
Most of this project has nothing to do with AI. That is not an accident and it is not an apology. It is the actual lesson.
Here is the whole system, six stages:
| # | stage | what it does | who does it |
|---|---|---|---|
| 1 | collect | classify every row, keep the ones it got wrong | code |
| 2 | cluster | group those rows so a decision covers many at once | code |
| 3 | propose | look at a group and say what should be written down | the model |
| 4 | validate | check every proposal against the rules and reject with a reason | code |
| 5 | apply | write to a candidate copy of the knowledge base | code |
| 6 | gate | run the tests, compare the score, keep it or throw it away | code |
Five stages out of six are ordinary programs. The model is a component inside a program, and a small one. Nearly all of the work in building an agentic system goes into stages 1, 2, 4, 5 and 6, because those are what make stage 3 safe to run unattended, and because stage 2 decides what stage 3 is even able to say.
A useful way to hold it: you are not building an AI. You are building an empty form and an inspector, and hiring a model to fill the form in. The form is the interesting part. Chapter 6 fires the model and fills the same form with thirty lines of if-statements, and most of the system does not notice.
If a word is unfamiliar#
The chapters are written tight, so the background lives in the glossary instead: 51 terms, each with one line you can carry in your head and a longer explanation of what it means in this system. You do not need to read it first. In the web version every term is a link the first time it appears in a chapter, and hovering it shows the one-liner.
Nothing here assumes you know this codebase, and the only programming you need is enough to read a function and run a command.
Chapters#
| ends with | ||
|---|---|---|
| 1 | One transaction, and you doing it by hand | five steps written on paper |
| 2 | Turning your five steps into five functions | node classify.mjs |
| 3 | The one step code cannot do, and where it goes instead | node check.mjs |
| 4 | The model fills in the form | node loop.mjs |
| 5 | Why the checks are the product | a batch that gets thrown away |
| 6 | The same loop with no model in it | node loop.mjs --backend heuristic |
| 7 | Layer one: the same string means two things | a fact that carries its conditions |
| 8 | Layer two: seeing what the model cannot | a second view of the same rows |
| 9 | The production loop in this repo | a real batch report |
| ~ | Glossary: every term, in one line and in full | reference, read as needed |
Reset at any time#
The loop edits learn/mini/kb.json and learn/mini/baseline.json for real. To start over:
git checkout learn/mini/kb.json learn/mini/baseline.json