Module 1 of 11 · Expert · 9 min read
Thinking in loops and graphs
The five shapes of AI workflow, the vocabulary of nodes, edges and state, and how to choose between them.
- 1Workflows come in five shapes: single call, chain, loop, tree and graph.
- 2Nodes do work, edges decide what runs next, and state carries information between them.
- 3Use the simplest shape that passes your tests; each step up adds cost and failure modes.
- 4Every loop needs a stopping condition; every branch needs a way to merge or choose.
01Five shapes
Think of these as increasing levels of control flow. An agent is usually a loop at its core, often embedded in a larger graph.
- Single call: one prompt, one answer. Most tasks.
- Chain: fixed steps in a line (extract, draft, edit). Covered in Advanced Prompting.
- Loop: repeat a step until a condition is met (revise until the rubric passes, fix until the tests pass).
- Tree: branch into several options, evaluate them, and pursue the best (Tree of Thoughts).
- Graph: branches that can merge, loops, conditional routes and shared state (Graph of Thoughts, agent workflow graphs).
02The vocabulary
These terms are used across frameworks, research papers and visual workflow tools, so learning them once pays off everywhere.
- Node: a unit of work, such as an LLM call, a tool call, a piece of code or a human review.
- Edge: a connection saying what runs next. Conditional edges choose a route based on a result.
- State: the shared record that nodes read and update, such as the task, drafts, scores, sources and iteration count.
- Router: a node whose job is to decide which edge to take.
- Stop condition: the rule that ends a loop or the whole run.
- Checkpoint: a saved copy of state, so a run can resume or be inspected.
03Draw it before you build it
Sketch the workflow as boxes and arrows before writing prompts. If you can't draw it, the model can't follow it. A text sketch is enough.
04Choosing a shape
Complexity has costs: more calls, more latency, more places for errors and drift. Add structure only when it measurably helps.
- Is one well-structured prompt good enough on your test set? Stop there.
- Does quality improve when the output is critiqued and revised? Add a loop.
- Are there several plausible approaches, and is choosing badly costly? Branch into a tree.
- Do independent sub-tasks need to run separately and then combine? Use a graph with parallel branches and a merge.
- Does the task need actions in the world, like searching, coding or browsing? Use an agent loop with tools.
05Two rules that prevent most disasters
Every loop needs an exit: a success condition, a maximum number of iterations and a budget. Every branch needs a merge or a choice: decide in advance how parallel results will be combined or how the winner will be picked. The Loop control module covers both in detail.
Finished reading?
Mark it complete to track your progress, then test yourself with the Loops, Graphs & Agents quiz.