# Your AI Agents Need Finite State Machines (FSMs)

> Source: <https://dev.to/remojansen/your-ai-agents-need-finite-state-machines-fsms-2i9j>
> Published: 2026-07-28 23:40:17+00:00

In [my previous article](https://dev.to/remojansen/from-rigidity-to-explicitness-how-ai-changes-the-role-of-constraints-in-software-5cp5), I argued that AI changes the role of constraints in software development.

For years, many developers saw constraints as something to minimize. Dynamic languages gained popularity over static ones. Schema-less databases promised greater flexibility. Convention replaced configuration. Implicit behavior was often preferred over explicit definitions.

The motivation was understandable. Constraints felt like friction. They slowed us down. AI changes that trade-off.

Today, every explicit constraint becomes valuable context that AI can use to better understand our systems.

A database schema is no longer just a validation mechanism. It describes the structure and meaning of the data.

An OpenAPI specification is no longer just a contract between services. It tells an AI how those services are expected to interact.

A type definition is no longer only for the compiler. It helps AI understand the intent behind an API.

Constraints haven't become valuable because they prevent mistakes. They've become valuable because they communicate knowledge. I believe the same principle applies beyond software development. It applies to business workflows.

There is enormous excitement around AI-powered workflow automation. Most current approaches are based on autonomous agents. An agent receives a request, reasons about the situation, selects tools, executes actions, and decides what should happen next.

For simple workflows, this can work remarkably well. For business-critical workflows, however, this architecture introduces unnecessary operational risk.

The AI is not only performing work. It is also responsible for discovering the business process while executing it. That is asking a probabilistic system to infer something that should already be known.

Business workflows contain rules that are independent of AI:

These are not AI problems. They are business rules. And business rules should not live inside prompts.

When AI workflows become more complex, the common solution is to add more agents.

A planner agent coordinates execution.

Specialized agents perform individual tasks.

Validation agents review the results.

Prompts become increasingly sophisticated. Yet the workflow itself often remains implicit. The workflow exists only through prompts, examples and emergent agent behavior.

This makes the process:

Difficult to understand.

Difficult to test.

Difficult to audit.

Almost impossible to verify.

Business processes deserve a better foundation.

Instead of asking AI to infer the workflow, define the workflow explicitly.

One of the simplest and most powerful ways to do this is with a finite state machine.

A finite state machine explicitly models:

For example, a purchase approval process could look like this:

```
Draft
  ↓
Submitted
  ↓
Approved
  ↓
Purchased
```

When the process is in the **Submitted** state, the workflow might expose exactly three valid transitions:

The AI no longer has to invent the workflow. The workflow itself defines what is possible. The AI only has to determine which of the valid actions is the most appropriate. The workflow provides the boundaries. The AI provides the intelligence.

The value of the finite state machine is not simply that it constrains the AI.

It makes the business process explicit.

The AI immediately knows:

Instead of inferring the workflow from prompts, examples, or previous executions, it receives a precise description of the process.

Just as an OpenAPI specification helps AI understand an API, a finite state machine helps AI understand a business process.

In both cases, explicit constraints become high-quality context.

This is where finite state machines become particularly interesting.

Unlike a prompt, an FSM is a formal model.

That means it is not only explicit.

It is verifiable.

Before an AI agent ever executes the workflow, we can analyze the model and answer questions like:

These are properties that can be verified independently of the AI. This is a fundamental difference from prompt-driven workflows. A prompt describes a process. A finite state machine defines and constrains a process. The FSM becomes an executable safety boundary around the AI.

The objective is not to make AI deterministic.

That is impossible.

The objective is to make the environment in which AI operates deterministic.

Without an explicit workflow, the AI constantly asks:

What should happen next?

With an FSM, the conversation changes.

The workflow says:

These are the only valid actions that can happen next.

The AI answers:

Given these valid options, which one is the most appropriate?

This is a subtle but profound architectural shift.

The AI no longer owns the workflow.

It navigates the workflow.

This model becomes even more powerful when exposed through MCP.

Instead of exposing dozens of low-level tools, the workflow exposes its current state and the transitions that are currently available.

An AI agent can discover:

The workflow becomes self-describing. Changing the business process means updating the workflow model. Not rewriting prompts. The AI automatically receives the new constraints as part of its context.

Large language models are probabilistic. Business processes should not be. A finite state machine does not make the AI smarter. It makes the overall system safer.

By limiting the AI to explicitly defined transitions, we drastically reduce the operational risks of AI-driven workflow automation.

Invalid transitions become impossible.

Every state change is verifiable.

Every decision is auditable.

Rollback becomes part of the workflow instead of an afterthought.

Compliance rules become explicit instead of implicit.

Most importantly, the AI no longer decides what is possible. It decides how to navigate a process whose boundaries have already been defined.

This is the same principle I discussed in my previous article.

Explicit schemas help AI understand data.

Explicit contracts help AI understand APIs.

Explicit types help AI understand code.

Explicit workflows help AI understand business processes.

The value does not come from adding more constraints. It comes from making the right constraints explicit.

As AI becomes increasingly responsible for business operations, I believe we will rely less on autonomous agents trying to infer business processes and more on explicit workflow models that define those processes in a way that both humans and AI can understand.

The future of AI workflow automation is not unlimited autonomy. It is controlled autonomy. AI provides intelligence. Explicit, verifiable workflow models provide correctness. The role of AI is not to own the workflow. Its role is to navigate it intelligently.

And that is where constraints stop being friction and start becoming business value.
