@statelyai/agent 2.0.0-alpha.15 → 2.0.0-alpha.16
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/dist/ai-sdk.cjs +1 -1
- package/dist/ai-sdk.d.cts +2 -2
- package/dist/ai-sdk.d.mts +2 -2
- package/dist/ai-sdk.mjs +1 -1
- package/dist/{decision-C0cUKvNt.cjs → decision-Ba8qrT8r.cjs} +42 -28
- package/dist/{decision-D9Zi7Xi5.mjs → decision-Bt2HYYRo.mjs} +31 -23
- package/dist/{event-log-store-D7pWtIhb.mjs → event-log-store-B-1fcfkT.mjs} +149 -141
- package/dist/{event-log-store-BkUNtyOF.d.mts → event-log-store-BrC9Q1xW.d.mts} +14 -12
- package/dist/{event-log-store-CVd2eyRy.d.cts → event-log-store-CQJq8_v4.d.cts} +14 -12
- package/dist/{event-log-store-CNT_7F0V.cjs → event-log-store-yquOV1TX.cjs} +148 -140
- package/dist/index.cjs +498 -520
- package/dist/index.d.cts +109 -104
- package/dist/index.d.mts +109 -104
- package/dist/index.mjs +497 -519
- package/dist/machines.cjs +1 -1
- package/dist/machines.d.cts +1 -1
- package/dist/machines.d.mts +1 -1
- package/dist/machines.mjs +1 -1
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/{run-agent-B_n4Qxye.d.cts → run-agent-BxjGaVpL.d.cts} +49 -109
- package/dist/{run-agent-BWzo4FLv.d.mts → run-agent-COHoCgQd.d.mts} +49 -109
- package/dist/{setup-agent-CpK0ZRWV.cjs → setup-agent-BLU77gqr.cjs} +141 -172
- package/dist/{setup-agent-DeHRW-qX.mjs → setup-agent-SbiiSbAU.mjs} +136 -167
- package/dist/sqlite.cjs +1 -1
- package/dist/sqlite.d.cts +2 -2
- package/dist/sqlite.d.mts +2 -2
- package/dist/sqlite.mjs +1 -1
- package/dist/{text-logic-DZW7XWy9.d.cts → text-logic-BFX5q7fM.d.cts} +23 -2
- package/dist/{text-logic-C7anC7qX.d.mts → text-logic-DQW8_DWW.d.mts} +23 -2
- package/dist/{types-DFD28AWe.d.cts → types-DYpK3QF4.d.mts} +7 -6
- package/dist/{types-CTBhMnFu.d.mts → types-pJ5Hn8fv.d.cts} +7 -6
- package/package.json +28 -28
- package/readme.md +6 -19
- package/schemas/agent-workflow.json +1 -4
|
@@ -184,13 +184,14 @@ type ToolMessage = {
|
|
|
184
184
|
*/
|
|
185
185
|
type AgentMessage = SystemMessage | UserMessage | AssistantMessage | ToolMessage;
|
|
186
186
|
/**
|
|
187
|
-
* A schema value on an {@link AgentToolDescriptor}
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* `
|
|
187
|
+
* A schema value on an {@link AgentToolDescriptor}: deliberately just `object`,
|
|
188
|
+
* because an SDK-native tool's `inputSchema` is the SDK's own union type (a Zod
|
|
189
|
+
* schema, the SDK's `Schema`, a lazy thunk, ...) and must assign structurally
|
|
190
|
+
* with no cast. The contract is runtime, not static: core narrows with
|
|
191
|
+
* `isStandardSchema` and reads {@link StandardSchemaV1} schemas via
|
|
192
|
+
* `getJsonSchema`; anything else passes through to the executor untouched.
|
|
192
193
|
*/
|
|
193
|
-
type AgentToolSchema =
|
|
194
|
+
type AgentToolSchema = object;
|
|
194
195
|
/**
|
|
195
196
|
* A tool exposed to a text request, described for both the model and
|
|
196
197
|
* (optionally) host execution. This is a **minimal structural contract**: any
|
|
@@ -184,13 +184,14 @@ type ToolMessage = {
|
|
|
184
184
|
*/
|
|
185
185
|
type AgentMessage = SystemMessage | UserMessage | AssistantMessage | ToolMessage;
|
|
186
186
|
/**
|
|
187
|
-
* A schema value on an {@link AgentToolDescriptor}
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
191
|
-
* `
|
|
187
|
+
* A schema value on an {@link AgentToolDescriptor}: deliberately just `object`,
|
|
188
|
+
* because an SDK-native tool's `inputSchema` is the SDK's own union type (a Zod
|
|
189
|
+
* schema, the SDK's `Schema`, a lazy thunk, ...) and must assign structurally
|
|
190
|
+
* with no cast. The contract is runtime, not static: core narrows with
|
|
191
|
+
* `isStandardSchema` and reads {@link StandardSchemaV1} schemas via
|
|
192
|
+
* `getJsonSchema`; anything else passes through to the executor untouched.
|
|
192
193
|
*/
|
|
193
|
-
type AgentToolSchema =
|
|
194
|
+
type AgentToolSchema = object;
|
|
194
195
|
/**
|
|
195
196
|
* A tool exposed to a text request, described for both the model and
|
|
196
197
|
* (optionally) host execution. This is a **minimal structural contract**: any
|
package/package.json
CHANGED
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/agent",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.16",
|
|
4
4
|
"description": "Make invalid agent actions impossible. Agent logic as state machines: deterministic, inspectable, resumable, runs anywhere.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agent",
|
|
7
|
+
"ai",
|
|
8
|
+
"state machine",
|
|
9
|
+
"statechart"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/statelyai/agent#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/statelyai/agent/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "David Khourshid <david@stately.ai>",
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/statelyai/agent.git"
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist",
|
|
23
|
+
"schemas",
|
|
24
|
+
"skills"
|
|
25
|
+
],
|
|
5
26
|
"type": "module",
|
|
6
27
|
"main": "dist/index.cjs",
|
|
7
28
|
"module": "dist/index.mjs",
|
|
@@ -59,29 +80,8 @@
|
|
|
59
80
|
},
|
|
60
81
|
"./agent-workflow.json": "./schemas/agent-workflow.json"
|
|
61
82
|
},
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"schemas",
|
|
65
|
-
"skills"
|
|
66
|
-
],
|
|
67
|
-
"keywords": [
|
|
68
|
-
"ai",
|
|
69
|
-
"state machine",
|
|
70
|
-
"agent",
|
|
71
|
-
"statechart"
|
|
72
|
-
],
|
|
73
|
-
"author": "David Khourshid <david@stately.ai>",
|
|
74
|
-
"license": "MIT",
|
|
75
|
-
"repository": {
|
|
76
|
-
"type": "git",
|
|
77
|
-
"url": "git+https://github.com/statelyai/agent.git"
|
|
78
|
-
},
|
|
79
|
-
"homepage": "https://github.com/statelyai/agent#readme",
|
|
80
|
-
"bugs": {
|
|
81
|
-
"url": "https://github.com/statelyai/agent/issues"
|
|
82
|
-
},
|
|
83
|
-
"engines": {
|
|
84
|
-
"node": ">=22.18.0"
|
|
83
|
+
"publishConfig": {
|
|
84
|
+
"access": "public"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@ai-sdk/openai": "^3.0.25",
|
|
@@ -124,9 +124,6 @@
|
|
|
124
124
|
"xstate": "6.0.0-alpha.25",
|
|
125
125
|
"zod": "^4.3.6"
|
|
126
126
|
},
|
|
127
|
-
"publishConfig": {
|
|
128
|
-
"access": "public"
|
|
129
|
-
},
|
|
130
127
|
"peerDependencies": {
|
|
131
128
|
"@opentelemetry/api": "^1",
|
|
132
129
|
"ai": "^6.0.67",
|
|
@@ -140,6 +137,9 @@
|
|
|
140
137
|
"optional": true
|
|
141
138
|
}
|
|
142
139
|
},
|
|
140
|
+
"engines": {
|
|
141
|
+
"node": ">=22.18.0"
|
|
142
|
+
},
|
|
143
143
|
"scripts": {
|
|
144
144
|
"build": "tsdown",
|
|
145
145
|
"demo": "pnpm --filter @statelyai/agent-demo dev",
|
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
"typecheck": "pnpm run typecheck:src && pnpm run typecheck:examples && pnpm run typecheck:example-packages",
|
|
149
149
|
"typecheck:src": "tsc --noEmit",
|
|
150
150
|
"typecheck:examples": "tsc -p examples/tsconfig.json --noEmit",
|
|
151
|
-
"typecheck:example-packages": "tsc -p examples/next-host --noEmit && tsc -p examples/tanstack-start-host --noEmit && tsc -p examples/tanstack-ai-stream --noEmit && tsc -p examples/cloudflare-agent-host --noEmit && tsc -p examples/cloudflare-workers-ai-host --noEmit",
|
|
151
|
+
"typecheck:example-packages": "pnpm run build && tsc -p examples/next-host --noEmit && tsc -p examples/tanstack-start-host --noEmit && tsc -p examples/tanstack-ai-stream --noEmit && tsc -p examples/cloudflare-agent-host --noEmit && tsc -p examples/cloudflare-workers-ai-host --noEmit",
|
|
152
152
|
"test:cloudflare": "pnpm --filter @statelyai/example-cloudflare-agent-host test && pnpm --filter @statelyai/example-cloudflare-workers-ai-host test",
|
|
153
153
|
"lint": "oxlint",
|
|
154
154
|
"format": "oxfmt src examples",
|
package/readme.md
CHANGED
|
@@ -17,7 +17,7 @@ Stately Agent 2 is in alpha. APIs may change before the stable release.
|
|
|
17
17
|
## Three starting points
|
|
18
18
|
|
|
19
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).
|
|
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 loop](docs/from-a-loop.md).
|
|
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
|
|
|
23
23
|
## Install
|
|
@@ -120,8 +120,6 @@ When the machine reaches `refunded`, the result is:
|
|
|
120
120
|
|
|
121
121
|
The model chooses between the events allowed in `deciding`. The `AUTO_REFUND` transition only works when the amount is at most $100. If the model chooses it for a larger amount, the guard rejects the choice and the decision is tried again.
|
|
122
122
|
|
|
123
|
-
`createScriptedExecutors` plays back canned answers through the same executor contract, so the machine above runs end to end before a model is involved. **No API key needed:**
|
|
124
|
-
|
|
125
123
|
```ts
|
|
126
124
|
import { createScriptedExecutors } from "@statelyai/agent";
|
|
127
125
|
|
|
@@ -131,7 +129,7 @@ const result = await runAgent(refundMachine, {
|
|
|
131
129
|
});
|
|
132
130
|
```
|
|
133
131
|
|
|
134
|
-
|
|
132
|
+
Scripted executors run the machine above end to end with no API key; swap in `createAiSdkExecutors({ models })` for a real model. See [Hosts and executors](docs/hosts.md).
|
|
135
133
|
|
|
136
134
|
## Architecture
|
|
137
135
|
|
|
@@ -149,18 +147,7 @@ The machine never talks to a model directly, so swapping `createAiSdkExecutors`
|
|
|
149
147
|
|
|
150
148
|
The example above has one model decision and two final outcomes. Real machines add approval states, retries, parallel work, child agents, and long-running waits without changing how control flow is represented.
|
|
151
149
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
<!-- core concepts derived from setupAgent, built-in agent actors, runAgent, and XState snapshots -->
|
|
155
|
-
|
|
156
|
-
- **Machines own control flow.** States, events, transitions, and guards define what can happen.
|
|
157
|
-
- **Models make bounded decisions.** `agent.decide` asks a model to choose one of the events accepted by the current state.
|
|
158
|
-
- **Requests are typed.** Inputs, outputs, context, and events use Standard Schema. Zod works out of the box.
|
|
159
|
-
- **Your code runs the model.** `runAgent` accepts executor functions. The example uses the Vercel AI SDK adapter, but the machine does not depend on a provider.
|
|
160
|
-
- **Snapshots can be stored.** An agent can stop for human input, save its XState snapshot, and resume later in another process.
|
|
161
|
-
- **Runs export verified replay entries.** Every `runAgent` result carries a JSON-safe `AgentLogEntry[]` with event identity, timestamp, machine version, and state/effect hashes; pass it to `replay` or `verifyReplay` without repeating model or tool calls.
|
|
162
|
-
- **Machines can be checked without model calls.** Lint their structure, simulate scripted decisions, and explore paths without an API key.
|
|
163
|
-
- **Agents are XState machines.** Guards, actors, parallel states, inspection, testing, and visualization work as usual.
|
|
150
|
+
The core concepts (machines owning control flow, bounded model decisions, typed requests, host-run executors, storable snapshots, verified replay entries) are in the [documentation overview](docs/index.md).
|
|
164
151
|
|
|
165
152
|
## Examples
|
|
166
153
|
|
|
@@ -174,7 +161,7 @@ The example above has one model decision and two final outcomes. Real machines a
|
|
|
174
161
|
|
|
175
162
|
See [all examples](examples/README.md).
|
|
176
163
|
|
|
177
|
-
##
|
|
164
|
+
## Related
|
|
178
165
|
|
|
179
166
|
- [Machines](docs/machines.md)
|
|
180
167
|
- [Text requests](docs/text-requests.md)
|
|
@@ -190,5 +177,5 @@ See [all examples](examples/README.md).
|
|
|
190
177
|
- [Observability](docs/observability.md)
|
|
191
178
|
- [Usage and budgets](docs/usage-and-budgets.md)
|
|
192
179
|
- [Agent patterns](docs/patterns.md)
|
|
193
|
-
- [Migrating from a loop](docs/from-a-loop.md)
|
|
194
|
-
- [
|
|
180
|
+
- [Migrating from a hand-rolled loop](docs/from-a-loop.md)
|
|
181
|
+
- [Coming from LangGraph](docs/langgraph-comparison.md)
|
|
@@ -483,10 +483,7 @@
|
|
|
483
483
|
},
|
|
484
484
|
"guard": {
|
|
485
485
|
"description": "Either a whole-string {{ }} expression evaluated as truthy/falsy, or a named guard reference resolved against the `guards` passed to setupAgent.fromConfig(config, { guards }). Object guards ({ type, params }) are rejected by the lowering.",
|
|
486
|
-
"anyOf": [
|
|
487
|
-
{ "$ref": "#/$defs/ExpressionString" },
|
|
488
|
-
{ "$ref": "#/$defs/Identifier" }
|
|
489
|
-
]
|
|
486
|
+
"anyOf": [{ "$ref": "#/$defs/ExpressionString" }, { "$ref": "#/$defs/Identifier" }]
|
|
490
487
|
},
|
|
491
488
|
"assign": {
|
|
492
489
|
"description": "Context assignments applied when this transition is taken.",
|