@statelyai/agent 2.0.0-alpha.35 → 2.0.0-alpha.36
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/CHANGELOG.md +111 -0
- package/dist/act-B9hLQls6.mjs +19 -0
- package/dist/act-CrX0JwWY.cjs +42 -0
- package/dist/ai-sdk.cjs +63 -7
- package/dist/ai-sdk.d.cts +13 -3
- package/dist/ai-sdk.d.mts +13 -3
- package/dist/ai-sdk.mjs +63 -7
- package/dist/{decision-BEsATcr1.cjs → decision-CMeuNZ1g.cjs} +262 -4
- package/dist/{decision-COkJNjOW.mjs → decision-m5hGmHpF.mjs} +239 -5
- package/dist/decision-object-B5zGSPFp.d.mts +15 -0
- package/dist/decision-object-DBcLWVvv.d.cts +15 -0
- package/dist/{run-agent-s5D32w99.cjs → effects-B23bFZEs.cjs} +948 -102
- package/dist/{run-agent-Ct_GZw_f.mjs → effects-CuOUNYtZ.mjs} +914 -104
- package/dist/{event-log-C7jeH0y8.mjs → event-log-DkVlk3Rh.mjs} +30 -15
- package/dist/{event-log-BWSSLUff.cjs → event-log-Dkc-yIYu.cjs} +41 -14
- package/dist/{event-log-store-BzXehP7R.d.cts → event-log-store-BBS8so8a.d.mts} +2 -2
- package/dist/{event-log-store-W49TCJXi.mjs → event-log-store-Brx9tOHt.mjs} +1 -1
- package/dist/{event-log-store-CleWpsp5.cjs → event-log-store-Cl-YWDnq.cjs} +1 -1
- package/dist/{event-log-store-CWjN6lmM.d.mts → event-log-store-bc4ICGcS.d.cts} +2 -2
- package/dist/index.cjs +660 -286
- package/dist/index.d.cts +168 -9
- package/dist/index.d.mts +168 -9
- package/dist/index.mjs +639 -271
- package/dist/internal-C3Lqu538.d.cts +43 -0
- package/dist/internal-DUcdhk-i.d.mts +43 -0
- package/dist/log.cjs +2 -2
- package/dist/log.d.cts +1 -1
- package/dist/log.d.mts +1 -1
- package/dist/log.mjs +2 -2
- package/dist/machines.cjs +457 -41
- package/dist/machines.d.cts +114 -43
- package/dist/machines.d.mts +114 -43
- package/dist/machines.mjs +457 -42
- package/dist/{model-source-DmhTMK39.cjs → model-source-B4WQ8Idp.cjs} +1 -1
- package/dist/{model-source-CK3F4YuU.mjs → model-source-kjGwqAV8.mjs} +1 -1
- package/dist/openai.cjs +149 -36
- package/dist/openai.d.cts +28 -10
- package/dist/openai.d.mts +28 -10
- package/dist/openai.mjs +149 -36
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/{run-agent-BGdx5913.d.mts → run-agent-BcQ-9NRT.d.cts} +91 -9
- package/dist/{run-agent-B1-Eqviq.d.cts → run-agent-C86drZtN.d.mts} +91 -9
- package/dist/{setup-agent-05uw4dPZ.mjs → setup-agent-BDmNr6PC.mjs} +9 -3
- package/dist/{setup-agent-BtfeFfF6.d.cts → setup-agent-BIKcbVXV.d.mts} +4 -4
- package/dist/{setup-agent-CXEBURdo.cjs → setup-agent-CmEToB8y.cjs} +9 -3
- package/dist/{setup-agent-C6nqzv_X.d.mts → setup-agent-jlo4vtaZ.d.cts} +4 -4
- package/dist/tanstack-ai.cjs +62 -4
- package/dist/tanstack-ai.d.cts +18 -6
- package/dist/tanstack-ai.d.mts +18 -6
- package/dist/tanstack-ai.mjs +62 -4
- package/dist/testing.cjs +399 -20
- package/dist/testing.d.cts +196 -255
- package/dist/testing.d.mts +196 -255
- package/dist/testing.mjs +395 -20
- package/dist/{text-logic-CV_4KGr6.d.cts → text-logic-BqxalgMr.d.mts} +87 -4
- package/dist/{text-logic-Ckh-rJFV.d.mts → text-logic-CSf9bqpP.d.cts} +87 -4
- package/dist/{types-Dp5_Ru4R.d.cts → types-DQUOOaZO.d.cts} +1 -1
- package/dist/{types-Dp5_Ru4R.d.mts → types-DQUOOaZO.d.mts} +1 -1
- package/dist/{usage-BDiJKyv9.d.cts → usage-DoP0Oi84.d.mts} +1 -1
- package/dist/{usage-DOoVUGVq.d.mts → usage-HtnrUsl9.d.cts} +1 -1
- package/dist/utils-7lSa4H-i.d.cts +403 -0
- package/dist/utils-CBbKw2fM.d.mts +403 -0
- package/dist/validate.cjs +44 -12
- package/dist/validate.d.cts +6 -6
- package/dist/validate.d.mts +6 -6
- package/dist/validate.mjs +44 -12
- package/dist/verify-Bink-Drw.cjs +2304 -0
- package/dist/{verify-BQpE8hUz.d.cts → verify-Buh8XSUr.d.mts} +208 -14
- package/dist/{verify-CqeuEmIk.d.mts → verify-CciG8UP-.d.cts} +208 -14
- package/dist/verify-Dpz1u5Pe.mjs +2251 -0
- package/dist/with-model-calls-B_WLmOSl.cjs +248 -0
- package/dist/with-model-calls-BkOwdroS.mjs +213 -0
- package/docs/act.md +102 -0
- package/docs/advanced.md +105 -0
- package/docs/any-stack.md +62 -0
- package/docs/choosing-a-run-mode.md +55 -0
- package/docs/debugging.md +29 -0
- package/docs/decisions.md +473 -0
- package/docs/environment-and-policy.md +188 -0
- package/docs/evals.md +509 -0
- package/docs/event-log.md +311 -0
- package/docs/from-a-loop.md +528 -0
- package/docs/generate-machines.md +110 -0
- package/docs/hosts.md +414 -0
- package/docs/human-in-the-loop.md +177 -0
- package/docs/index.md +48 -0
- package/docs/judgments.md +281 -0
- package/docs/langgraph-comparison.md +198 -0
- package/docs/machines-as-data.md +454 -0
- package/docs/machines-presets.md +198 -0
- package/docs/machines.md +497 -0
- package/docs/messages.md +67 -0
- package/docs/meta.json +52 -0
- package/docs/models-and-providers.md +268 -0
- package/docs/multi-agent.md +68 -0
- package/docs/observability.md +109 -0
- package/docs/patterns.md +31 -0
- package/docs/persistence.md +136 -0
- package/docs/quickstart.md +121 -0
- package/docs/roadmap.md +22 -0
- package/docs/scope.md +75 -0
- package/docs/statechart-policy-examples.md +69 -0
- package/docs/steps.md +54 -0
- package/docs/strangler-fig.md +323 -0
- package/docs/text-requests.md +250 -0
- package/docs/thinking-in-state-machines.md +324 -0
- package/docs/tools.md +249 -0
- package/docs/upgrading.md +37 -0
- package/docs/usage-and-budgets.md +516 -0
- package/docs/validate-and-repair.md +253 -0
- package/docs/verify.md +487 -0
- package/docs/xstate-4-and-5-apps.md +161 -0
- package/llms.txt +53 -0
- package/package.json +10 -3
- package/readme.md +30 -15
- package/skills/add-evals/SKILL.md +3 -1
- package/skills/add-traces/SKILL.md +6 -1
- package/skills/build-machine/SKILL.md +81 -0
- package/skills/generate-machine/SKILL.md +1 -1
- package/skills/graph-engineering/SKILL.md +13 -3
- package/skills/improve-machine/SKILL.md +21 -2
- package/skills/loop-to-machine/SKILL.md +147 -192
- package/skills/loop-to-machine/reference.md +260 -0
- package/dist/utils-BnXdWih3.d.mts +0 -108
- package/dist/utils-ebVpCYoF.d.cts +0 -108
- package/dist/verify-Bpahmr34.mjs +0 -1241
- package/dist/verify-DCLZa9R0.cjs +0 -1288
- package/dist/with-model-calls-BXYdBdcu.cjs +0 -45
- package/dist/with-model-calls-Bv4V4EHC.mjs +0 -34
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,116 @@
|
|
|
1
1
|
# @statelyai/agent
|
|
2
2
|
|
|
3
|
+
## 2.0.0-alpha.36
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#209](https://github.com/statelyai/agent/pull/209) [`1e8e42d`](https://github.com/statelyai/agent/commit/1e8e42db528033e0e37e0f5ecc2d106708ceb9c6) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths`/`canReach`: `children: "coupled"` steps each child machine inside the parent's search, so a witness is a run the machines can make together. A child's events reach the parent in the child's own order, its output follows them, and the parent's `sendTo`/`forwardTo` sends are applied to the child as made (no `childEvents` entry needed). New `hostEvents` option lists the event types the host can send the machine, so child-only status events are not offered as host events.
|
|
8
|
+
|
|
9
|
+
- [#197](https://github.com/statelyai/agent/pull/197) [`21f132e`](https://github.com/statelyai/agent/commit/21f132eee370ba6565f92563fff6a8f457eae72b) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Compatible decisions are answered as one structured-output object by default, decisions can be split into several model calls, and a new `agent.act` builtin sends any number of events in one tool loop.
|
|
10
|
+
|
|
11
|
+
- **Object answers by default (behavior change).** The AI SDK, OpenAI, and TanStack AI `decide` executors now ask for one structured-output object: `{ event }` for an open choice, `{ choice }` for a closed one. Root unions of object payloads become separate event variants; payloads that cannot be represented without unsupported composition default to tool mode. An answer holds exactly one event by construction. Pass `decideMode: 'tool'` (or a function of the request) to any adapter to keep one tool per candidate event; tool mode now turns parallel tool calls off where the provider allows it and rejects an answer with more than one call. Decision models such as Jev are unaffected.
|
|
12
|
+
- **OpenAI `api` (behavior change).** `api` is unset by default: calls with function tools (`generateText` with tools, a tool-mode `decide`) use the Responses API, and every other call, including an object-mode `decide`, uses Chat Completions. `api: 'chat'` now sends everything to Chat Completions, tools and decisions included, with a host-side Chat Completions tool loop. `api: 'responses'` sends everything to the Responses API.
|
|
13
|
+
- **Decision strategies.** `agent.decide` input and `createDecisionLogic` take `strategy` (`'direct'`, `'pick-then-fill'`, `'grouped'`, or `'auto'`, the default), `fillModel`, and `groups`. `'pick-then-fill'` picks the event type as a closed choice, then fills its payload: by a second closed choice when every field is finite, else by a structured `generateText` call on `fillModel`. This lets a decision model pick the type while a language model writes open fields. `'grouped'` picks a group of event types first. `'auto'` uses `'pick-then-fill'` when `fillModel` is set and `'grouped'` above 24 events in two or more groups. Sub-calls count against the model-call budget, are traced, and get callKeys suffixed `.pick`, `.group`, or `.fill`. `verifyAgentConfig` reports a `'pick-then-fill'` decision with open payload fields and no `fillModel`.
|
|
14
|
+
- **`agent.act`.** A new builtin invoke runs one `generateText` tool loop whose tools are the state's accepted (non-human) events plus any plain `tools`. Calls run in call order; each accepted event is sent to the machine and answered with its delta (`{ state?, changed? }`), and calls after the state exits answer `ACT_STATE_EXITED`. `lintAgentMachine` reports `decide-allows-human-event` for it too. An act loop does not resume mid-flight after a crash.
|
|
15
|
+
|
|
16
|
+
- [#208](https://github.com/statelyai/agent/pull/208) [`f8c18db`](https://github.com/statelyai/agent/commit/f8c18dbd4a3f2c93311b5fadb783023ae2e27701) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `wrapWorkflow({ id, effects, run })` wraps an existing async workflow, unchanged, as an agent machine: `running` invokes it, `done` carries its result. Each effect call is an `effect.call` then `effect.done` or `effect.error` event, so it shows in transitions, traces, and the event log. `wrapped.run(input, { effects, recorder, signal, ... })` returns what the workflow returned and rethrows what it threw; `recorder` records a golden run.
|
|
17
|
+
|
|
18
|
+
`checkParity({ scenarios, effects, before, after })` in `@statelyai/agent/testing` records `before` per scenario, replays `after` against the recording with no effect running, and compares them with `compareRecordings`. A throwing `after` is a report row, not a throw.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- [#203](https://github.com/statelyai/agent/pull/203) [`c1ba55e`](https://github.com/statelyai/agent/commit/c1ba55e28514daf49ed24486c0d389706d126827) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `abortWith: { event, timeout? }` on `runAgent`/`createAgentRuntime` routes `signal`'s abort through the machine: the event is sent into the run and the run continues until the machine settles. Falls back to `cause: "aborted"` when the machine does not handle the event or `timeout` elapses.
|
|
23
|
+
|
|
24
|
+
- [#203](https://github.com/statelyai/agent/pull/203) [`c1ba55e`](https://github.com/statelyai/agent/commit/c1ba55e28514daf49ed24486c0d389706d126827) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Add `createApprovalBatchMachine` to `@statelyai/agent/machines`: one spawned child per proposed tool call runs a `policy` (`"allow"` | `"ask"` | `"deny"`), waits for `APPROVE` / `APPROVE_ALWAYS` / `REJECT` (routed by `callId`) when asked, and executes only approved calls through `execute`, either after every approval settles (`executeWhen: "allReady"`, default) or each as approved (`"eachReady"`). `CANCEL_ALL` ends the batch; output is per-call `{ id, status, result?, error?, reason? }` plus the `approveAlways` rules to persist.
|
|
25
|
+
|
|
26
|
+
- [#211](https://github.com/statelyai/agent/pull/211) [`3cb2c9b`](https://github.com/statelyai/agent/commit/3cb2c9b86afad13ba5e9cee6d9a75802e086986d) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Skills and docs from a timed brownfield self-improvement trial: ported runners take a run-options argument passed through to `runAgent` (the strangler-fig example's step 1 runner now does), prompt text moves into a versioned request config at carve time, thread ids for decider-less machines include the request version, and `improve-machine` covers prompt text in code you may not edit and values lost between states that `foldTraces` cannot show.
|
|
27
|
+
|
|
28
|
+
- [#218](https://github.com/statelyai/agent/pull/218) [`09cd9e7`](https://github.com/statelyai/agent/commit/09cd9e737c8dced4f10d439452339cdcfca3e060) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `describeMachine` parses transition functions instead of matching them with regular expressions. Every return path counts: ternaries, `&&` and `||`, early returns, and local constants. A helper's target that the old matcher dropped now shows as `?`. The new `source: true` option prints each transition function under its line. Skills and `llms.txt` say to keep targets inline.
|
|
29
|
+
|
|
30
|
+
- [#203](https://github.com/statelyai/agent/pull/203) [`c1ba55e`](https://github.com/statelyai/agent/commit/c1ba55e28514daf49ed24486c0d389706d126827) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths`/`canReach`: `interleave: "pending"` forks external events while an invoke is outstanding; `errors[src]` arrays fork one failing branch per value; `children: "explore"` explores invoked child machines and forks the parent on their distinct outputs and failures; the report's new `vacuous` lists event types whose payload-reading transitions were only tried as bare `{ type }`.
|
|
31
|
+
|
|
32
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`aee7241`](https://github.com/statelyai/agent/commit/aee7241b66e3ab3ad1011da834948b24482230ce) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths`/`canReach` with `children: "explore"`: an invoke or text request with no `outputs` entry, pending beside an explored child, now ends that branch `needs-output` instead of vanishing from the search, so the report is not complete.
|
|
33
|
+
|
|
34
|
+
- [#207](https://github.com/statelyai/agent/pull/207) [`5e128f9`](https://github.com/statelyai/agent/commit/5e128f98d5ce0f195cfc897c58f4aae0a40b1f91) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths`/`canReach`: new `budget: { nodes?, ms?, childCache? }` bounds the whole call, child searches (`children: "explore"`) included; `budget.nodes` defaults to 250,000. An exhausted budget stops the search cleanly with a `budget-exhausted: nodes` or `budget-exhausted: ms` note; the report's new `partial` and `complete` flags say so, and `canReach` returns `complete: false`; `verifyAgentConfig` fails its explore gate with the note. Explored-child outcomes are kept in a bounded LRU cache, and a search keeps one parent pointer per node instead of a path copy, so long searches retain far less memory.
|
|
35
|
+
|
|
36
|
+
- [#203](https://github.com/statelyai/agent/pull/203) [`c1ba55e`](https://github.com/statelyai/agent/commit/c1ba55e28514daf49ed24486c0d389706d126827) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths`/`canReach` with `children: "explore"` offers an invoked child only the events `childEvents[src]` lists (the ones the parent forwards); a child wait for an unlisted event leaves the search incomplete instead of reporting the child's finals as reachable.
|
|
37
|
+
|
|
38
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`5ef1b1f`](https://github.com/statelyai/agent/commit/5ef1b1f42623ebd03e5a68b3c9b82e9a384ff8e7) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths`/`canReach` with `children: "explore"`: a child's delivered parent events are keyed by its actor session, so a child restarted under the same id can deliver the same event again instead of being reported unreachable.
|
|
39
|
+
|
|
40
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`45bb78c`](https://github.com/statelyai/agent/commit/45bb78cf70112dd12d3e0b967ed3675240e7c7fc) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths`/`canReach` with `children: "explore"`: while an explored child is pending, every pending text request, scripted invoke, and child settlement forks, so a child settling before a sibling invoke with an earlier id is explored instead of missed.
|
|
41
|
+
|
|
42
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`61bdedb`](https://github.com/statelyai/agent/commit/61bdedb2ba811cdf1b5b421429f1c7dbbfc4994e) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths`/`canReach` with `children: "explore"`: a decision pending beside an explored child is no longer a false `needs-output`; its choices branch alongside the other pending settlements.
|
|
43
|
+
|
|
44
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`ace82b0`](https://github.com/statelyai/agent/commit/ace82b0822fb5b4ab25ed4318473bb4af9ca7efd) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths`/`canReach` with `children: "explore"`: every decision pending beside an explored child expands its choices, not only the first.
|
|
45
|
+
|
|
46
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`6e9cba6`](https://github.com/statelyai/agent/commit/6e9cba65cbd06b955fe95efa845e00b9740c174b) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `explorePaths`/`canReach` with `children: "explore"` explore spawned child machines (`enq.spawn(actors.x, { id, input })`) with their spawn input, and fork the parent on each event a child sends it (`sendTo(parent, …)`). Pending explored children settle in any order.
|
|
47
|
+
|
|
48
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`c97915b`](https://github.com/statelyai/agent/commit/c97915b26d4f6c87b479996a7f726ad23c0f8528) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `canReach`/`explorePaths`: a state the machine only passes through (an `always` hop or a `choice` state) now counts as reached. Before, `canReach` on such a state returned `{ reachable: false, complete: true }`, a false proof.
|
|
49
|
+
|
|
50
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`2184f14`](https://github.com/statelyai/agent/commit/2184f14d45dd5430c6454ec2cb2d651cd3addd57) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `runAgent`: an ignored `inbox` event no longer ends the `onIdle` loop; only an ignored opening event or `onIdle` answer does.
|
|
51
|
+
|
|
52
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`b9204a6`](https://github.com/statelyai/agent/commit/b9204a639cf40416f8acfef4d9d6d20347b9e94c) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `runAgent`: whether an ignored event came from the `inbox` is tracked per pass by its source, so an ignored `onIdle` answer that reuses an event object once sent through the inbox ends the loop instead of being retried.
|
|
53
|
+
|
|
54
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`3b0b229`](https://github.com/statelyai/agent/commit/3b0b2290e4510c55ca9ad3743f5418c0abacfe23) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `runAgent`: an `inbox.send` made synchronously inside `onIdle` now resumes the run instead of hanging it.
|
|
55
|
+
|
|
56
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`2324e39`](https://github.com/statelyai/agent/commit/2324e3916fd17b281450f77d97008b66be36ff20) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `runAgent`: an `inbox.send` that lands just after an `onIdle` answer wins the idle race is queued for the next pass instead of being dropped.
|
|
57
|
+
|
|
58
|
+
- [#203](https://github.com/statelyai/agent/pull/203) [`c1ba55e`](https://github.com/statelyai/agent/commit/c1ba55e28514daf49ed24486c0d389706d126827) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Export every type that can appear in the inferred type of a `setupAgent(...).createMachine(...)` machine, `createAgentRuntime` value, `runAgent` result, or preset machine (`WithAgentInputSchema`, `EventUnion`, `AgentEventSchemaInputMap`, `BuiltinAgentActors`, `DecisionModeOption`, and others), so consumers compiled with `declaration: true` or `composite: true` no longer hit TS2742 "cannot be named without a reference to .../dist/types-<hash>.mjs".
|
|
59
|
+
|
|
60
|
+
- [#204](https://github.com/statelyai/agent/pull/204) [`32be90f`](https://github.com/statelyai/agent/commit/32be90f3794f7ababc8745e196201ef81ef8a75e) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Add `proposeApprovalRules` and `proposeCaps` to `@statelyai/agent/testing`: from many runs' traces, propose an `allow`/`deny` rule per approval key (allow only when never rejected and no violation, with `support` as the run count) and a value per cap (`p95` of passing runs plus one, never below `current` while runs hit the cap). Proposals are for a person; nothing promotes them.
|
|
61
|
+
|
|
62
|
+
- [#204](https://github.com/statelyai/agent/pull/204) [`392677b`](https://github.com/statelyai/agent/commit/392677b324bc32b399b9f9402000fd4e9ed08d81) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `createRecorder` records any client: `recorder.fn(name, asyncFn, options?)` and `recorder.client(name, client, { methods })` record each call as a `call` effect (arguments, result or error, stream chunks), and replay answers it by name and order with no network. `redact`, `serialize`, and `revive` control what is recorded and returned; `compareRecordings` reports `call-name`, `call-args`, and `call-result`.
|
|
63
|
+
|
|
64
|
+
- [#215](https://github.com/statelyai/agent/pull/215) [`5cbf89b`](https://github.com/statelyai/agent/commit/5cbf89bab4372a5bae318435dfe4155104e8fecf) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `wrapWorkflow` observes an effect that resolves to a stream: `effect.done` carries the chunks once the stream is read (or the reader stops early), and a mid-stream throw is an `effect.error`.
|
|
65
|
+
`wrapWorkflow` hands the workflow its own deep copy of a plain-data input, so legacy code that mutates its input no longer throws on XState's frozen context.
|
|
66
|
+
`canReach` lists why a search is incomplete in `unexplored` when `complete` is false, such as a src with no `outputs` entry.
|
|
67
|
+
`checkParity` and `compareRecordings` report a run that returned on one side and threw on the other as an `output` divergence, and `checkParity` names the thrown error in its message.
|
|
68
|
+
`describeMachine` prints `→ ?` for a function transition whose target is a variable (including shorthand `{ target }`), and no longer marks a transition that always returns an object literal `(conditional)` because of a conditional in its context patch.
|
|
69
|
+
`wrapWorkflow` keeps a streaming generator's return value flowing to a manual `next()` loop and records it: `effect.done` carries `{ chunks, returned }` when the generator returned a value, and `next()` called on the generator itself is observed too.
|
|
70
|
+
`checkParity` takes `normalizeError(error, scenario)`, which maps each side's thrown error before the two are compared; rows keep the raw errors.
|
|
71
|
+
`describeMachine` leaves a spread of the current context (`{ ...ctx, outcome }`, or `{ context: e }` in minified source) out of the keys a transition sets.
|
|
72
|
+
`explorePaths` `done` terminals carry the machine's `output`.
|
|
73
|
+
|
|
74
|
+
- [#219](https://github.com/statelyai/agent/pull/219) [`be16144`](https://github.com/statelyai/agent/commit/be16144cb52290fcc1b8db5f165d147629773054) Thanks [@davidkpiano](https://github.com/davidkpiano)! - - `wrapWorkflow` no longer freezes the caller's input: machine context holds its own copy of plain objects and arrays, and `run()` makes the workflow's own copy from the caller's input (an input that cannot be copied reaches it as is).
|
|
75
|
+
- `describeMachine` takes `helpers` and prints their source in a `Helpers` section. With `source: true`, it also prints entry and exit actions. It undoes vite SSR import rewrites.
|
|
76
|
+
- `explorePaths` and `canReach` path labels now use the v6 event shape `{ type: "xstate.done.actor" | "xstate.error.actor", actorId }`, not `xstate.done.actor.<id>`.
|
|
77
|
+
- `outputs: { src: [] }` marks a src that never settles: its invoke stays pending and the search explores events.
|
|
78
|
+
- `lintAgentMachine` takes `ignore: [{ code, path }]` to skip one check at one state.
|
|
79
|
+
- A replayed error's `name` is no longer an own enumerable property.
|
|
80
|
+
|
|
81
|
+
- [#220](https://github.com/statelyai/agent/pull/220) [`d19f404`](https://github.com/statelyai/agent/commit/d19f404d7f0afb97448650802b0e3214ed043643) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Fixes from greenfield trials:
|
|
82
|
+
|
|
83
|
+
- `runAgent` with `onIdle` keeps one inspector root across passes (the root and persisted children keep their handles), and `signal` now aborts a run parked in `onIdle`; `onIdle` receives `{ signal }`.
|
|
84
|
+
- Resuming with host-owned timers no longer throws `AgentSnapshotDivergedError`: a timer's wall-clock `scheduledAt` is left out of the snapshot hash.
|
|
85
|
+
- A request that fails inside a child machine reaches the child's `onError` instead of settling the run idle.
|
|
86
|
+
- A plain actor inside a child machine starts only after the child's earlier log entries are durable, so a resume no longer re-runs a completed tool.
|
|
87
|
+
- A request's `@agent.usage` inside a child reaches the root before the child's completion, so budget handlers see concurrent children's spend.
|
|
88
|
+
- `explorePaths` and `canReach` fire armed timers (`after`, `timeout`, delayed raises) as events instead of reporting a timer-gated search complete; `timers: "ignore"` restores the old behavior with the result marked incomplete. New `usage` option delivers `@agent.usage` before a root text request settles. A src provided as a plain actor is explored as one, even when registered as a request. New `textOutput(result, { messages })` canned output for machines that read `output.messages`.
|
|
89
|
+
|
|
90
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`4e42225`](https://github.com/statelyai/agent/commit/4e422253a97d9af218204f011038f5a2ad09cbae) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `runAgent` takes an `inbox` from `createAgentInbox()`: `inbox.send(event)` delivers host events mid-run (a cancel, a user message) with `AgentRuntime.send`'s result, queues before start, and resumes an idle run ahead of a pending `onIdle` answer.
|
|
91
|
+
|
|
92
|
+
- [#203](https://github.com/statelyai/agent/pull/203) [`c1ba55e`](https://github.com/statelyai/agent/commit/c1ba55e28514daf49ed24486c0d389706d126827) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `AgentRuntime.send(event)` delivers a host event (a cancel, a user message) into a running run's mailbox: a parked `nextEvent()` resolves with it, and it is journaled and replayed like any other event. Returns `false` once the run stopped or the machine left `active`; throws `runtime-finished` after `finish`.
|
|
93
|
+
|
|
94
|
+
- [#212](https://github.com/statelyai/agent/pull/212) [`e4c28b9`](https://github.com/statelyai/agent/commit/e4c28b9d08f00d8ddd761cb3811ab8f1852e11ba) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Docs and skills label self-improvement as experimental: the `improve-machine` skill, step 4 of `graph-engineering`, the improvement loop in Environment and policy, Part 2 of Migrating from a hand-rolled loop, and the improving examples. The gates (`verifyAgentConfig`, held-out replay) are unchanged.
|
|
95
|
+
|
|
96
|
+
- [#205](https://github.com/statelyai/agent/pull/205) [`c2e79aa`](https://github.com/statelyai/agent/commit/c2e79aac567387381ab53491e90e09410ef8935f) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Export `SetupAgentResult`, the return type of `setupAgent(...)`, so exporting a setup itself (`export const agentSetup = setupAgent(...)`) emits declarations under `declaration`/`composite` on TS 6 and 7 instead of failing with TS2883/TS7056.
|
|
97
|
+
|
|
98
|
+
- [#201](https://github.com/statelyai/agent/pull/201) [`1f66d1c`](https://github.com/statelyai/agent/commit/1f66d1cdf04c6279543ae50457047a2ae4a87fd6) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Ship `docs/` and `llms.txt` in the package so installed skills and agents can read the docs offline; quickstart pins `xstate@6.0.0-alpha.69`.
|
|
99
|
+
|
|
100
|
+
- [#206](https://github.com/statelyai/agent/pull/206) [`eba9594`](https://github.com/statelyai/agent/commit/eba9594f440639615c47a635354078466028222a) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `loop-to-machine` skill: record any model client with `recorder.client`/`recorder.fn`, exact canary counts and `it.fails` when running the old suite through the port, `explorePaths` error arrays and child exploration, `createAgentInbox` for host events, and `createApprovalBatchMachine` for approval batches.
|
|
101
|
+
|
|
102
|
+
- [#202](https://github.com/statelyai/agent/pull/202) [`6b43d21`](https://github.com/statelyai/agent/commit/6b43d212ddeda9aa39414e7c069a53b0ed723e6b) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Skills: pre-code checklist and real-codebase inventory in `loop-to-machine`, a no-decision-points branch in `improve-machine`, relative docs links.
|
|
103
|
+
|
|
104
|
+
- [#210](https://github.com/statelyai/agent/pull/210) [`7662135`](https://github.com/statelyai/agent/commit/76621350ea5dd68dc3c8a9c588875cf5a63500e5) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Inspection: `runAgent` and `createAgentRuntime` now hand an `inspect` callback one stable actor handle per session, announced once. Before, the durable runtime re-created actor objects each step under the same `sessionId`, so `@statelyai/sdk`'s inspector reported duplicate ids and showed no snapshots. The docs' `createInspector` recipe now works as written; it awaits `inspector.ready` before printing the URL.
|
|
105
|
+
|
|
106
|
+
- [#216](https://github.com/statelyai/agent/pull/216) [`bb2fb70`](https://github.com/statelyai/agent/commit/bb2fb700acf8a1ebd525acc22451ddddf4c73c6b) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Skills and `llms.txt` open with an XState v6 (not v5) primer and an "inspect one event" recipe using `transition`.
|
|
107
|
+
|
|
108
|
+
- [#217](https://github.com/statelyai/agent/pull/217) [`f1ecc51`](https://github.com/statelyai/agent/commit/f1ecc51896211d8c702c081d99ed98476c367faa) Thanks [@davidkpiano](https://github.com/davidkpiano)! - `loop-to-machine` recipe: restore a persisted snapshot with `machine.restoreSnapshot` before passing it to `transition`.
|
|
109
|
+
|
|
110
|
+
- [#213](https://github.com/statelyai/agent/pull/213) [`36dd5a5`](https://github.com/statelyai/agent/commit/36dd5a574707f0a85114e14b8aa3fe33a90a270e) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Require `xstate@6.0.0-alpha.73`. Machines without an `id` are journaled with XState's empty-string id instead of `"(machine)"`. Inline (direct-object) invokes are keyed by their invoke `id`. An actor resolving `null` now reaches `onDone` with `output: null`.
|
|
111
|
+
|
|
112
|
+
- [#220](https://github.com/statelyai/agent/pull/220) [`d19f404`](https://github.com/statelyai/agent/commit/d19f404d7f0afb97448650802b0e3214ed043643) Thanks [@davidkpiano](https://github.com/davidkpiano)! - Require `xstate@6.0.0-beta.0`. Snapshots and event logs are restored through `restoreActor` from `xstate/persist` (`machine.restoreSnapshot` and the `snapshot` actor option are gone in the beta). Snapshots persisted under a v6 alpha, including init entries that carry one, do not restore unchanged: the beta renamed timer `startedAt` to `scheduledAt` and changed the actor-ref marker. Drain or discard them before upgrading.
|
|
113
|
+
|
|
3
114
|
## 2.0.0-alpha.35
|
|
4
115
|
|
|
5
116
|
### Patch Changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { E as ACT_ACTOR } from "./event-log-DkVlk3Rh.mjs";
|
|
2
|
+
import { createAsyncLogic } from "xstate";
|
|
3
|
+
//#region src/act.ts
|
|
4
|
+
/** The `agent.act` builtin's tool-loop bound when its input sets no `maxSteps`. */
|
|
5
|
+
const DEFAULT_ACT_MAX_STEPS = 20;
|
|
6
|
+
/** What an event tool answers once the invoking state has exited. */
|
|
7
|
+
const ACT_STATE_EXITED = "state exited; stopped";
|
|
8
|
+
/** Whether `logic` is the (unbound) `agent.act` builtin. @internal */
|
|
9
|
+
function isActLogic(logic) {
|
|
10
|
+
return !!logic && typeof logic === "object" && logic.kind === "statelyai.actLogic";
|
|
11
|
+
}
|
|
12
|
+
function createActActor() {
|
|
13
|
+
const logic = createAsyncLogic({ run: async () => {
|
|
14
|
+
throw new Error(`'${ACT_ACTOR}' has no host execution. Run the machine with createAgentRuntime(...) or provideExecutors(...) and a 'generateText' executor.`);
|
|
15
|
+
} });
|
|
16
|
+
return Object.assign(logic, { kind: "statelyai.actLogic" });
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { isActLogic as i, DEFAULT_ACT_MAX_STEPS as n, createActActor as r, ACT_STATE_EXITED as t };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const require_event_log = require("./event-log-Dkc-yIYu.cjs");
|
|
2
|
+
let xstate = require("xstate");
|
|
3
|
+
//#region src/act.ts
|
|
4
|
+
/** The `agent.act` builtin's tool-loop bound when its input sets no `maxSteps`. */
|
|
5
|
+
const DEFAULT_ACT_MAX_STEPS = 20;
|
|
6
|
+
/** What an event tool answers once the invoking state has exited. */
|
|
7
|
+
const ACT_STATE_EXITED = "state exited; stopped";
|
|
8
|
+
/** Whether `logic` is the (unbound) `agent.act` builtin. @internal */
|
|
9
|
+
function isActLogic(logic) {
|
|
10
|
+
return !!logic && typeof logic === "object" && logic.kind === "statelyai.actLogic";
|
|
11
|
+
}
|
|
12
|
+
function createActActor() {
|
|
13
|
+
const logic = (0, xstate.createAsyncLogic)({ run: async () => {
|
|
14
|
+
throw new Error(`'${require_event_log.ACT_ACTOR}' has no host execution. Run the machine with createAgentRuntime(...) or provideExecutors(...) and a 'generateText' executor.`);
|
|
15
|
+
} });
|
|
16
|
+
return Object.assign(logic, { kind: "statelyai.actLogic" });
|
|
17
|
+
}
|
|
18
|
+
//#endregion
|
|
19
|
+
Object.defineProperty(exports, "ACT_STATE_EXITED", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function() {
|
|
22
|
+
return ACT_STATE_EXITED;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "DEFAULT_ACT_MAX_STEPS", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function() {
|
|
28
|
+
return DEFAULT_ACT_MAX_STEPS;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "createActActor", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function() {
|
|
34
|
+
return createActActor;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "isActLogic", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function() {
|
|
40
|
+
return isActLogic;
|
|
41
|
+
}
|
|
42
|
+
});
|
package/dist/ai-sdk.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_event_log = require("./event-log-
|
|
3
|
-
const require_decision = require("./decision-
|
|
4
|
-
const require_model_source = require("./model-source-
|
|
5
|
-
const require_with_model_calls = require("./with-model-calls-
|
|
2
|
+
const require_event_log = require("./event-log-Dkc-yIYu.cjs");
|
|
3
|
+
const require_decision = require("./decision-CMeuNZ1g.cjs");
|
|
4
|
+
const require_model_source = require("./model-source-B4WQ8Idp.cjs");
|
|
5
|
+
const require_with_model_calls = require("./with-model-calls-B_WLmOSl.cjs");
|
|
6
6
|
let ai = require("ai");
|
|
7
7
|
//#region src/ai-sdk/mappers.ts
|
|
8
8
|
/**
|
|
@@ -430,13 +430,14 @@ function createAiSdkExecutors(source) {
|
|
|
430
430
|
const decide = async (request, info) => {
|
|
431
431
|
const { model, settings: modelSettings } = resolveAiSdkModel(options, request.model);
|
|
432
432
|
if (isDecisionModel(model)) return decideWithDecisionModel(model, request, info);
|
|
433
|
-
const choice = request.options ? toAiSdkOptionTool(request.options) : void 0;
|
|
434
|
-
const tools = choice ? choice.tools : toAiSdkEventTools(request.events);
|
|
435
|
-
const messages = toDecisionMessages(request);
|
|
436
433
|
const settings = {
|
|
437
434
|
...callSettings(options, request),
|
|
438
435
|
...defined(modelSettings ?? {})
|
|
439
436
|
};
|
|
437
|
+
if (require_with_model_calls.resolveDecisionMode(options.decideMode, request) === "object") return decideWithObject(model, settings, request, info);
|
|
438
|
+
const choice = request.options ? toAiSdkOptionTool(request.options) : void 0;
|
|
439
|
+
const tools = choice ? choice.tools : toAiSdkEventTools(request.events);
|
|
440
|
+
const messages = toDecisionMessages(request);
|
|
440
441
|
const toolNames = Object.keys(tools);
|
|
441
442
|
let callEnd;
|
|
442
443
|
const unnamed = (ended, call) => ({
|
|
@@ -448,6 +449,7 @@ function createAiSdkExecutors(source) {
|
|
|
448
449
|
model,
|
|
449
450
|
abortSignal: info?.signal,
|
|
450
451
|
...settings,
|
|
452
|
+
providerOptions: withParallelToolCallsOff(settings.providerOptions),
|
|
451
453
|
onLanguageModelCallEnd: (event) => {
|
|
452
454
|
callEnd = event;
|
|
453
455
|
return settings.onLanguageModelCallEnd?.(event);
|
|
@@ -468,6 +470,11 @@ function createAiSdkExecutors(source) {
|
|
|
468
470
|
if (!result) return unnamed(callEnd);
|
|
469
471
|
const toolCall = result.toolCalls[0];
|
|
470
472
|
if (!toolCall) return unnamed(result);
|
|
473
|
+
if (result.toolCalls.length > 1) return {
|
|
474
|
+
rejected: require_with_model_calls.multipleCallsRejection(result.toolCalls.map((call) => call.toolName)),
|
|
475
|
+
usage: toAgentCallUsage(result.usage),
|
|
476
|
+
finishReason: result.finishReason
|
|
477
|
+
};
|
|
471
478
|
if (toolCall.invalid && typeof toolCall.input === "string" && toolNames.includes(toolCall.toolName)) return unnamed(result, {
|
|
472
479
|
toolName: toolCall.toolName,
|
|
473
480
|
invalidJson: true
|
|
@@ -494,6 +501,55 @@ function createAiSdkExecutors(source) {
|
|
|
494
501
|
decide
|
|
495
502
|
};
|
|
496
503
|
}
|
|
504
|
+
function withParallelToolCallsOff(providerOptions) {
|
|
505
|
+
const host = providerOptions ?? {};
|
|
506
|
+
return {
|
|
507
|
+
...host,
|
|
508
|
+
openai: {
|
|
509
|
+
parallelToolCalls: false,
|
|
510
|
+
...host.openai
|
|
511
|
+
},
|
|
512
|
+
anthropic: {
|
|
513
|
+
disableParallelToolUse: true,
|
|
514
|
+
...host.anthropic
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
async function decideWithObject(model, settings, request, info) {
|
|
519
|
+
const messages = toDecisionMessages(request);
|
|
520
|
+
const result = await (0, ai.generateText)({
|
|
521
|
+
model,
|
|
522
|
+
abortSignal: info?.signal,
|
|
523
|
+
...settings,
|
|
524
|
+
providerOptions: {
|
|
525
|
+
...settings.providerOptions,
|
|
526
|
+
openai: {
|
|
527
|
+
strictJsonSchema: false,
|
|
528
|
+
...settings.providerOptions?.openai
|
|
529
|
+
}
|
|
530
|
+
},
|
|
531
|
+
system: request.system,
|
|
532
|
+
...messages ? {
|
|
533
|
+
messages,
|
|
534
|
+
allowSystemInMessages: true
|
|
535
|
+
} : { prompt: request.prompt ?? "" },
|
|
536
|
+
output: ai.Output.object({
|
|
537
|
+
schema: (0, ai.jsonSchema)(require_with_model_calls.decisionObjectSchema(request)),
|
|
538
|
+
name: "decision"
|
|
539
|
+
}),
|
|
540
|
+
stopWhen: (0, ai.stepCountIs)(1),
|
|
541
|
+
...toAiSdkGenerationSettings(request)
|
|
542
|
+
}).catch((error) => {
|
|
543
|
+
if (ai.NoObjectGeneratedError.isInstance(error) && error.usage) return error;
|
|
544
|
+
throw error;
|
|
545
|
+
});
|
|
546
|
+
const text = result.text ?? "";
|
|
547
|
+
return {
|
|
548
|
+
...require_with_model_calls.fromDecisionObject(request, extractFirstJsonValue(text) ?? text),
|
|
549
|
+
usage: toAgentCallUsage(result.usage),
|
|
550
|
+
finishReason: result.finishReason ?? "other"
|
|
551
|
+
};
|
|
552
|
+
}
|
|
497
553
|
/** The question id a decision model's closed choice is asked under. */
|
|
498
554
|
const DECISION_QUESTION_ID = "next";
|
|
499
555
|
async function decideWithDecisionModel(model, request, info) {
|
package/dist/ai-sdk.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { l as AgentTools, p as ChosenEvent } from "./types-DQUOOaZO.cjs";
|
|
2
|
+
import { I as AgentDecisionRejection, L as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-CSf9bqpP.cjs";
|
|
3
|
+
import { n as DecisionModeOption, t as DecisionMode } from "./decision-object-DBcLWVvv.cjs";
|
|
3
4
|
import { Experimental_DecisionModel, FinishReason, LanguageModel, LanguageModelUsage, ModelMessage, ToolSet, TypedToolCall, TypedToolResult, generateText } from "ai";
|
|
4
5
|
import { AnyStateMachine } from "xstate";
|
|
5
6
|
//#region src/ai-sdk/mappers.d.ts
|
|
@@ -67,6 +68,14 @@ export type AiSdkCallSettings = Omit<Parameters<typeof generateText>[0], "model"
|
|
|
67
68
|
* portable, and a host that cannot honor a knob simply does not set it.
|
|
68
69
|
*/
|
|
69
70
|
export type CreateAiSdkExecutorsOptions<TModels extends AiSdkModelMap = AiSdkModelMap> = {
|
|
71
|
+
/**
|
|
72
|
+
* How a language model answers a `decide` request: `'object'` (default), one
|
|
73
|
+
* structured-output object naming the event; or `'tool'`, one tool per
|
|
74
|
+
* candidate event under a required tool choice, with parallel tool calls
|
|
75
|
+
* turned off and a multi-call answer rejected. A function picks per request.
|
|
76
|
+
* Decision models are unaffected.
|
|
77
|
+
*/
|
|
78
|
+
decideMode?: DecisionModeOption;
|
|
70
79
|
settings?: AiSdkCallSettings | ((request: AgentTextRequest | AgentDecisionRequest) => AiSdkCallSettings | undefined);
|
|
71
80
|
} & ({
|
|
72
81
|
models: TModels;
|
|
@@ -176,4 +185,5 @@ export interface AiSdkExecutors {
|
|
|
176
185
|
*/
|
|
177
186
|
export declare function createAiSdkExecutors<TModels extends AiSdkModelMap>(options: CreateAiSdkExecutorsOptions<TModels>): AiSdkExecutors;
|
|
178
187
|
export declare function createAiSdkExecutors(machine: AnyStateMachine): AiSdkExecutors;
|
|
179
|
-
//#endregion
|
|
188
|
+
//#endregion
|
|
189
|
+
export type { AiSdkCallUsage, DecisionMode, DecisionModeOption };
|
package/dist/ai-sdk.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { l as AgentTools, p as ChosenEvent } from "./types-DQUOOaZO.mjs";
|
|
2
|
+
import { I as AgentDecisionRejection, L as AgentDecisionRequest, c as AgentRequestExecutorInfo, f as AgentTextRequest, r as AgentFinishReason, t as AgentCallUsage } from "./text-logic-BqxalgMr.mjs";
|
|
3
|
+
import { n as DecisionModeOption, t as DecisionMode } from "./decision-object-B5zGSPFp.mjs";
|
|
3
4
|
import { AnyStateMachine } from "xstate";
|
|
4
5
|
import { Experimental_DecisionModel, FinishReason, LanguageModel, LanguageModelUsage, ModelMessage, ToolSet, TypedToolCall, TypedToolResult, generateText } from "ai";
|
|
5
6
|
//#region src/ai-sdk/mappers.d.ts
|
|
@@ -67,6 +68,14 @@ export type AiSdkCallSettings = Omit<Parameters<typeof generateText>[0], "model"
|
|
|
67
68
|
* portable, and a host that cannot honor a knob simply does not set it.
|
|
68
69
|
*/
|
|
69
70
|
export type CreateAiSdkExecutorsOptions<TModels extends AiSdkModelMap = AiSdkModelMap> = {
|
|
71
|
+
/**
|
|
72
|
+
* How a language model answers a `decide` request: `'object'` (default), one
|
|
73
|
+
* structured-output object naming the event; or `'tool'`, one tool per
|
|
74
|
+
* candidate event under a required tool choice, with parallel tool calls
|
|
75
|
+
* turned off and a multi-call answer rejected. A function picks per request.
|
|
76
|
+
* Decision models are unaffected.
|
|
77
|
+
*/
|
|
78
|
+
decideMode?: DecisionModeOption;
|
|
70
79
|
settings?: AiSdkCallSettings | ((request: AgentTextRequest | AgentDecisionRequest) => AiSdkCallSettings | undefined);
|
|
71
80
|
} & ({
|
|
72
81
|
models: TModels;
|
|
@@ -176,4 +185,5 @@ export interface AiSdkExecutors {
|
|
|
176
185
|
*/
|
|
177
186
|
export declare function createAiSdkExecutors<TModels extends AiSdkModelMap>(options: CreateAiSdkExecutorsOptions<TModels>): AiSdkExecutors;
|
|
178
187
|
export declare function createAiSdkExecutors(machine: AnyStateMachine): AiSdkExecutors;
|
|
179
|
-
//#endregion
|
|
188
|
+
//#endregion
|
|
189
|
+
export type { AiSdkCallUsage, DecisionMode, DecisionModeOption };
|
package/dist/ai-sdk.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { c as renderDecisionAttempts, o as decisionOptionIds } from "./decision-
|
|
3
|
-
import { t as resolveModelSource } from "./model-source-
|
|
4
|
-
import { n as rejectedAnswer, t as withModelCalls } from "./with-model-calls-
|
|
1
|
+
import { H as providerOutputSchema, P as getAgentOutputMode, at as isStandardSchema, gt as AgentTruncatedError, mt as isRecord } from "./event-log-DkVlk3Rh.mjs";
|
|
2
|
+
import { c as renderDecisionAttempts, o as decisionOptionIds } from "./decision-m5hGmHpF.mjs";
|
|
3
|
+
import { t as resolveModelSource } from "./model-source-kjGwqAV8.mjs";
|
|
4
|
+
import { a as multipleCallsRejection, i as fromDecisionObject, n as rejectedAnswer, o as resolveDecisionMode, r as decisionObjectSchema, t as withModelCalls } from "./with-model-calls-BkOwdroS.mjs";
|
|
5
5
|
import { InvalidResponseDataError, NoObjectGeneratedError, Output, ToolChoiceViolationError, experimental_decide, generateText, jsonSchema, stepCountIs, streamText, tool } from "ai";
|
|
6
6
|
//#region src/ai-sdk/mappers.ts
|
|
7
7
|
/**
|
|
@@ -429,13 +429,14 @@ function createAiSdkExecutors(source) {
|
|
|
429
429
|
const decide = async (request, info) => {
|
|
430
430
|
const { model, settings: modelSettings } = resolveAiSdkModel(options, request.model);
|
|
431
431
|
if (isDecisionModel(model)) return decideWithDecisionModel(model, request, info);
|
|
432
|
-
const choice = request.options ? toAiSdkOptionTool(request.options) : void 0;
|
|
433
|
-
const tools = choice ? choice.tools : toAiSdkEventTools(request.events);
|
|
434
|
-
const messages = toDecisionMessages(request);
|
|
435
432
|
const settings = {
|
|
436
433
|
...callSettings(options, request),
|
|
437
434
|
...defined(modelSettings ?? {})
|
|
438
435
|
};
|
|
436
|
+
if (resolveDecisionMode(options.decideMode, request) === "object") return decideWithObject(model, settings, request, info);
|
|
437
|
+
const choice = request.options ? toAiSdkOptionTool(request.options) : void 0;
|
|
438
|
+
const tools = choice ? choice.tools : toAiSdkEventTools(request.events);
|
|
439
|
+
const messages = toDecisionMessages(request);
|
|
439
440
|
const toolNames = Object.keys(tools);
|
|
440
441
|
let callEnd;
|
|
441
442
|
const unnamed = (ended, call) => ({
|
|
@@ -447,6 +448,7 @@ function createAiSdkExecutors(source) {
|
|
|
447
448
|
model,
|
|
448
449
|
abortSignal: info?.signal,
|
|
449
450
|
...settings,
|
|
451
|
+
providerOptions: withParallelToolCallsOff(settings.providerOptions),
|
|
450
452
|
onLanguageModelCallEnd: (event) => {
|
|
451
453
|
callEnd = event;
|
|
452
454
|
return settings.onLanguageModelCallEnd?.(event);
|
|
@@ -467,6 +469,11 @@ function createAiSdkExecutors(source) {
|
|
|
467
469
|
if (!result) return unnamed(callEnd);
|
|
468
470
|
const toolCall = result.toolCalls[0];
|
|
469
471
|
if (!toolCall) return unnamed(result);
|
|
472
|
+
if (result.toolCalls.length > 1) return {
|
|
473
|
+
rejected: multipleCallsRejection(result.toolCalls.map((call) => call.toolName)),
|
|
474
|
+
usage: toAgentCallUsage(result.usage),
|
|
475
|
+
finishReason: result.finishReason
|
|
476
|
+
};
|
|
470
477
|
if (toolCall.invalid && typeof toolCall.input === "string" && toolNames.includes(toolCall.toolName)) return unnamed(result, {
|
|
471
478
|
toolName: toolCall.toolName,
|
|
472
479
|
invalidJson: true
|
|
@@ -493,6 +500,55 @@ function createAiSdkExecutors(source) {
|
|
|
493
500
|
decide
|
|
494
501
|
};
|
|
495
502
|
}
|
|
503
|
+
function withParallelToolCallsOff(providerOptions) {
|
|
504
|
+
const host = providerOptions ?? {};
|
|
505
|
+
return {
|
|
506
|
+
...host,
|
|
507
|
+
openai: {
|
|
508
|
+
parallelToolCalls: false,
|
|
509
|
+
...host.openai
|
|
510
|
+
},
|
|
511
|
+
anthropic: {
|
|
512
|
+
disableParallelToolUse: true,
|
|
513
|
+
...host.anthropic
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
}
|
|
517
|
+
async function decideWithObject(model, settings, request, info) {
|
|
518
|
+
const messages = toDecisionMessages(request);
|
|
519
|
+
const result = await generateText({
|
|
520
|
+
model,
|
|
521
|
+
abortSignal: info?.signal,
|
|
522
|
+
...settings,
|
|
523
|
+
providerOptions: {
|
|
524
|
+
...settings.providerOptions,
|
|
525
|
+
openai: {
|
|
526
|
+
strictJsonSchema: false,
|
|
527
|
+
...settings.providerOptions?.openai
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
system: request.system,
|
|
531
|
+
...messages ? {
|
|
532
|
+
messages,
|
|
533
|
+
allowSystemInMessages: true
|
|
534
|
+
} : { prompt: request.prompt ?? "" },
|
|
535
|
+
output: Output.object({
|
|
536
|
+
schema: jsonSchema(decisionObjectSchema(request)),
|
|
537
|
+
name: "decision"
|
|
538
|
+
}),
|
|
539
|
+
stopWhen: stepCountIs(1),
|
|
540
|
+
...toAiSdkGenerationSettings(request)
|
|
541
|
+
}).catch((error) => {
|
|
542
|
+
if (NoObjectGeneratedError.isInstance(error) && error.usage) return error;
|
|
543
|
+
throw error;
|
|
544
|
+
});
|
|
545
|
+
const text = result.text ?? "";
|
|
546
|
+
return {
|
|
547
|
+
...fromDecisionObject(request, extractFirstJsonValue(text) ?? text),
|
|
548
|
+
usage: toAgentCallUsage(result.usage),
|
|
549
|
+
finishReason: result.finishReason ?? "other"
|
|
550
|
+
};
|
|
551
|
+
}
|
|
496
552
|
/** The question id a decision model's closed choice is asked under. */
|
|
497
553
|
const DECISION_QUESTION_ID = "next";
|
|
498
554
|
async function decideWithDecisionModel(model, request, info) {
|