What is state machines in AI Agents? A Guide for engineering managers in retail banking

By Cyprian AaronsUpdated 2026-04-21
state-machinesengineering-managers-in-retail-bankingstate-machines-retail-banking

State machines are a way to model software as a set of defined states and the valid transitions between them. In AI agents, a state machine controls what the agent can do next based on where it is in the workflow.

How It Works

Think of a state machine like a bank branch queue with clear rules.

A customer is either:

  • waiting
  • being served
  • sent to fraud review
  • completed
  • escalated to a human

They do not jump randomly between those states. They move only when a condition is met, like identity verified, document missing, or risk score too high.

That is the core idea in an AI agent. The agent is not “thinking freely” about every next step. It is following a controlled path:

  • State: what the agent is doing right now
  • Event: something that happens, like user input or an API response
  • Transition: moving from one state to another
  • Guard condition: a rule that must be true before the transition happens

For engineering managers in retail banking, this matters because AI agents often sit inside regulated workflows. You do not want an agent deciding on its own to skip KYC checks, send an approval email early, or call a downstream system twice.

A simple example:

StateEventNext State
StartCustomer asks to open accountCollecting details
Collecting detailsID uploadedVerifying identity
Verifying identityVerification passesAccount setup
Verifying identityVerification failsManual review
Manual reviewAgent receives analyst decisionCompleted

This is different from a generic chatbot flow. A chatbot can drift. A state machine keeps the agent inside the approved process.

For banks, that control matters more than fancy conversation quality.

Why It Matters

  • It reduces operational risk

    • The agent cannot execute invalid steps if transitions are explicitly defined.
    • That helps prevent bad actions like duplicate submissions or premature approvals.
  • It improves auditability

    • Every step has a known state and reason for transition.
    • That makes it easier to explain behavior to compliance, internal audit, and ops teams.
  • It simplifies handoffs

    • When the agent hits uncertainty, it can move into a human review state.
    • That creates clean escalation paths instead of broken conversations.
  • It makes testing practical

    • You can test each state and transition independently.
    • Engineering teams can validate edge cases like missing documents, timeout failures, or verification mismatches.

For retail banking leaders, this is not just architecture trivia. It is how you turn an AI assistant into something production-safe enough for customer-facing workflows.

Real Example

Take a credit card dispute assistant in retail banking.

The customer says: “I don’t recognize this transaction.”

Without structure, an LLM might ask follow-up questions, summarize the complaint, or suggest next steps in an inconsistent order. With a state machine, you define the workflow clearly.

States

  • Start
  • AuthenticateCustomer
  • CollectDisputeDetails
  • CheckEligibility
  • SubmitClaim
  • NotifyCustomer
  • EscalateToAgent
  • Done

Flow

  1. Start
    • Customer opens dispute through chat or app.
  2. AuthenticateCustomer
    • The agent requests OTP or security questions.
    • If authentication fails after N attempts, transition to EscalateToAgent.
  3. CollectDisputeDetails
    • The agent gathers merchant name, date, amount, and reason.
  4. CheckEligibility
    • The system checks whether the transaction falls within dispute policy windows.
    • If outside policy, go to NotifyCustomer.
  5. SubmitClaim
    • The claim is created in the case management system.
  6. NotifyCustomer
    • The customer gets reference number and SLA details.
  7. Done

Why this works better

The LLM handles language generation inside each state:

  • asking for missing info
  • summarizing customer responses
  • explaining policy outcomes

The state machine handles control:

  • what comes next
  • when to stop
  • when to escalate
  • which systems can be called

That separation is important in banking because it keeps business logic deterministic while still using AI where it adds value.

A practical implementation pattern looks like this:

class DisputeStateMachine:
    def __init__(self):
        self.state = "Start"

    def handle_event(self, event):
        if self.state == "Start" and event == "customer_intent_detected":
            self.state = "AuthenticateCustomer"

        elif self.state == "AuthenticateCustomer" and event == "auth_passed":
            self.state = "CollectDisputeDetails"

        elif self.state == "AuthenticateCustomer" and event == "auth_failed":
            self.state = "EscalateToAgent"

        elif self.state == "CollectDisputeDetails" and event == "details_complete":
            self.state = "CheckEligibility"

        elif self.state == "CheckEligibility" and event == "eligible":
            self.state = "SubmitClaim"

        elif self.state == "CheckEligibility" and event == "ineligible":
            self.state = "NotifyCustomer"

        elif self.state in ["SubmitClaim", "NotifyCustomer", "EscalateToAgent"]:
            self.state = "Done"

This is intentionally boring code. That is good.

Boring code is easier to secure, test, monitor, and explain when compliance asks why the assistant took a certain path.

Related Concepts

  • Finite State Machines (FSMs)

    • The classic version of state machines with explicit states and transitions.
  • Workflow orchestration

    • Used when you need multi-step business processes with retries, timeouts, and external system calls.
  • LLM tool calling

    • Lets the model invoke APIs or functions while the state machine decides whether that action is allowed.
  • Conversation memory

    • Stores context across turns; useful inside states but should not replace control flow.
  • Human-in-the-loop escalation

    • A pattern for handing off uncertain or high-risk cases to operations or support staff.

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