ModelRefs / State Machine (Agents) — AI Glossary

State Machine (Agents) — AI Glossary

An agent control architecture defining discrete states and transitions, enabling structured, predictable agent behavior.

Overview

LangGraph implements agents as state machines: graph nodes process state, edges route based on conditions, and the state object carries context between steps. State machines prevent unstructured 'do anything' agent loops, support human-in-the-loop interrupts at defined states, and enable checkpoint/resume for long-running workflows.

Reference details

Topicagents
Also known asfinite state machine, agent graph
Last reviewed2026-06-24

How it works

  1. States are declared explicitly, each a named step with a defined purpose, and the set of states is finite and enumerable — which is the property that makes the agent's behaviour reviewable before it runs.
  2. A shared state object carries context between steps. Each node reads it and returns an update rather than mutating global memory, so what passed from one step to the next is inspectable at every hop.
  3. Edges define legal transitions. A conditional edge routes on the state's contents, so branching is a declared function of data rather than a model's free choice about what to do next.
  4. Cycles are allowed but bounded. A retry or refine loop is an edge back to an earlier state with a counter in the state object, which is how the loop terminates at all.
  5. Checkpointing persists the state object at each transition, which gives three things a free-form loop cannot: resume after a crash, time-travel to inspect an earlier step, and a human-in-the-loop interrupt at a declared state.
  6. Termination is a declared state, not an emergent outcome. This is the single largest difference from an open agent loop, where the stopping condition is the model's judgement.

Example: Why a declared cycle bound is not a detail

An open agent loop with a tool call per step and no bound averages, say, 8 steps on success but occasionally fails to converge. If 2% of runs loop until a 50-step safety cap, the mean step count is 0.98 x 8 + 0.02 x 50 = 7.84 + 1 = 8.84 — about 10% above the 8 that the happy path suggests. The cost distribution is worse than the mean implies: those 2% of runs each consume 50 / 8 = 6.25x the tokens of a normal run, so they account for 1 / 8.84 ≈ 11% of total spend while being 2% of traffic. Declaring the refine cycle with a bound of 3 caps the worst case at a known number of steps instead of a safety net, and makes the 2% visible as an explicit failure state that can be routed to a human rather than as a cost anomaly discovered in a billing report.

Commonly confused with

A state machine is not a DAG, and the difference is cycles. A DAG expresses a pipeline where each step runs once and the shape is fixed before execution; a state machine permits returning to a previous state, which is what retry, refine and clarify loops require. The other confusion is with an agent loop: an agent loop has one implicit state and lets the model choose the next action every turn, while a state machine constrains which transitions exist. The trade is real — a state machine cannot discover a path its author did not declare, which is exactly why it is predictable.

When to use it

Reach for it when:

  • Workflows with known stages and branch conditions, where the path should be a design decision rather than a model decision.
  • Human-in-the-loop requirements, since an interrupt needs a declared state to pause at.
  • Long-running or resumable jobs, where checkpointed state is what survives a crash.
  • Anything that must be audited, because a transition log reconstructs exactly what happened and why.

Reach for something else when:

  • Genuinely open-ended exploration, where the useful path is not known in advance and declaring states forecloses it.
  • Single-step tasks, where a graph is ceremony around one model call.
  • Rapid prototyping of an unclear problem: the state graph will be rewritten more often than the prompt, and each rewrite is more work.
  • When the branch conditions cannot be expressed as functions of state — if routing genuinely requires open judgement, that belongs in a node, not an edge.

Continue your research

Use these connected ModelRefs sections to compare alternatives, inspect implementation paths, and review the evidence and governance boundaries relevant to State Machine (Agents) — AI Glossary.

Frequently asked questions

What is State Machine (Agents)?

An agent control architecture defining discrete states and transitions, enabling structured, predictable agent behavior.

Is State Machine (Agents) the same as finite state machine?

Yes — finite state machine, agent graph are common aliases for State Machine (Agents).

What concepts are related to State Machine (Agents)?

Closely related concepts include dag, agent, parallel execution.