Why a second part
Part 1 ends with a governed agent in seven files. Every idea that matters is in there: the loop, the tool, the guardrail, the gate, the log.
Part 2 is the same agent, rebuilt as something a team could actually run. Not because Part 1 was wrong — because four things change the moment a script has to survive being used.
The four changes
Section titled “The four changes”Seven scripts become one package. step7.py is a teaching artefact: one
file you read top to bottom. Part 2 is run.py plus a fraud_triage/ package,
because a system with five stages and eight tools does not fit in a file you can
hold in your head.
One loop becomes a pipeline. Part 1 has a single agent that calls tools until it is finished. Part 2 has five named stages — Intake → Enrichment → Risk → Case → Human gate — and only two of them involve a model at all. Naming the stages is what makes the system reviewable: you can point at the one that went wrong.
Judgment leaves the model entirely. Part 1 argued that a hard rule belongs
in code. Part 2 does it: the risk score is computed by explicit weights in
rules.py, and no model touches the number. Run the system ten times and the
scores do not move.
Defensive plumbing appears. Real tool calls arrive malformed, or aimed at the wrong customer. Part 2 has a function whose only job is to throw away the model’s arguments and substitute the right ones. Part 1 never had to pay that tax.
What you should already have
Section titled “What you should already have”Part 2 assumes Part 1 — the loop, structured output, the
difference between an instruction and a guardrail. It also assumes the same
setup: uv, Ollama, qwen2.5:3b. Nothing new to install.
The result you’re building toward
Section titled “The result you’re building toward”ALERT-001 -> ESCALATE (risk 100/100, confidence high)ALERT-002 -> CLEAR (risk 0/100, confidence high)ALERT-003 -> MONITOR (risk 35/100, confidence low)Those three numbers are the same every single run. The wording of the case summaries is different every time, and so is the set of tools the model chooses to call. Holding both of those facts at once is the whole point of Part 2.
How to follow along
Section titled “How to follow along”The code is in the course repo
under part2/, and its git history is the syllabus — each step below is one
commit, and the code runs at every commit:
git clone https://github.com/nhial/building-ai-agentscd building-ai-agentsgit log --oneline -- part2/ # the eight stepsgit switch --detach <sha> # jump to any one of themcd part2 && uv run --with ollama run.pyYou can read the pages without doing that. But being able to run step 4 exactly as it was, then step 5, and diff them, is worth more than any explanation on this site.