What is state machines in AI Agents? A Guide for developers in banking
State machines are a way to model an AI agent as a set of named states, with explicit rules for how it moves from one state to another. In banking, a state machine keeps an agent predictable by controlling what it can do next based on the current context, events, and policy checks.
How It Works
Think of a state machine like a bank branch workflow.
A customer comes in to open an account. They do not jump straight from “walked in” to “account approved.” They move through clear steps:
- •
Start - •
Identity Verification - •
KYC Review - •
Risk Check - •
Approval - •
Rejected
Each step is a state. Each action or event triggers a transition. If KYC passes, the process moves forward. If documents are missing, it moves to Waiting for Documents. If sanctions screening fails, it moves to Escalation.
For AI agents, the same pattern applies.
Instead of letting the model decide everything in one shot, you define:
- •States: what the agent is currently doing
- •Events: what happened externally or internally
- •Transitions: what state should come next
- •Guards: conditions that must be true before moving
- •Actions: work executed when entering or leaving a state
A simple banking support agent might look like this:
| State | Trigger | Next State |
|---|---|---|
Idle | Customer asks about card dispute | Collecting Details |
Collecting Details | Required fields complete | Validating Claim |
Validating Claim | Fraud rules pass | Submitting Case |
Submitting Case | Case created in core system | Done |
Validating Claim | Risk rule fails | Escalation |
This is different from a free-form chatbot. The agent is not improvising its workflow every turn. It is following a controlled path.
That matters in banking because you usually need:
- •auditability
- •deterministic behavior
- •policy enforcement
- •safe fallbacks when systems fail
A useful mental model is an ATM flow.
You insert your card, enter PIN, choose transaction, confirm amount, and receive cash or receipt. The machine does not ask random follow-up questions midway through withdrawal. It only accepts certain inputs at each step, and only certain transitions are valid.
AI agents need that same discipline when they touch regulated workflows.
Why It Matters
Banks should care about state machines because they reduce ambiguity in systems that cannot afford it.
- •
They make agent behavior auditable
You can trace exactly why the agent moved from one step to another. That is useful for compliance reviews, incident analysis, and model governance.
- •
They constrain LLM unpredictability
The model can generate language, but the workflow stays controlled. This lowers the risk of skipped checks, duplicate actions, or policy violations.
- •
They handle exceptions cleanly
Banking processes are full of edge cases: missing docs, failed verification, timeout on core banking APIs, manual review triggers. State machines give each exception a defined path.
- •
They improve testability
You can unit test transitions like normal code. Given state X and event Y, assert that the next state is Z. That is much easier than testing a fully open-ended agent loop.
Real Example
Let’s say you are building an AI agent for insurance claims intake inside a bank-owned insurance product.
The customer uploads photos of damage after a car accident and asks whether the claim can be filed immediately.
A good state machine for this agent might be:
- •
Start- •User opens claim request.
- •
CollectPolicyInfo- •Agent asks for policy number and claimant identity.
- •
VerifyCoverage- •System checks whether the policy is active and covers the incident date.
- •
CollectEvidence- •Agent requests photos, police report number, and incident description.
- •
FraudScreening- •Rules engine checks for duplicate claims, unusual timing, or suspicious patterns.
- •
Decision- •If all checks pass: submit claim.
- •If evidence is incomplete: request more documents.
- •If fraud risk is high: route to manual review.
- •
SubmittedorEscalated
Here’s what makes this production-safe:
from enum import Enum
class ClaimState(Enum):
START = "start"
COLLECT_POLICY_INFO = "collect_policy_info"
VERIFY_COVERAGE = "verify_coverage"
COLLECT_EVIDENCE = "collect_evidence"
FRAUD_SCREENING = "fraud_screening"
DECISION = "decision"
SUBMITTED = "submitted"
ESCALATED = "escalated"
def transition(state, event):
if state == ClaimState.START and event == "user_started":
return ClaimState.COLLECT_POLICY_INFO
if state == ClaimState.COLLECT_POLICY_INFO and event == "policy_verified":
return ClaimState.VERIFY_COVERAGE
if state == ClaimState.VERIFY_COVERAGE and event == "coverage_valid":
return ClaimState.COLLECT_EVIDENCE
if state == ClaimState.COLLECT_EVIDENCE and event == "evidence_complete":
return ClaimState.FRAUD_SCREENING
if state == ClaimState.FRAUD_SCREENING and event == "fraud_clear":
return ClaimState.DECISION
if state == ClaimState.DECISION and event == "submit_ok":
return ClaimState.SUBMITTED
if event == "manual_review_required":
return ClaimState.ESCALATED
return state
The value here is not the code itself. It is the separation of concerns:
- •the LLM handles conversation and extraction
- •the rules engine handles policy checks
- •the state machine handles workflow control
That separation prevents your agent from acting like an overeager intern with API access.
Related Concepts
If you are implementing this in banking systems, these topics sit right next to state machines:
- •
Finite State Machines (FSMs)
The classic formal version of this idea. Good for simple workflows with clear transitions. - •
Workflow Engines
Tools like Temporal or Camunda handle long-running business processes with retries and durable execution. - •
Orchestration vs Choreography
Useful when deciding whether one central controller manages transitions or multiple services react independently. - •
Guard Conditions
Boolean checks that determine whether a transition is allowed. Common in compliance-heavy flows. - •
Agent Memory / Conversation State
The data an AI agent carries between turns. This is separate from workflow state but often stored together in practice.
If you are building agents for banking or insurance, start with explicit states before you let the model improvise. In regulated systems, clarity beats cleverness every time.
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