What is state machines in AI Agents? A Guide for CTOs in wealth management
State machines are a way to model an AI agent as a set of named states, where each state defines what the agent is allowed to do next. A state machine controls the agent by moving it from one state to another based on events, conditions, or outputs.
In AI agents, this matters because the agent should not act like a free-form chatbot when handling regulated workflows. It should behave like a controlled process with clear steps, guardrails, and exit conditions.
How It Works
Think of a state machine like a wealth management client onboarding checklist at a private bank.
A new client does not jump straight from “interested” to “fully onboarded.” They move through stages:
- •Lead captured
- •KYC documents requested
- •Documents reviewed
- •Risk profile assessed
- •Compliance approval pending
- •Account opened
Each stage is a state. The rules decide when the client can move forward, when they need more information, and when the process must stop.
For an AI agent, the same idea applies. Instead of letting the model improvise across a long conversation, you define states such as:
- •
idle - •
collecting_client_details - •
verifying_identity - •
checking_compliance_rules - •
escalating_to_human - •
completed
The agent only performs actions valid for its current state. If it is in verifying_identity, it should not suddenly draft an investment recommendation. If compliance fails, it moves to escalating_to_human rather than continuing as if nothing happened.
That gives you three things:
- •Predictability
- •Auditability
- •Control
For engineers, the implementation is usually a combination of:
- •A state definition
- •Transition rules
- •Event handlers
- •Persistence so the workflow survives retries and restarts
A simple example looks like this:
stateDiagram-v2
[*] --> idle
idle --> collecting_client_details: user starts onboarding
collecting_client_details --> verifying_identity: required fields complete
verifying_identity --> checking_compliance_rules: identity verified
verifying_identity --> escalating_to_human: verification failed
checking_compliance_rules --> completed: approved
checking_compliance_rules --> escalating_to_human: flagged
This is not just workflow plumbing. In an AI agent, the state machine becomes the control layer that decides when the LLM can reason, when it must ask for data, and when it must stop.
Why It Matters
CTOs in wealth management should care because state machines reduce operational risk without killing automation.
- •
They constrain hallucinations
The model cannot wander outside approved steps. That matters when an agent is collecting suitability data or summarizing portfolio changes.
- •
They improve auditability
Every transition can be logged: who triggered it, what data was present, and why the system moved forward. That helps with compliance reviews and internal controls.
- •
They make human escalation explicit
Wealth workflows often need advisor review or compliance sign-off. State machines make escalation a first-class path instead of an afterthought.
- •
They simplify testing
You can test each state and transition independently. That is much easier than validating a fully open-ended agent conversation.
For product teams, this means cleaner user journeys. For engineering teams, it means fewer edge cases where the agent gets stuck, repeats itself, or takes unsafe actions.
Real Example
Consider an insurance wealth product where a client wants advice on reallocating assets after retirement while also updating beneficiary details.
A naive agent might try to handle everything in one conversation:
- •Ask about goals.
- •Suggest portfolio changes.
- •Collect beneficiary info.
- •Trigger account updates.
- •Maybe ask for compliance confirmation somewhere along the way.
That is risky. The better approach is to break it into states.
Workflow
| State | Purpose | Allowed Actions |
|---|---|---|
intake | Capture request type | Ask clarifying questions |
suitability_check | Gather risk and profile data | Request missing fields |
recommendation_draft | Prepare advisory summary | Generate draft only |
advisor_review | Human validation | Route to advisor |
beneficiary_update | Handle account admin task | Collect required forms |
completion | Close case | Send confirmation |
What happens in practice
A client says: “I want to reduce equity exposure and update my beneficiary.”
The agent enters intake, identifies two separate intents, then branches:
- •
For investment advice:
- •Move to
suitability_check - •Verify risk tolerance and time horizon
- •Generate a draft recommendation
- •Send to advisor review before client delivery
- •Move to
- •
For beneficiary update:
- •Move to
beneficiary_update - •Request legal identity verification and required consent
- •Submit only after checks pass
- •Move to
If any required condition fails, the system transitions to advisor_review or escalation, not back into free conversation mode.
That separation matters in regulated environments. You do not want the same agent that summarizes market commentary also deciding whether enough evidence exists to change account ownership details.
Related Concepts
- •
Finite State Machines (FSMs)
The standard model behind most production workflow agents.
- •
Workflow orchestration
Tools like Temporal or Step Functions often implement stateful business processes around agents.
- •
Guardrails
Policy checks that constrain what the model can say or do inside each state.
- •
Human-in-the-loop design
Patterns for routing uncertain or high-risk steps to advisors or operations staff.
- •
Conversation memory vs process state
Memory stores context; state defines what phase the workflow is in and what action comes next.
Keep learning
- •The complete AI Agents Roadmap — my full 8-step breakdown
- •Free: The AI Agent Starter Kit — PDF checklist + starter code
- •Work with me — I build AI for banks and insurance companies
By Cyprian Aarons, AI Consultant at Topiax.
Want the complete 8-step roadmap?
Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.
Get the Starter Kit