Explicit state transitions for an agent execution graph

← Back to Blog & Articles

An agent run needs an explicit control model.

A prompt may suggest a sequence of actions, but the runtime must decide whether a transition is legal, what state it requires, and what evidence records it. State machines make these rules inspectable. Execution graphs extend the idea by allowing branches, joins, retries, waits, and human approvals while retaining a deterministic record of what happened.

The reference graph uses named states and an allowlist of directed transitions. A transition is rejected if its source does not match the run's current state, if it is not in the graph, or if it attempts to leave a terminal state. This simple guard prevents a model, a stale worker, or a bug from jumping directly from observation to completion or from re-entering an effect phase after cancellation.

The graph is a policy artifact. It records where model proposals are permitted, where policy must decide, where durable events are appended, and where external effects can occur. A plan can choose among authorized branches, but cannot add an edge. High-risk edges can require an approval event; cancellation and budget exhaustion have explicit transitions rather than being exceptional control flow.

Every transition has inputs, outputs, preconditions, and a version. The runtime persists the selected edge and evidence identifiers before performing an external effect. Later replay can reconstruct why a state changed, while a visual graph helps reviewers assess reachability: can an untrusted input reach an irreversible effect without policy? Can a denial still lead to execution? Are all failure paths terminal or recoverable?

The laboratory verifies permitted progress from planned to evidence-gathered to approval-pending, rejects illegal skips, and proves terminal states cannot transition again. The graph code is deliberately independent of a provider or framework; adapters can render it or translate it to a workflow system without changing the safety contract.

Continue with the book

Explore the full treatment, worked examples, and exercises in Building Production-Grade AI Agents.


Companion article for Building Production-Grade AI Agents, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top