Stately

Stately Agent

Stately Agent is XState plus typed model requests, decisions, and host executors. The state machine remains the single portable agent-logic artifact.

Mental model

  • XState owns states, events, actors, snapshots, persistence semantics, inspection, timers, parallelism, and durable execution.
  • Stately Agent owns model request logic, decision constraints, executor binding, interactions, streaming, eval helpers, and Agent-specific lint.
  • The host framework owns storage, retries, queues, interruption recovery, and provider SDK behavior.

Start here

Core APIs

APIPurpose
runAgentRun a machine to done or idle; the default entry point
setupAgentSchema-first XState setup with Agent request actors
createAgentRuntimeAdvanced, own the loop: bind executors, expose one durable transition loop
runToQuiescenceAdvanced, own the loop: drive a runtime to done, idle, or error
getInteraction / eventFromInteractionRender and validate human interactions
decideNextAsk a model for one event a plain XState machine accepts
describeMachineRender a machine as plain text for a model
wrapWorkflowWrap an existing async workflow, unchanged, as a machine
isAgentIdleDistinguish a human wait from a stuck settled machine
ContextOf / EventOf / other *Of typesExtract setup and machine types

Entry points

EntryPurpose
@statelyai/agentAuthoring, running, human interaction, and the executor contract
@statelyai/agent/testinglintAgentMachine, simulateAgent, canReach, checkParity, trajectories, seams
@statelyai/agent/logThe event log: replay, forkEventLog, getDecisionAttempts, hand-built entries, stores
@statelyai/agent/ai-sdkcreateAiSdkExecutors: the Vercel AI SDK adapter, for language and decision models
@statelyai/agent/openaiExecutors over the raw openai package
@statelyai/agent/tanstack-aicreateTanStackAiExecutors, the TanStack AI adapter
@statelyai/agent/machinesPreset machines: tool loop, sequential, parallel, router, supervisor, handoff
@statelyai/agent/otelOpenTelemetry trace handler
@statelyai/agent/validateJSON workflow config validation and verifyAgentConfig pre-run gates

Core has no runtime dependency on the AI SDK.

On this page