The control-flow spectrum

Lesson 1 of 5 in State Machines vs LLM Loops: Who Owns Control Flow?.

Every agent architecture answers one question: when step n finishes, who decides what step n+1 is?

There are two pure answers. In a state machine, code decides — every state is named, every transition is written down, and the system can only ever be in a situation someone enumerated in advance. In a free-running LLM loop, the model decides — each iteration it reads the whole history and picks the next tool call, and the runtime’s only levers are stopping conditions and guardrails.

Neither pure answer is wrong. They are opposite ends of a spectrum of control flow ownership, and almost every real system lives somewhere between them. Learn to place a design on this spectrum and most of its properties — reliability, cost, debuggability, audit-readiness — follow automatically.

Key terms: control flow, state machine, agent loop, orchestration, non-determinism

Who owns the next step?

  1. Free-running LLM loop — the model owns control flow

    The model reads everything so far and decides the next action, every single iteration. Nothing about the run’s shape exists until the run happens. Anthropic describes the Claude Agent SDK’s loop as gather context → take action → verify work → repeat — the runtime provides tools and stopping conditions; the model provides the plan. Maximum adaptability, minimum enumerability: you cannot list in advance the situations the system can reach.

  2. Model-routed graph — code defines the states, the model picks the edges

    You enumerate the nodes — research, draft, review, escalate — and the model chooses which edge to follow, typically by returning a routing decision as a structured output. The model steers, but only among destinations you wrote down. This is the conditional-edge pattern in graph frameworks and the routing move in supervisor–worker designs.

  3. Coded graph, model inside nodes — code picks every transition; the model exercises judgment within a state

    The sequence is fixed by code — validate, then classify, then act, then notify — and the LLM works inside individual states: reading a document, classifying a complaint, drafting a reply. Control flow is fully deterministic; only the content of each step is model-shaped. Most production “agents” doing real work in enterprises are here.

  4. Fully-coded state machine — code owns everything

    Every state, transition, retry, and timeout is explicit. The system is exhaustively testable and boringly predictable — and if a model appears at all, it only fills slots (a summary here, an extraction there) with no vote on what happens next. If your task fits comfortably here, ask the workflow question honestly: do you need an agent at all?

A useful reflex: when someone shows you an agent design, don’t ask “which framework?” first. Ask “point at the line of code — or the model call — that decides what happens next.” If the answer is a switch statement, you’re near the base of the pyramid. If the answer is “the model’s next tokens”, you’re at the apex, and everything in the next lesson about replay and audits gets harder.

Interactive checkpoint quiz (2 questions) — open this page in a browser to take it.