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.
Human Approval for AI Agents: State Machines
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.
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.
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.
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.
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
- built
“one thing we've released is LangGraph”
6:30in3 ingredients for building reliable enterprise agentsYouTube Verified7 sources· Talk, GitHub, Job posting, Web· archived
- featureStately: State machine modeling
“where we do state machine modeling”
YouTube Unverified1 source· Talk
- feature
XState: State machine library
“XState, which is a state machine library”
YouTube Unverified1 source· Talk
- builtDavid Khourshid built
XState
creator“I’m the creator of XState”
YouTube Verified3 sources· Talk
- foundedDavid Khourshid founded Stately
“I’m the founder of Stately.ai”
YouTube Verified2 sources· Talk
- featurestate machine: Deterministic workflows can constrain nondeterministic agent behavior and enforce transitions
“you have determinism in the core and nondeterminism in the edges”
YouTube Unverified1 source· Talk
- featurestate machine: Workflow traces can be mapped to transitions for visualization and debugging
“you can map your traces to each of the transitions in the state machine”
YouTube Unverified1 source· Talk
- featurestate machine: Guards can validate agent output and route errors to retries or mitigation states
“you have guards. You could say it must pass the schema”
YouTube Unverified1 source· Talk
- usesto create, validate, visualize, and edit state machines
“we use AI itself to create a state machine”
YouTube Unverified1 source· Talk
- built
LangGraph built state machinegraph library for creating state machines with agents“LangGraph is essentially a graph library for creating the same thing: state machines with agents”
YouTube Unverified1 source· Talk
- featureStately visual editor: Visual editor for state machines, available at states.new
“if you go to states.new, that's where the visual editor is”
YouTube Unverified1 source· Talk











