Building More Reliable AI Agents with State Machines
Agentic problem solving holds immense promise, but current implementations often suffer from brittleness and unpredictable behavior. To address this, I created Statewright — a visual platform that uses state machines to constrain LLMs and improve reliability.
The Problem with Current Approaches
Many agent frameworks rely on brute-forcing solutions with larger models or longer prompts. While these approaches can work, they’re not scalable or sustainable for complex tasks. I observed that agents often fail when:
- They get stuck in infinite loops
- They use the wrong tools at the wrong time
- They attempt actions outside their scope
- They lack clear guidance on what to do next
State Machines as a Solution
Instead of making models bigger, I focused on reducing the problem space. With Statewright, each agent operates within a clearly defined state machine that:
- Limits tool access based on current context
- Enforces sequential steps with clear transitions
- Provides specific instructions for each phase
- Prevents out-of-scope actions through protocol enforcement
This approach yielded surprisingly positive results across multiple model families (qwen-coder, gpt-oss, gemma4) — particularly above the 13B parameter inflection point. Even frontier models like Haiku and Opus showed improvements in reliability with fewer tokens.
How Statewright Works
Statewright consists of:
- Core Engine: A Rust-based system that evaluates state machine definitions (states, transitions, guards)
- Plugin Layer: Integrates with LLM platforms like Claude Code via their APIs
- Visual Editor: Allows users to design and tweak workflows in a graph view
When you activate a Statewright workflow:
- The model only sees relevant tools (instead of dozens)
- It receives clear instructions for the current state
- Transitions occur automatically when conditions are met
- The system prevents actions outside the defined scope
Try It Yourself
Statewright is live with a free tier, accessible through Claude Code:
/plugin marketplace add statewright/statewright
/plugin install statewright
/reload-plugins
start the bugfix workflow or /statewright start bugfix
You’ll need to paste your API key when prompted (you may need to do this twice for Claude).
The visual editor at statewright.ai lets you design custom workflows with clear failure paths and retry mechanisms — essential for agentic tasks that require iteration.