← Back to Leaderboard
Astatelyai

statelyai/agent

An XState-based TypeScript SDK for constraining and replaying LLM workflows

Engineering Health (Methodology)
A · 78/100
Maintenance Activity
● Updated today
Latest Release
v1.1.6
Commercial License Check
MIT · Commercial Friendly

Automated SPDX check for reference only — not legal advice. Disclaimer

Maintenance35/35
Fork Adoption12/25
Release Cadence11/20
License Clarity20/20
API
Total Stars
★ 511
24h Growth
+0
7d Growth
+3
Forks
30

GitHub Star History

Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.

statelyai/agent Star History (2024-01-02 - 2026-12-04) ALL-TIME STAR HISTORY (2024-01 – 2026-12) +510 in 1067d · avg +0/day 539 270 0 2024-01-02: ★ 12024-03-09: ★ 392024-05-18: ★ 742024-07-27: ★ 1192024-10-05: ★ 1532024-12-14: ★ 1882025-02-22: ★ 2352025-05-03: ★ 2732025-07-12: ★ 2932025-09-20: ★ 3072025-11-29: ★ 3202026-02-07: ★ 3292026-04-18: ★ 3462026-06-27: ★ 3592026-09-05: ★ 4552026-12-04: ★ 511 ★ 511 2024-01 2025-06 2026-12

Evidence-Backed Technical Brief

AI Deep Review

Architecture & Core Mechanics

Stately Agent is a TypeScript SDK built on XState. setupAgent defines the machine and schemas for input, context, output, and events. During a run, runAgent routes typed requests to host executors such as generateText, streamText, and decide, then feeds the result back as an event or output. For a decision, the model proposes an event from the supplied set; the machine owns guards and transitions. Given the same inputs and recorded results, the control flow can be replayed without assuming the model itself is deterministic.

The executor boundary keeps provider calls out of the statechart. The host chooses models, supplies credentials, runs effects, and stores native XState snapshots. It can use the Vercel AI SDK, raw OpenAI SDK, or TanStack AI adapter, or supply plain functions for a custom integration or a model-free test. Approval states, retries, parallel work, and child agents remain explicit parts of the machine.

Key Capabilities & Differentiators

canReach checks whether a modeled violation state is reachable without calling a model. In the refund example, the model may propose AUTO_REFUND, but the guard permits the transition only at $100 or less. A result of reachable: false is evidence of non-reachability within the modeled scope only when exploration also reports complete: true. For runtime debugging, replay reconstructs a run from its event log without issuing fresh model calls; resuming live work instead uses a stored snapshot and an incoming event.

The brownfield tools address different checks: checkConformance checks a recorded run against a model of existing code, checkParity compares the machine's behavior against recorded effects from the old implementation, and compareRuns classifies outcome differences as same, intended, or regression. wrapWorkflow can capture an inspection and trace baseline before a rewrite, but wrapping an opaque async function does not make its internal rules verifiable. Those rules need to be modeled before reachability checks can say anything about them.

Trade-offs & Limitations

Compared with a hand-written loop around an AI SDK, Stately Agent makes branching and business rules explicit and gives teams tools to verify and replay that control flow. The cost is designing states, event schemas, and guards instead of adding another conditional. For teams already using a graph framework such as LangGraph, the deciding factor is whether XState's reachability checks, recorded-run comparisons, and snapshot restoration solve a concrete problem worth migrating for. A simple prompt-to-response endpoint is unlikely to justify the extra structure.

The guarantee stops at the modeled boundary. A legal event can still be the wrong decision, and a statechart cannot verify a constraint that an executor enforces privately. The host must also provide durable storage, decide how to handle retries, and make external effects safe to repeat; restoring a snapshot is not an exactly-once guarantee. MIT allows commercial embedding, but it does not govern provider terms or the hosted inspector relay.

Hardware & Deployment Guide

Embed @statelyai/agent in a Node.js 22+ application. For TypeScript authoring, use TypeScript 5.4+ and a Standard Schema implementation such as Zod 4, Zod 3.24+, Valibot, or ArkType. The package is ESM-first and also publishes CommonJS builds. Match XState to the exact peer required by the chosen package version: 2.0.0-alpha.41 pairs with 6.0.0-beta.2, while the supplied source checkout requires 6.0.0-beta.4. Core verification and stubbed runs work offline; live provider calls need network access and credentials. Deploy it as an application dependency, not as a turnkey API service.

