WhoBuilt

Human Approval for AI Agents: State Machines

Oct 12, 2026· 11 min· 359 views·Watch on YouTube

Speaker

David Khourshid, founder of Stately.ai and creator of XState, discusses combining state machines and AI agents with Callstack at Studio Time during AgentConf 2026 in Warsaw.

Deterministic workflows, flexible agents

Khourshid describes keeping the overall workflow deterministic while allowing an agent flexibility within each step. That gives teams control over which steps can happen and in what order, while still letting a model handle open-ended tasks.

Approval, safety, and visibility

He uses an email drafter as an example: the agent drafts a message, but the state machine prevents sending it before user approval. He says prompts alone cannot guarantee business rules. Mapping traces to states and transitions can also show where an agent gets stuck or spends unexpected time.

A basic implementation pattern

Khourshid says state machines can be implemented in any language, from a switch statement to a function that returns the next state. The workflow repeatedly reads events, chooses a state, runs its effects, and continues until the process is done. He sees actor models as a way to coordinate agents and state machines as a way to define each agent’s behavior.

Handling unpredictable model output

Because model output may be unexpected, Khourshid recommends using guards such as schema checks to determine whether an output is valid. The workflow can then retry the agent call or move to an error state for mitigation. At Stately.ai, an earlier system generated three candidate state machines, checked them, and looped back when they were invalid.

Choosing the right scale and tools

Khourshid says simple input-output tasks may not need a state machine, while some production machines reach 200 states. He points to LangGraph as a graph library for defining agent logic with state machines. Stately.ai offers a visual editor at states.new.

Takeaways

  • Put business rules such as approval requirements in workflow logic so prompts do not have to enforce them alone.
  • Use states and transitions to trace where an agent gets stuck, repeats work, or spends unexpected time.
  • Validate model output with guards, then define retries or recovery states for invalid results.
  • Use a state machine when a task has meaningful steps or constraints; simple free-text generation may not need one.
  • Treat the state machine as the workflow and let agents handle flexible work within its steps.

Mentioned in this talk

Search inside this talk

What was claimed 11

Related talks