statelyai/agent

Create state-machine-powered LLM agents using XState

What it solves

It prevents AI agents from taking invalid actions by moving control flow logic out of the LLM and into a deterministic state machine. This ensures that agents remain predictable, inspectable, and resumable, while the LLM is restricted to picking from a set of legal events defined by the machine's current state.

How it works

Stately Agent integrates model requests and decisions into XState. The state machine defines the legal transitions and guards; the LLM proposes an event, and the machine determines if that event is allowed. The system separates the machine logic from the execution environment (the host), meaning the same agent machine can be run locally for testing with scripted executors or in production using providers like the Vercel AI SDK without changing the machine's definition.

Who it’s for

Developers building AI agents who need strict control over the agent's behavior, deterministic workflows, and the ability to easily test, visualize, and persist the state of their agents.

Highlights

  • Deterministic Control Flow: The state machine owns the logic, making invalid actions impossible.
  • Model Agnostic: The machine never talks to the model directly, allowing developers to swap LLM providers or executors easily.
  • Built-in Patterns: Includes runnable examples for common agent architectures like ReAct, reflection, plan-and-execute, and RAG.
  • Native XState Integration: Leverages XState's capabilities for snapshots, versioning, and migration of agent states.

Related

  • Project
  • Project
  • Project
  • Project
  • Project