Your Sunday, upgraded. Free live AI class · 5 PM ISTReserve your seat
AGENTS & AUTOMATION

Use a State Machine for Long AI Workflows

Explicit states make it easier to resume a workflow, explain its progress and prevent actions from happening in the wrong order.

On this page

The core idea

A workflow that waits for approval, calls external services and retries failures needs durable progress. A state machine records the allowed states and transitions. This does not require a large orchestration platform for every project; even a small table of states and guarded transitions can make the process easier to operate.

A practical approach

Step 1

Name states around business meaning, such as draft, awaiting_review, approved, sending and completed. Define terminal failure and cancellation states too.

Step 2

For each transition, list the actor, required evidence and side effects. Prevent transitions that skip required approval or validation.

Step 3

Persist enough state to resume after a restart. Use version checks or another concurrency control so two workers cannot advance the same item inconsistently.

Worked example

A content workflow moves from draft to reviewed to scheduled to published. A model can suggest edits while the item is a draft, but it cannot treat a generated ‘looks good’ sentence as the reviewed state. A recorded reviewer decision is the transition evidence.

A mistake to avoid

Status labels without transition rules are only decoration. Another common error is marking work completed before the external service confirms success. Keep ‘submitted’ distinct from ‘completed’ when the service processes asynchronously.

Try it yourself

Draw the states for one workflow and write a transition table. Include a service timeout, a rejected review and a restart halfway through execution. Check that each case has a valid route forward.

Your implementation checklist

  • States describe business progress.
  • Transitions require explicit evidence.
  • Submitted and completed are distinguished.
  • Restarts do not repeat committed side effects.

Share or cite this guide

Innovate with Ajay Editorial (2026-10-04). Use a State Machine for Long AI Workflows. https://innovatewithajay.com/blogs/use-a-state-machine-for-long-workflows

Editorial approach, sources and corrections

YOUR NEXT CHAPTER

You have the curiosity.
Let’s turn it into capability.

Start with a practical workshop or bring a specific question to Ajay.

Chat with Ajay