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:

#stagewhat it doeswho does it
1collectclassify every row, keep the ones it got wrongcode
2clustergroup those rows so a decision covers many at oncecode
3proposelook at a group and say what should be written downthe model
4validatecheck every proposal against the rules and reject with a reasoncode
5applywrite to a candidate copy of the knowledge basecode
6gaterun the tests, compare the score, keep it or throw it awaycode

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
1One transaction, and you doing it by handfive steps written on paper
2Turning your five steps into five functionsnode classify.mjs
3The one step code cannot do, and where it goes insteadnode check.mjs
4The model fills in the formnode loop.mjs
5Why the checks are the producta batch that gets thrown away
6The same loop with no model in itnode loop.mjs --backend heuristic
7Layer one: the same string means two thingsa fact that carries its conditions
8Layer two: seeing what the model cannota second view of the same rows
9The production loop in this repoa real batch report
~Glossary: every term, in one line and in fullreference, 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