What is state machines in AI Agents? A Guide for CTOs in banking

By Cyprian AaronsUpdated 2026-04-21
state-machinesctos-in-bankingstate-machines-banking

State machines are a way to model an AI agent as a set of defined states, with explicit rules for how it moves from one state to another. In AI agents, a state machine keeps the agent on a controlled path by making it do only the next valid action based on its current state and inputs.

How It Works

Think of a state machine like a bank’s payment workflow.

A payment does not jump randomly from “initiated” to “settled.” It moves through known steps: initiated, authenticated, screened, approved, posted, or rejected. Each step is a state, and each transition has a rule.

An AI agent works the same way when you want it to behave predictably. Instead of letting the model decide everything in one shot, you define:

  • States: what phase the agent is in
  • Events: what happened to trigger movement
  • Transitions: what state is allowed next
  • Actions: what the agent should do in that state

For example:

  • State: Collecting customer details
  • Event: Customer uploads ID
  • Transition: Move to verification
  • Action: Run KYC checks

This matters because LLMs are probabilistic. They are good at language and reasoning, but not naturally reliable at workflow control. A state machine gives you guardrails.

A useful analogy for banking CTOs: think of it like an ATM session.

The ATM does not let you withdraw cash before authenticating. It does not let you deposit after the session times out unless you start again. The machine enforces order. That is exactly what a state machine does for an AI agent handling regulated workflows.

In practice, this means the agent is not “free-form chatting” its way through operations. It is following an approved path. That makes behavior easier to test, audit, and explain to risk teams.

Why It Matters

CTOs in banking should care because state machines solve problems that show up quickly in production AI systems:

  • Control and predictability

    • You can define exactly what the agent is allowed to do next.
    • That reduces hallucinated actions and broken workflows.
  • Auditability

    • Every transition can be logged.
    • That gives compliance teams a clear trail for reviews, disputes, and model governance.
  • Safer automation

    • The agent cannot skip required checks like sanctions screening or human approval.
    • This is important for KYC, fraud review, claims handling, and lending decisions.
  • Easier recovery

    • If a workflow fails midway, the system knows where it stopped.
    • You can resume from the correct state instead of rerunning everything.

Here is the practical difference:

Without State MachineWith State Machine
Agent may choose inconsistent next stepsAgent follows approved transitions
Hard to debug failuresFailures map to specific states
Weak audit trailEvery action is tied to a state change
Risk of skipping controlsMandatory gates are enforced

For banks, this is not just architecture hygiene. It is how you keep AI agents inside operational and regulatory boundaries.

Real Example

Take a retail banking dispute workflow for card fraud.

A customer reports an unauthorized transaction through chat or mobile app. An AI agent can help triage the case, but it should not make uncontrolled decisions. A state machine keeps it disciplined.

A simple flow looks like this:

  1. Intake

    • Agent collects transaction details.
    • If required fields are missing, it stays in intake.
  2. Identity verification

    • Agent asks authentication questions or triggers OTP.
    • If verification fails, it transitions to manual review.
  3. Fraud assessment

    • Agent checks transaction patterns, merchant risk, device signals, and prior disputes.
    • If risk score exceeds threshold, move to escalation.
  4. Customer communication

    • Agent explains next steps and timelines.
    • It only sends approved message templates from this state.
  5. Resolution

    • If policy allows, provisional credit is issued.
    • Otherwise the case goes to an investigator.

A simplified implementation might look like this:

from enum import Enum

class State(Enum):
    INTAKE = "intake"
    VERIFY_IDENTITY = "verify_identity"
    FRAUD_ASSESSMENT = "fraud_assessment"
    CUSTOMER_COMMUNICATION = "customer_communication"
    RESOLUTION = "resolution"
    MANUAL_REVIEW = "manual_review"

def next_state(state, event):
    if state == State.INTAKE and event == "details_complete":
        return State.VERIFY_IDENTITY
    if state == State.VERIFY_IDENTITY and event == "identity_verified":
        return State.FRAUD_ASSESSMENT
    if state == State.FRAUD_ASSESSMENT and event == "low_risk":
        return State.CUSTOMER_COMMUNICATION
    if state == State.FRAUD_ASSESSMENT and event == "high_risk":
        return State.MANUAL_REVIEW
    if state == State.CUSTOMER_COMMUNICATION and event == "customer_notified":
        return State.RESOLUTION
    return state

The value here is not the code itself. It is that every step is explicit.

If your AI agent uses an LLM to draft messages or summarize evidence, the LLM becomes one component inside a controlled workflow rather than the workflow controller itself. That separation is what makes enterprise deployment realistic.

Related Concepts

  • Finite State Machines

    • The classic computer science model behind controlled transitions.
  • Workflow Orchestration

    • Managing multi-step business processes across services and human approvals.
  • Agent Memory

    • How an AI agent stores context across states or sessions.
  • Tool Calling / Function Calling

    • Letting an LLM invoke APIs while staying inside defined boundaries.
  • Human-in-the-Loop Design

    • Routing high-risk cases to analysts instead of fully automating them.

Keep learning

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

Related Guides