What is state machines in AI Agents? A Guide for developers in insurance

By Cyprian AaronsUpdated 2026-04-21
state-machinesdevelopers-in-insurancestate-machines-insurance

State machines are a way to model an AI agent as a set of defined states and transitions between those states. In an AI agent, state machines control what the agent can do next based on its current state, the input it receives, and the rules you define.

How It Works

Think of a state machine like a claims workflow in an insurance company.

A claim does not just “happen” all at once. It moves through stages:

  • New
  • Intake Complete
  • Needs Review
  • Awaiting Documents
  • Approved
  • Rejected
  • Closed

An AI agent built with a state machine works the same way. It is not free-running and improvising every step. It is always in one state, and only certain transitions are allowed.

For example:

  • If the user uploads a policy document, the agent may move from Waiting for Documents to Document Review
  • If the document is valid, it may move to Ready for Decision
  • If data is missing, it may move back to Waiting for Documents
  • If fraud signals appear, it may move to Escalate to Human Adjuster

This is useful because insurance workflows have rules. You do not want an AI claims assistant jumping from “customer asked a question” straight to “approve payout” without checking coverage, exclusions, deductible, and policy status.

A simple mental model:

StateAllowed inputNext state
Collecting InfoUser submits claim detailsValidating Claim
Validating ClaimCoverage confirmedAssessing Damage
Validating ClaimMissing fieldsCollecting Info
Assessing DamageEstimate within thresholdAuto Decision
Assessing DamageHigh value or risky caseHuman Review

This is different from a chatbot that just answers messages. A state machine gives your agent memory of where it is in the process and guardrails around what comes next.

A good everyday analogy is a traffic light.

  • Green means go
  • Yellow means slow down or prepare
  • Red means stop

You do not decide randomly which color comes next. The system changes based on rules and timing. That is what you want in regulated insurance flows: predictable behavior, clear auditability, and fewer surprises.

Why It Matters

Developers in insurance should care because state machines solve problems that show up immediately in production:

  • They make AI behavior predictable

    • Claims intake, underwriting support, FNOL triage, and policy servicing all need deterministic flow control.
    • A state machine prevents the agent from skipping required steps.
  • They reduce compliance risk

    • You can enforce mandatory checks before decisions are made.
    • That matters when you need audit trails for regulators, internal risk teams, or customer disputes.
  • They improve human handoff

    • Not every case should be automated.
    • A state machine makes escalation explicit instead of burying it inside prompt logic.
  • They make debugging easier

    • When an agent misbehaves, you can inspect the current state and transition history.
    • That is much easier than tracing a long chain of LLM outputs.

For engineering teams, this also makes testing cleaner. You can write tests per state transition instead of trying to validate one giant prompt that behaves differently every time you change wording.

Real Example

Let’s say you are building an AI assistant for motor insurance claims intake.

The user reports an accident through chat or voice. Your agent needs to collect structured information before anything else happens.

A practical flow could look like this:

  1. Start

    • User opens claim conversation.
    • Agent greets them and asks for policy number.
  2. Policy Lookup

    • Agent checks if the policy exists and is active.
    • If invalid, transition to Policy Issue.
  3. Incident Capture

    • Agent collects date, location, vehicle details, third-party involvement, and photos.
    • If any required field is missing, stay in this state until complete.
  4. Coverage Check

    • Agent evaluates whether the incident falls under coverage rules.
    • If there is a possible exclusion or ambiguous wording, move to Human Review.
  5. Damage Assessment

    • Agent estimates severity using uploaded images and repair estimates.
    • Low-value cases can continue to auto-triage.
    • High-value cases go to adjuster review.
  6. Decision

    • If everything checks out and thresholds are met, create the claim record and notify the customer.
    • Otherwise escalate with full context attached.

Here is what that looks like in code:

from enum import Enum

class ClaimState(Enum):
    START = "start"
    POLICY_LOOKUP = "policy_lookup"
    INCIDENT_CAPTURE = "incident_capture"
    COVERAGE_CHECK = "coverage_check"
    DAMAGE_ASSESSMENT = "damage_assessment"
    HUMAN_REVIEW = "human_review"
    DECISION = "decision"

def next_state(current_state, event):
    if current_state == ClaimState.START and event == "policy_submitted":
        return ClaimState.POLICY_LOOKUP

    if current_state == ClaimState.POLICY_LOOKUP:
        return ClaimState.INCIDENT_CAPTURE if event == "policy_valid" else ClaimState.HUMAN_REVIEW

    if current_state == ClaimState.INCIDENT_CAPTURE:
        return ClaimState.COVERAGE_CHECK if event == "all_fields_collected" else ClaimState.INCIDENT_CAPTURE

    if current_state == ClaimState.COVERAGE_CHECK:
        return ClaimState.DAMAGE_ASSESSMENT if event == "coverage_confirmed" else ClaimState.HUMAN_REVIEW

    if current_state == ClaimState.DAMAGE_ASSESSMENT:
        return ClaimState.DECISION if event == "low_risk" else ClaimState.HUMAN_REVIEW

    return current_state

The point is not the syntax. The point is that each step has explicit rules.

In production, your LLM can still do useful work inside each state:

  • extract entities from messages
  • summarize documents
  • classify urgency
  • draft customer responses

But the state machine decides when those tools run and what happens after they run. That separation keeps your agent controllable.

Related Concepts

If you are implementing this in an insurance stack, these topics sit right next to state machines:

  • Finite State Machines (FSMs)

    • The classic version of this pattern with fixed states and transitions.
  • Workflow orchestration

    • Useful when your agent needs retries, timers, approvals, or parallel steps.
  • Conversation memory

    • Stores context across turns so the agent knows what has already happened inside a state.
  • Tool calling / function calling

    • Lets the LLM trigger APIs like policy lookup, claims systems, or document extraction.
  • Human-in-the-loop review

    • Essential for exceptions, edge cases, fraud flags, and regulated decisions that should not be fully automated.

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