Validate optional adapter versions separately: the AI SDK adapter needs ai 7.0.128+, raw OpenAI needs openai 5+, and TanStack AI needs @tanstack/ai 1.7+. A mismatched optional SDK can install successfully and fail at import or invocation. The 2.0 line is still alpha: alpha.41 added checkConformance, and alpha.42 changed the AI SDK adapter to default to maxRetries: 0 so run usage can count each provider request. Pin versions and retest retry behavior and persisted snapshots when upgrading.

Decision boundary: agent.decide receives allowedEvents; XState guards still decide whether a proposed transition can fire.
Invariant checks: canReach can test whether a sentinel state is reachable without a model API key; check complete before treating non-reachability as proof.
Recovery and debugging: XState snapshots support pause and resume; replay reconstructs state from recorded events without another model call.
Incremental migration: wrapWorkflow captures a baseline, while checkParity compares behavior as phases move into the machine.
Provider boundary: Optional Vercel AI SDK, raw OpenAI SDK, and TanStack AI adapters use the same host-executor interface as custom functions.
Live inspection: The runAgent inspect option connects to the Stately inspector via @statelyai/sdk and a hosted relay.
Best For

TypeScript teams building approval-gated support or operations workflows that need explicit business rules, resumable pauses, and auditable replay, or migrating an existing agent in phases with parity checks.

Skip If

A single model call or a small tool loop is enough, you need a bundled service with managed persistence, or you cannot pin an alpha SDK to its exact XState beta peer.

Reviewed on 2026-12-03 · Grounded in GitHub README, root file tree & releasesMethodology

Quick Start & Installation

API
pnpm add @statelyai/agent@2.0.0-alpha.41 xstate@6.0.0-beta.2 zod

Comparison vs. Top Agents & Frameworks Alternatives

Full comparison →
RepositoryStars7d TrendStackLicenseCore Positioning
agent ★511+3TypeScriptMITAn XState-based TypeScript SDK for constraining and replaying LLM workflows
ruflo82.8k+342TypeScriptMITA TypeScript orchestration layer for coding agents, with shared memory and MCP
browser-use122.7k+477PythonMITPython REPL and CDP for adaptive browser automation
langgraph45.8k+293PythonMITPython graph orchestration for stateful, resumable agents and workflows

AI Context Briefing (for Claude / Cursor / Windsurf)

Standardized architecture summary & quickstart commands ready to paste into coding agents.

Raw .md ↗
curl -sL https://repoforai.com/repo/statelyai/agent.md

Embed Star History Chart & Badges in README.md

Full-history Star History SVGs and velocity cards on GitHub Camo: drop-in replacement for OSSInsight and Star History widgets.

statelyai/agent Star History on RepoForAI

Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).

Frequently Asked Questions about agent

How do I integrate it without handing control flow to the model?

Define states, guards, and typed events with setupAgent, then pass the machine and executor functions to runAgent. The model can propose an event from the allowed set, but the machine still evaluates the transition guard. The host owns credentials, model calls, and snapshot storage; it can resume a paused run by passing a snapshot and an event.

Does it need a GPU, and what determines runtime overhead?

The Node.js orchestration layer does not require a GPU when using remote model APIs or stub executors. Size CPU and memory for concurrent runs, actor work, and retained event data. Model cost and latency depend on provider calls and concurrency; if you supply an executor for local inference, size GPU and VRAM separately for that model.

Can I use it commercially and self-host it?

Yes. The MIT license permits commercial use and embedding, subject to retaining the required copyright and license notices. You can run the agent runtime in your own application and store snapshots yourself. Model providers have separate terms and data-handling policies, and the documented Stately inspector integration connects through a hosted relay.

When is it a better fit than an AI SDK loop or an existing graph framework?

Choose Stately Agent when legal transitions, testable guards, and replay are central requirements. Compared with a hand-written AI SDK loop, it adds an explicit control-flow model and tools to check it, at the cost of more upfront modeling. If you are already using a graph-based framework such as LangGraph, evaluate whether those XState-specific verification and replay tools justify rewriting the orchestration.

Upstream README & Documentation

This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.

Maintaining statelyai/agent? Pin to Homepage + competitor /alternatives pages with a custom Cloud/Demo CTA.Feature statelyai/agent on Homepage & Alternatives ($19)
WEEKLY BREAKOUT DIGEST

Top 10 Breakout Open-Source AI Repos, Every Thursday

Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.

Zero spam · 1-click unsubscribe · Privacy Policy

Saved in your browser · Export Markdown RFC tables or jump into /vs compare