Agents and AutomationLesson 33 of 72

Module 4 · Surviving real data

When the loop should be a graph

In this lesson

  • 9 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 5 of 9 in this chapter

This chapter’s goalDiagnose a failing agent run from its trace and apply the specific fix it needs: a retry policy, a validator, a shorter chain, or no loop at all.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 7Free · no account needed
Lesson steps

Choice is a cost as well as a feature

A free-running loop gives the model a decision at every step. That is exactly right when nobody knows the path in advance, and exactly wrong when everybody does. A refund process has been the same five steps for eleven years. Asking a model to rediscover them forty times a day is paying for creativity in a place where creativity is a defect.

The alternative is a state machine: named states, defined transitions, and a model call only where a genuine judgement is required.

Text
verify_order ──> check_policy ──> decide ──┬──> issue_refund ──> notify
                                            ├──> escalate ─────> notify
                                            └──> reject ───────> notify

verify_order is a database lookup, no model. check_policy reads the policy text against the order and is a model call. decide is a model call returning one of three enum values. issue_refund is code with a limit. notify is a template. One agent turned into three model calls and four functions.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Context Engineering exam.

Stuck on something?Ask Mai, your AI tutor

How to cite: Addaly (2026) ‘When the loop should be a graph’, in Agents and Automation. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/agents-and-automation/state-machines-over-loops (Accessed: 29 November 2026).