@statelyai/agent 2.0.0-alpha.27 → 2.0.0-alpha.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@statelyai/agent",
3
- "version": "2.0.0-alpha.27",
3
+ "version": "2.0.0-alpha.28",
4
4
  "description": "Make invalid agent actions impossible. Agent logic as state machines: deterministic, inspectable, resumable, runs anywhere.",
5
5
  "keywords": [
6
6
  "agent",
package/readme.md CHANGED
@@ -16,7 +16,7 @@ Stately Agent 2 is in alpha. APIs may change before the stable release.
16
16
 
17
17
  ## Three starting points
18
18
 
19
- - **Author a new agent.** Build a machine from states, decisions, and typed requests; run it locally with `runAgent`, test it with no API key, then use it in any framework or runtime with zero machine changes. See the [Quickstart](docs/quickstart.md) and [Use in any stack](docs/any-stack.md).
19
+ - **Author a new agent.** Build a machine from states, decisions, and typed requests; run it locally with `runToQuiescence`, test it with no API key, then use it in any framework or runtime with zero machine changes. See the [Quickstart](docs/quickstart.md) and [Use in any stack](docs/any-stack.md).
20
20
  - **Retrofit an existing agent.** Turn a `while` loop into a machine: your SDK calls, tools, and retry code become the executors; the machine replaces only the control flow. See [Migrating from a hand-rolled loop](docs/from-a-loop.md).
21
21
  - **Copy a known pattern.** ReAct, reflection, plan-and-execute, RAG, supervisor, and more, each a single runnable file you lift in 60 seconds. See [Agent patterns](docs/patterns.md).
22
22
 
@@ -52,12 +52,12 @@ Requirements:
52
52
 
53
53
  ## Quick start
54
54
 
55
- <!-- refund decision example using setupAgent, agent.decide, a machine guard, and the AI SDK runAgent host -->
55
+ <!-- refund decision example using setupAgent, agent.decide, a machine guard, and the AI SDK runToQuiescence host -->
56
56
 
57
57
  This agent reviews refund requests. The model may propose an automatic refund, but the state machine owns the $100 limit.
58
58
 
59
59
  ```ts
60
- import { runAgent, setupAgent } from "@statelyai/agent";
60
+ import { createAgentRuntime, runToQuiescence, setupAgent } from "@statelyai/agent";
61
61
  import { z } from "zod";
62
62
 
63
63
  const agentSetup = setupAgent({
@@ -108,15 +108,19 @@ const refundMachine = agentSetup.createMachine({
108
108
  },
109
109
  });
110
110
 
111
- const result = await runAgent(refundMachine, {
112
- input: {
113
- request: "I was charged twice for the same order.",
114
- amount: 75,
111
+ const result = await runToQuiescence(
112
+ createAgentRuntime(refundMachine, {
113
+ // An executor is a plain function, so this run needs no API key and no
114
+ // provider package.
115
+ executors: { decide: async () => ({ event: { type: "AUTO_REFUND" } }) },
116
+ }),
117
+ {
118
+ input: {
119
+ request: "I was charged twice for the same order.",
120
+ amount: 75,
121
+ },
115
122
  },
116
- // An executor is a plain function, so this run needs no API key and no
117
- // provider package.
118
- executors: { decide: async () => ({ event: { type: "AUTO_REFUND" } }) },
119
- });
123
+ );
120
124
 
121
125
  if (result.status === "done") {
122
126
  console.log(result.output);
@@ -137,10 +141,12 @@ To call a real model, leave the machine unchanged and swap the executors:
137
141
  import { openai } from "@ai-sdk/openai";
138
142
  import { createAiSdkExecutors } from "@statelyai/agent/ai-sdk";
139
143
 
140
- const liveResult = await runAgent(refundMachine, {
141
- input: { request: "I was charged twice for the same order.", amount: 75 },
142
- executors: createAiSdkExecutors({ models: { fast: openai("gpt-5.4-mini") } }),
143
- });
144
+ const liveResult = await runToQuiescence(
145
+ createAgentRuntime(refundMachine, {
146
+ executors: createAiSdkExecutors({ models: { fast: openai("gpt-5.4-mini") } }),
147
+ }),
148
+ { input: { request: "I was charged twice for the same order.", amount: 75 } },
149
+ );
144
150
  ```
145
151
 
146
152
  For a machine with several requests, the executor routes on `request.name`, or `MockLanguageModelV3` from `ai/test` stands in for the provider behind `createAiSdkExecutors`. See [Evals](docs/evals.md#testing-without-a-provider).
@@ -151,7 +157,7 @@ Passing the same `models` map to `setupAgent({ models })` types the machine's mo
151
157
 
152
158
  ```mermaid
153
159
  flowchart LR
154
- M["Agent machine<br/>states · guards · requests"] -->|request| R["runAgent"]
160
+ M["Agent machine<br/>states · guards · requests"] -->|request| R["runToQuiescence"]
155
161
  R -->|executor call| E["Host executors<br/>generateText · streamText · decide"]
156
162
  E -->|API call| L["Model"]
157
163
  L -->|result| E
@@ -144,9 +144,7 @@ function validateGeneratedConfig(candidate: unknown): AgentWorkflowConfig {
144
144
  const result = validateAgentConfig(candidate);
145
145
  if (result.valid) return candidate as AgentWorkflowConfig;
146
146
  throw new Error(
147
- result.errors
148
- .map((error) => `${error.path || "(root)"} ${error.message}`)
149
- .join("\n"),
147
+ result.errors.map((error) => `${error.path || "(root)"} ${error.message}`).join("\n"),
150
148
  );
151
149
  }
152
150
  ```
@@ -243,13 +241,13 @@ Keep the cap at ~3. A config that fails three schema-shaped repairs is usually a
243
241
  Deliver the config JSON plus how to run it:
244
242
 
245
243
  ```ts
246
- import { runAgent } from "@statelyai/agent";
244
+ import { runToQuiescence } from "@statelyai/agent";
247
245
  import { createAiSdkExecutors } from "@statelyai/agent/ai-sdk";
248
246
 
249
- const result = await runAgent(machine, {
250
- input: { ticket: "Export downloads a 0-byte CSV on Safari." },
251
- executors: createAiSdkExecutors({ resolveModel }),
252
- });
247
+ const result = await runToQuiescence(
248
+ createAgentRuntime(machine, { executors: createAiSdkExecutors({ resolveModel }) }),
249
+ { input: { ticket: "Export downloads a 0-byte CSV on Safari." } },
250
+ );
253
251
  ```
254
252
 
255
253
  Say which gates passed, list any warning-severity lint diagnostics, and report the dry-run status. Model refs are strings, so the host supplies `resolveModel`.