@statelyai/agent 2.0.0-alpha.26 → 2.0.0-alpha.27
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 +4 -4
- package/dist/ai-sdk.d.cts +6 -6
- package/dist/ai-sdk.d.mts +6 -6
- package/dist/ai-sdk.mjs +4 -4
- package/dist/{decision-CM9CYZ6t.cjs → decision-CmM8-HHz.cjs} +10 -9
- package/dist/{decision-DzSv1NpD.mjs → decision-RQ0iv0oZ.mjs} +10 -9
- package/dist/{event-log-store-Ba2fsc4E.mjs → event-log-store-2pAFiWuc.mjs} +1 -1
- package/dist/{event-log-store-DvOcs10J.d.cts → event-log-store-2xzFmgr2.d.cts} +1 -1
- package/dist/{event-log-store-DxyVgnas.d.mts → event-log-store-BIPOz-di.d.mts} +1 -1
- package/dist/{event-log-store-DQmImLYk.cjs → event-log-store-C-COhIXP.cjs} +1 -1
- package/dist/index.cjs +13 -195
- package/dist/index.d.cts +25 -105
- package/dist/index.d.mts +25 -105
- package/dist/index.mjs +12 -189
- package/dist/log.cjs +1 -1
- package/dist/log.d.cts +1 -1
- package/dist/log.d.mts +1 -1
- package/dist/log.mjs +1 -1
- package/dist/machines.cjs +4 -7
- package/dist/machines.d.cts +5 -7
- package/dist/machines.d.mts +5 -7
- package/dist/machines.mjs +4 -7
- package/dist/openai.cjs +3 -3
- package/dist/openai.d.cts +5 -5
- package/dist/openai.d.mts +5 -5
- package/dist/openai.mjs +3 -3
- package/dist/otel.cjs +2 -2
- package/dist/otel.d.cts +3 -3
- package/dist/otel.d.mts +3 -3
- package/dist/otel.mjs +2 -2
- package/dist/{run-agent-CG343kFs.d.mts → run-agent-ByO-Bxyd.d.cts} +184 -179
- package/dist/{run-agent-BOfoJg5B.d.cts → run-agent-COXXc0RW.d.mts} +184 -179
- package/dist/{run-agent-Cb1-LS5P.cjs → run-agent-Dmf8GV2d.cjs} +539 -737
- package/dist/{run-agent-DvDQd4If.mjs → run-agent-xNTxpt82.mjs} +537 -705
- package/dist/{setup-agent-CFW-jPI8.mjs → setup-agent-BuanDXeh.mjs} +6 -28
- package/dist/{setup-agent-CPf7MxnG.cjs → setup-agent-DV4cTou-.cjs} +6 -28
- package/dist/testing.cjs +276 -27
- package/dist/testing.d.cts +17 -15
- package/dist/testing.d.mts +17 -15
- package/dist/testing.mjs +260 -12
- package/dist/{text-logic-Bl_ZRxDi.mjs → text-logic-CIqHAmBi.mjs} +10 -26
- package/dist/{text-logic-BFEOxyxv.d.cts → text-logic-D-czVPYp.d.mts} +27 -28
- package/dist/{text-logic-hZSiRUo1.d.mts → text-logic-IjfYy9DP.d.cts} +27 -28
- package/dist/{text-logic-C8xyr6Ag.cjs → text-logic-f5F5sCdc.cjs} +9 -43
- package/dist/{types-B1Qs2q3q.d.cts → types-BgNbNKnJ.d.mts} +3 -3
- package/dist/{types-tA3SdczG.d.mts → types-hR5f5YXa.d.cts} +3 -3
- package/dist/{utils-C2DPqomn.d.mts → utils-_q7F-AZu.d.mts} +2 -2
- package/dist/{utils-ceStNCOh.d.cts → utils-o4YRdHJX.d.cts} +2 -2
- package/dist/validate.cjs +0 -8
- package/dist/validate.mjs +0 -8
- package/package.json +3 -3
- package/readme.md +4 -2
- package/schemas/agent-workflow.json +0 -8
package/dist/testing.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { u as ChosenEvent } from "./types-
|
|
2
|
-
import { Z as AgentError, c as AgentRequestExecutorInfo, f as AgentTextRequest, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-
|
|
3
|
-
import { d as
|
|
4
|
-
import { t as MetaOfSnapshot } from "./utils-
|
|
1
|
+
import { u as ChosenEvent } from "./types-BgNbNKnJ.mjs";
|
|
2
|
+
import { Z as AgentError, c as AgentRequestExecutorInfo, f as AgentTextRequest, s as AgentRequestExecutor, t as AgentCallUsage, u as AgentRequestExecutors } from "./text-logic-D-czVPYp.mjs";
|
|
3
|
+
import { c as AgentRunResult, d as AgentRuntimeOptions, o as AgentRunInit } from "./run-agent-COXXc0RW.mjs";
|
|
4
|
+
import { t as MetaOfSnapshot } from "./utils-_q7F-AZu.mjs";
|
|
5
5
|
import { AnyMachineSnapshot, AnyStateMachine, EventFromLogic, InputFrom, SnapshotFrom, StateValue } from "xstate";
|
|
6
6
|
|
|
7
7
|
//#region src/verify.d.ts
|
|
@@ -415,11 +415,13 @@ interface TrajectoryMatch {
|
|
|
415
415
|
* @example Trajectory assertions in a test
|
|
416
416
|
* ```ts
|
|
417
417
|
* const statePath: unknown[] = [];
|
|
418
|
-
* const result = await
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
418
|
+
* const result = await runToQuiescence(
|
|
419
|
+
* createAgentRuntime(machine, {
|
|
420
|
+
* executors,
|
|
421
|
+
* onTransition: (snapshot) => statePath.push(snapshot.value),
|
|
422
|
+
* }),
|
|
423
|
+
* { input },
|
|
424
|
+
* );
|
|
423
425
|
*
|
|
424
426
|
* const path = matchesTrajectory(statePath, ['prompting', 'drafting', 'sent']);
|
|
425
427
|
* expect(path.matched, JSON.stringify(path.firstMiss)).toBe(true);
|
|
@@ -480,7 +482,7 @@ interface SeamTurn<TMachine extends AnyStateMachine> {
|
|
|
480
482
|
/** 0-based index of this pause within the run. */
|
|
481
483
|
turn: number;
|
|
482
484
|
/** The `idle` result that produced the pause. */
|
|
483
|
-
result:
|
|
485
|
+
result: AgentRunResult<TMachine>;
|
|
484
486
|
}
|
|
485
487
|
/**
|
|
486
488
|
* One text call in a {@link runSeam} run's ledger, in call order — the receipt
|
|
@@ -511,7 +513,7 @@ interface SeamSlice {
|
|
|
511
513
|
}
|
|
512
514
|
/** Options for {@link runSeam}. */
|
|
513
515
|
interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
514
|
-
/** Machine input, passed straight through to `
|
|
516
|
+
/** Machine input, passed straight through to `runToQuiescence`. */
|
|
515
517
|
input?: InputFrom<TMachine>;
|
|
516
518
|
/**
|
|
517
519
|
* The call plan: scripted answers per key, consumed in order. A key is a
|
|
@@ -554,15 +556,15 @@ interface RunSeamOptions<TMachine extends AnyStateMachine> {
|
|
|
554
556
|
* Text slots are always owned by the routing.
|
|
555
557
|
*/
|
|
556
558
|
executors?: Partial<AgentRequestExecutors>;
|
|
557
|
-
/** Passed through to `
|
|
558
|
-
actors?:
|
|
559
|
+
/** Passed through to `createAgentRuntime`: actor implementations merged onto the machine. */
|
|
560
|
+
actors?: (AgentRuntimeOptions<TMachine> & AgentRunInit<TMachine>)["actors"];
|
|
559
561
|
}
|
|
560
562
|
/** What {@link runSeam} returns: the seam's own answer, plus the run it caused. */
|
|
561
563
|
interface RunSeamResult<TMachine extends AnyStateMachine> {
|
|
562
564
|
/**
|
|
563
|
-
* The final `
|
|
565
|
+
* The final `runToQuiescence` result. `usage` accounts for the last leg.
|
|
564
566
|
*/
|
|
565
|
-
result:
|
|
567
|
+
result: AgentRunResult<TMachine>;
|
|
566
568
|
/** What the seam call returned, or `undefined` when the run never reached it. */
|
|
567
569
|
seamOutput: unknown;
|
|
568
570
|
/**
|
package/dist/testing.mjs
CHANGED
|
@@ -1,6 +1,251 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { a as isDecisionLogic, d as isRecord, l as getAcceptedEvents, s as resolveDecision, t as AgentDecisionExhaustedError } from "./decision-
|
|
3
|
-
import {
|
|
1
|
+
import { b as getRegisteredAgentExecutionOptions, d as isTextLogic, f as normalizeGeneratorResult, j as getStateMeta, u as getCallUsage, v as executorBoundLogics, z as AgentError } from "./text-logic-CIqHAmBi.mjs";
|
|
2
|
+
import { a as isDecisionLogic, d as isRecord, l as getAcceptedEvents, s as resolveDecision, t as AgentDecisionExhaustedError } from "./decision-RQ0iv0oZ.mjs";
|
|
3
|
+
import { f as runToQuiescence, s as createAgentRuntime } from "./run-agent-xNTxpt82.mjs";
|
|
4
|
+
import { initialTransition, transition } from "xstate";
|
|
5
|
+
//#region src/steps.ts
|
|
6
|
+
/**
|
|
7
|
+
* Internal: the pure `(state, event) => (nextState, requests)` view of an
|
|
8
|
+
* agent machine, used by model-free simulation (`simulateAgent`) and tests.
|
|
9
|
+
* An {@link AgentStep} is a snapshot plus the model requests the machine is
|
|
10
|
+
* now waiting on; nothing here executes anything. Hosts use
|
|
11
|
+
* `createAgentRuntime`.
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
/** @internal Normalizes current and legacy XState invoke effect shapes. */
|
|
15
|
+
function getInvokeEffectMetadata(action) {
|
|
16
|
+
if (action.type === "@xstate.spawn") return action;
|
|
17
|
+
if (action.type === "xstate.spawnChild") {
|
|
18
|
+
const params = action.params;
|
|
19
|
+
return params ? {
|
|
20
|
+
...params,
|
|
21
|
+
logic: action.logic
|
|
22
|
+
} : void 0;
|
|
23
|
+
}
|
|
24
|
+
if (action.type === "@xstate.start" && typeof action.src === "string") return action;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The invokes a snapshot is still waiting on, lowered to the same spawn-effect
|
|
28
|
+
* shape {@link getAgentRequests} reads. Derived from the snapshot's live
|
|
29
|
+
* children rather than the last transition's actions, so a state that invokes
|
|
30
|
+
* several actors at once (an `invoke: [...]` array, or parallel regions each
|
|
31
|
+
* invoking) keeps reporting the siblings after the first one settles —
|
|
32
|
+
* including when the settled invoke's `onDone` is targetless and starts
|
|
33
|
+
* nothing new.
|
|
34
|
+
*
|
|
35
|
+
* Entries are ordered by invoke id, so a walker that resolves one invoke per
|
|
36
|
+
* step is deterministic.
|
|
37
|
+
*
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
function getPendingInvokes(snapshot) {
|
|
41
|
+
const children = snapshot.children ?? {};
|
|
42
|
+
return Object.keys(children).sort().flatMap((id) => {
|
|
43
|
+
const child = children[id];
|
|
44
|
+
const childSnapshot = child?.getSnapshot?.();
|
|
45
|
+
if (!child || childSnapshot?.status !== "active") return [];
|
|
46
|
+
return [{
|
|
47
|
+
type: "@xstate.spawn",
|
|
48
|
+
id,
|
|
49
|
+
src: child.src,
|
|
50
|
+
input: childSnapshot.input,
|
|
51
|
+
logic: child.logic
|
|
52
|
+
}];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Scans a set of executable actions (as returned by xstate's `transition`/
|
|
57
|
+
* `initialTransition`) for spawned `TextLogic`/`DecisionLogic` invokes and
|
|
58
|
+
* lowers each into an {@link AgentStepRequest}. Pass `options.machine` to
|
|
59
|
+
* pre-fill `schemas`/`actors` from the machine's registered `setupAgent`
|
|
60
|
+
* options instead of passing them by hand.
|
|
61
|
+
* `options.snapshot` is required to resolve a decision's candidate events
|
|
62
|
+
* (intersecting declared `allowedEvents` with what's currently legal) — omit
|
|
63
|
+
* it and decision requests report an empty `events` list.
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
function getAgentRequests(actions, { machine, ...options } = {}) {
|
|
68
|
+
if (machine) options = {
|
|
69
|
+
...getRegisteredAgentExecutionOptions(machine),
|
|
70
|
+
...options
|
|
71
|
+
};
|
|
72
|
+
return actions.flatMap((action) => {
|
|
73
|
+
const params = getInvokeEffectMetadata(action);
|
|
74
|
+
if (!params || typeof params.src !== "string") return [];
|
|
75
|
+
if (typeof params.id !== "string" || params.id.length === 0) throw new Error(`Agent invoke '${params.src}' must define a durable string id.`);
|
|
76
|
+
const registeredLogic = isTextLogic(params.logic) || isDecisionLogic(params.logic) ? params.logic : options.actors?.[params.src];
|
|
77
|
+
if (isDecisionLogic(registeredLogic)) {
|
|
78
|
+
const decisionRequest = registeredLogic.request(params.input);
|
|
79
|
+
const allowedEventTypes = registeredLogic.allowedEventTypes?.(params.input);
|
|
80
|
+
const events = options.snapshot ? getAcceptedEvents(options.snapshot, {
|
|
81
|
+
events: options.events,
|
|
82
|
+
schemas: options.schemas,
|
|
83
|
+
eventTypes: allowedEventTypes
|
|
84
|
+
}) : [];
|
|
85
|
+
return [{
|
|
86
|
+
...decisionRequest,
|
|
87
|
+
id: params.id,
|
|
88
|
+
events
|
|
89
|
+
}];
|
|
90
|
+
}
|
|
91
|
+
const textLogic = isTextLogic(registeredLogic) ? registeredLogic : void 0;
|
|
92
|
+
const input = textLogic ? textLogic.request(params.input) : void 0;
|
|
93
|
+
if (!input) return [];
|
|
94
|
+
return [{
|
|
95
|
+
kind: "text",
|
|
96
|
+
id: params.id,
|
|
97
|
+
src: params.src,
|
|
98
|
+
...textLogic ? { mode: textLogic.mode } : {},
|
|
99
|
+
input,
|
|
100
|
+
tools: input.tools ?? {},
|
|
101
|
+
events: []
|
|
102
|
+
}];
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Builds the canonical `xstate.done.actor` event xstate's `transition()`
|
|
107
|
+
* expects to resolve a spawned invoke — including the child session identity
|
|
108
|
+
* that rejects a stale completion from an earlier incarnation.
|
|
109
|
+
*
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
function doneEvent(snapshot, request, output) {
|
|
113
|
+
const id = typeof request === "string" ? request : request.id;
|
|
114
|
+
const child = snapshot.children[id];
|
|
115
|
+
return {
|
|
116
|
+
type: "xstate.done.actor",
|
|
117
|
+
actorId: id,
|
|
118
|
+
...typeof child?.sessionId === "string" ? { sessionId: child.sessionId } : {},
|
|
119
|
+
output
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The `xstate.error.actor` counterpart of {@link doneEvent} — the event a
|
|
124
|
+
* failed invoke delivers, which `onError` transitions observe. Carries the
|
|
125
|
+
* same child session identity, so xstate does not discard it as stale.
|
|
126
|
+
*
|
|
127
|
+
* @internal
|
|
128
|
+
*/
|
|
129
|
+
function errorEvent(snapshot, request, error) {
|
|
130
|
+
const id = typeof request === "string" ? request : request.id;
|
|
131
|
+
const child = snapshot.children[id];
|
|
132
|
+
return {
|
|
133
|
+
type: "xstate.error.actor",
|
|
134
|
+
actorId: id,
|
|
135
|
+
...typeof child?.sessionId === "string" ? { sessionId: child.sessionId } : {},
|
|
136
|
+
error
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Applies a request's `output` as a done event (or, with `outcome: 'error'`,
|
|
141
|
+
* its `output` as the invoke's error) via `transition(...)`, returning the raw
|
|
142
|
+
* `[snapshot, actions]` tuple. Lower-level than {@link resolveAgentStep} /
|
|
143
|
+
* {@link rejectAgentStep} — those helpers wrap this and also run
|
|
144
|
+
* {@link getAgentRequests} to produce the next {@link AgentStep}.
|
|
145
|
+
*
|
|
146
|
+
* @internal
|
|
147
|
+
*/
|
|
148
|
+
function transitionResult(logic, snapshot, request, output, outcome = "output") {
|
|
149
|
+
const event = outcome === "error" ? errorEvent(snapshot, request, output) : doneEvent(snapshot, request, output);
|
|
150
|
+
const result = transition(logic, snapshot, event);
|
|
151
|
+
applyFinalStateOutput(logic, result[0], event);
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Starts a machine and returns its first {@link AgentStep} — the step-path
|
|
156
|
+
* equivalent of `initialTransition` plus request discovery. Begins the
|
|
157
|
+
* durable/per-model-call-checkpoint loop: resolve each `step.requests` entry
|
|
158
|
+
* (via {@link executeAgentRequest} for `kind: 'text'`, or
|
|
159
|
+
* {@link resolveDecision} for `kind: 'decision'`), then advance with
|
|
160
|
+
* {@link resolveAgentStep} or {@link transitionAgentStep}.
|
|
161
|
+
*/
|
|
162
|
+
function initialAgentStep(machine, input, options) {
|
|
163
|
+
const [snapshot, actions] = initialTransition(machine, input);
|
|
164
|
+
return createAgentStep(machine, snapshot, actions, getRegisteredAgentExecutionOptions(machine, options));
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Applies an externally-sent event (e.g. a decision's chosen event, or a
|
|
168
|
+
* human's reply) and returns the next {@link AgentStep}. Accepts **either**
|
|
169
|
+
* a raw snapshot **or** a prior `AgentStep` as the second argument —
|
|
170
|
+
* `.snapshot` is unwrapped automatically, so callers can thread the whole
|
|
171
|
+
* step object through without manually plucking the snapshot out.
|
|
172
|
+
*/
|
|
173
|
+
function transitionAgentStep(machine, snapshotOrStep, event, options) {
|
|
174
|
+
const [nextSnapshot, actions] = transition(machine, isAgentStep(snapshotOrStep) ? snapshotOrStep.snapshot : snapshotOrStep, event);
|
|
175
|
+
return createAgentStep(machine, nextSnapshot, actions, getRegisteredAgentExecutionOptions(machine, options));
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Applies a resolved text request's output (a `kind: 'text'`
|
|
179
|
+
* {@link AgentRequest} — not a decision) as a done event and returns the
|
|
180
|
+
* next {@link AgentStep}. For decisions, resolve with `resolveDecision`
|
|
181
|
+
* (which returns a {@link ChosenEvent}) and apply it with
|
|
182
|
+
* {@link transitionAgentStep} instead — a decision has no output value of
|
|
183
|
+
* its own to feed here.
|
|
184
|
+
*/
|
|
185
|
+
function resolveAgentStep(machine, step, request, output, options) {
|
|
186
|
+
const [snapshot, actions] = transitionResult(machine, step.snapshot, request, output);
|
|
187
|
+
return createAgentStep(machine, snapshot, actions, getRegisteredAgentExecutionOptions(machine, options));
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Rejects a pending invoke — the failure counterpart of
|
|
191
|
+
* {@link resolveAgentStep}. Delivers `error` as the invoke's
|
|
192
|
+
* `xstate.error.actor` event, so the machine takes that invoke's `onError`
|
|
193
|
+
* transition and returns the next {@link AgentStep}. With no `onError` in
|
|
194
|
+
* scope the returned step's snapshot has `status: 'error'`, exactly as a live
|
|
195
|
+
* run's failed invoke does.
|
|
196
|
+
*
|
|
197
|
+
* A durable host replays a failed call with this: the log says the call
|
|
198
|
+
* failed, so the replay rejects the invoke instead of resolving it. Scripted
|
|
199
|
+
* playthroughs use it too — see `simulateAgent`'s `script.errors`.
|
|
200
|
+
*
|
|
201
|
+
* `error` can be any value. An `Error` instance is the usual one, but a plain
|
|
202
|
+
* object (`{ code: 'truncated' }`) reaches the `onError` transition as
|
|
203
|
+
* `event.error` untouched, so a machine that branches on a failure code is
|
|
204
|
+
* testable without constructing a provider's error class.
|
|
205
|
+
*/
|
|
206
|
+
function rejectAgentStep(machine, step, request, error, options) {
|
|
207
|
+
const [snapshot, actions] = transitionResult(machine, step.snapshot, request, error, "error");
|
|
208
|
+
return createAgentStep(machine, snapshot, actions, getRegisteredAgentExecutionOptions(machine, options));
|
|
209
|
+
}
|
|
210
|
+
function createAgentStep(machine, snapshot, actions, options) {
|
|
211
|
+
applyFinalStateOutput(machine, snapshot);
|
|
212
|
+
return {
|
|
213
|
+
snapshot,
|
|
214
|
+
actions,
|
|
215
|
+
requests: getAgentRequests(getPendingInvokes(snapshot), {
|
|
216
|
+
...options,
|
|
217
|
+
snapshot
|
|
218
|
+
}),
|
|
219
|
+
done: snapshot.status === "done"
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
function resolveStateValueConfig(config, value) {
|
|
223
|
+
if (typeof value === "string") return config.states?.[value];
|
|
224
|
+
if (!value || typeof value !== "object") return;
|
|
225
|
+
for (const [key, childValue] of Object.entries(value)) {
|
|
226
|
+
const childConfig = config.states?.[key];
|
|
227
|
+
if (!childConfig) continue;
|
|
228
|
+
if (childConfig.type === "final") return childConfig;
|
|
229
|
+
const nested = resolveStateValueConfig(childConfig, childValue);
|
|
230
|
+
if (nested) return nested;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
function applyFinalStateOutput(logic, snapshot, event) {
|
|
234
|
+
const machineSnapshot = snapshot;
|
|
235
|
+
if (machineSnapshot.status !== "done" || machineSnapshot.output !== void 0 || !("config" in logic)) return;
|
|
236
|
+
const config = logic.config;
|
|
237
|
+
if (!config) return;
|
|
238
|
+
const output = resolveStateValueConfig(config, machineSnapshot.value)?.output;
|
|
239
|
+
if (output === void 0) return;
|
|
240
|
+
machineSnapshot.output = typeof output === "function" ? output({
|
|
241
|
+
context: machineSnapshot.context,
|
|
242
|
+
event
|
|
243
|
+
}) : output;
|
|
244
|
+
}
|
|
245
|
+
function isAgentStep(value) {
|
|
246
|
+
return !!value && typeof value === "object" && "snapshot" in value && "actions" in value && "requests" in value;
|
|
247
|
+
}
|
|
248
|
+
//#endregion
|
|
4
249
|
//#region src/verify.ts
|
|
5
250
|
const DECIDE_SRC = "agent.decide";
|
|
6
251
|
function normalizeInvokes(invoke) {
|
|
@@ -77,7 +322,7 @@ function checkDirectObjectSrc(ctx) {
|
|
|
77
322
|
code: "direct-object-src",
|
|
78
323
|
severity: "warning",
|
|
79
324
|
path: node.path,
|
|
80
|
-
message: `State '${node.path}' invokes a direct-object agent logic. Direct-object invoke srcs cannot be rebound by
|
|
325
|
+
message: `State '${node.path}' invokes a direct-object agent logic. Direct-object invoke srcs cannot be rebound by the agent runtime, so they inherit no host executors — call '.withExecutor(...)' on the logic, or register it as a string-keyed actor source (machine.provide({ actors: { name: logic } })) and invoke it by name.`
|
|
81
326
|
});
|
|
82
327
|
}
|
|
83
328
|
return out;
|
|
@@ -811,11 +1056,13 @@ function matcherFor(expected) {
|
|
|
811
1056
|
* @example Trajectory assertions in a test
|
|
812
1057
|
* ```ts
|
|
813
1058
|
* const statePath: unknown[] = [];
|
|
814
|
-
* const result = await
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
*
|
|
818
|
-
*
|
|
1059
|
+
* const result = await runToQuiescence(
|
|
1060
|
+
* createAgentRuntime(machine, {
|
|
1061
|
+
* executors,
|
|
1062
|
+
* onTransition: (snapshot) => statePath.push(snapshot.value),
|
|
1063
|
+
* }),
|
|
1064
|
+
* { input },
|
|
1065
|
+
* );
|
|
819
1066
|
*
|
|
820
1067
|
* const path = matchesTrajectory(statePath, ['prompting', 'drafting', 'sent']);
|
|
821
1068
|
* expect(path.matched, JSON.stringify(path.firstMiss)).toBe(true);
|
|
@@ -1023,9 +1270,7 @@ async function runSeam(machine, options) {
|
|
|
1023
1270
|
let result;
|
|
1024
1271
|
const maxTurns = options.maxTurns ?? 12;
|
|
1025
1272
|
for (let turn = 0; turn <= maxTurns; turn++) {
|
|
1026
|
-
result = await
|
|
1027
|
-
...snapshot ? { snapshot } : { input: options.input },
|
|
1028
|
-
...event ? { event } : {},
|
|
1273
|
+
result = await runToQuiescence(createAgentRuntime(machine, {
|
|
1029
1274
|
...options.actors ? { actors: options.actors } : {},
|
|
1030
1275
|
executors,
|
|
1031
1276
|
onTransition: (next, causedBy) => {
|
|
@@ -1034,6 +1279,9 @@ async function runSeam(machine, options) {
|
|
|
1034
1279
|
liveEvents = events.length;
|
|
1035
1280
|
statePath.push(next.value);
|
|
1036
1281
|
}
|
|
1282
|
+
}), {
|
|
1283
|
+
...snapshot ? { snapshot } : { input: options.input },
|
|
1284
|
+
...event ? { event } : {}
|
|
1037
1285
|
});
|
|
1038
1286
|
if (result.status !== "idle" || turn === maxTurns) break;
|
|
1039
1287
|
const next = options.respond?.({
|
|
@@ -125,7 +125,7 @@ function findNonSerializableContextPaths(context, limit = 5) {
|
|
|
125
125
|
* their prompts or executors hash identically; adding/removing/retargeting a
|
|
126
126
|
* state or transition changes the hash.
|
|
127
127
|
*
|
|
128
|
-
* Used by {@link
|
|
128
|
+
* Used by {@link createAgentRuntime} to stamp settled snapshots with a `version` and to
|
|
129
129
|
* detect a structurally-edited machine on resume. It is a change detector, not
|
|
130
130
|
* a cryptographic digest — collisions are possible but unlikely for real
|
|
131
131
|
* configs. Declare `createMachine({ version })` to pin an explicit version instead.
|
|
@@ -136,7 +136,7 @@ function getMachineStructuralHash(machine) {
|
|
|
136
136
|
/**
|
|
137
137
|
* The version a machine is stamped with everywhere: an explicitly declared
|
|
138
138
|
* `createMachine({ version })` when present, else its
|
|
139
|
-
* {@link getMachineStructuralHash}. Single source of truth so `
|
|
139
|
+
* {@link getMachineStructuralHash}. Single source of truth so `createAgentRuntime`,
|
|
140
140
|
* `provideExecutors`/`traceTransitions` trace envelopes agree.
|
|
141
141
|
* @internal
|
|
142
142
|
*/
|
|
@@ -327,7 +327,7 @@ function validateSchemaSync(schema, value) {
|
|
|
327
327
|
* Registered execution options, keyed on BOTH the machine object and its root
|
|
328
328
|
* `config` object. `config` is shared by reference across `machine.provide(...)`
|
|
329
329
|
* (unlike the machine itself), so the `config` key is what lets a machine
|
|
330
|
-
* rebound by `
|
|
330
|
+
* rebound by `createAgentRuntime` — or by any host `.provide(...)` — still resolve the
|
|
331
331
|
* schemas/actors `setupAgent` registered. Always write through
|
|
332
332
|
* {@link setAgentExecutionOptions} and read through
|
|
333
333
|
* {@link getAgentExecutionOptions}.
|
|
@@ -347,7 +347,7 @@ function setAgentExecutionOptions(machine, options) {
|
|
|
347
347
|
}
|
|
348
348
|
/**
|
|
349
349
|
* Reads the options registered for `machine`, falling back to the root `config`
|
|
350
|
-
* key so a `.provide(...)`-rebound machine (e.g. the one behind a `
|
|
350
|
+
* key so a `.provide(...)`-rebound machine (e.g. the one behind a `runToQuiescence`
|
|
351
351
|
* result snapshot) resolves the same pack.
|
|
352
352
|
*/
|
|
353
353
|
function getAgentExecutionOptions(machine) {
|
|
@@ -357,24 +357,9 @@ function getAgentExecutionOptions(machine) {
|
|
|
357
357
|
const config = machineConfigKey(machine);
|
|
358
358
|
return config ? agentExecutionOptions.get(config) : void 0;
|
|
359
359
|
}
|
|
360
|
-
/**
|
|
361
|
-
* Machine-carried wait-state predicates, keyed on the machine's root `config`
|
|
362
|
-
* object. `config` is shared by reference across `machine.provide(...)` (unlike
|
|
363
|
-
* the machine object itself), so a predicate registered here travels with the
|
|
364
|
-
* machine through `.provide` — which is why it is keyed on `config`, not the
|
|
365
|
-
* machine. Set by `setupAgent({ isIdle })` in `createMachine` and by
|
|
366
|
-
* `setupAgent.fromConfig` (its `isIdle` option or the config's
|
|
367
|
-
* `idleTags`), read by `runAgent` before its structural default.
|
|
368
|
-
*/
|
|
369
|
-
const machineIdlePredicates = /* @__PURE__ */ new WeakMap();
|
|
370
|
-
/** Reads the {@link machineIdlePredicates} predicate carried by `machine` (via its root `config`), if any. */
|
|
371
|
-
function getMachineIdlePredicate(machine) {
|
|
372
|
-
const config = machine.config;
|
|
373
|
-
return config ? machineIdlePredicates.get(config) : void 0;
|
|
374
|
-
}
|
|
375
360
|
const unboundPlaceholderLogics = /* @__PURE__ */ new WeakSet();
|
|
376
361
|
/** Text/decision logics created WITH their own executor (withExecutor or the
|
|
377
|
-
* factory's second arg) — these are runnable as-is, so
|
|
362
|
+
* factory's second arg) — these are runnable as-is, so the runtime's bind check
|
|
378
363
|
* must not reject them as direct-object invoke srcs. */
|
|
379
364
|
const executorBoundLogics = /* @__PURE__ */ new WeakSet();
|
|
380
365
|
function missingActor(src) {
|
|
@@ -408,7 +393,7 @@ const AGENT_FINISH_REASONS = new Set([
|
|
|
408
393
|
/**
|
|
409
394
|
* Reads a settled call's {@link AgentFinishReason} off a RAW executor result's
|
|
410
395
|
* `finishReason` field — the finish-reason sibling of {@link getCallUsage},
|
|
411
|
-
* applied by
|
|
396
|
+
* applied by the runtime before it puts the reason on the `request.end` trace.
|
|
412
397
|
* A provider's `'error'` normalizes to `'other'`; anything else the union does
|
|
413
398
|
* not name (an un-normalized provider string, a missing field) returns
|
|
414
399
|
* `undefined`.
|
|
@@ -430,7 +415,7 @@ const AGENT_USAGE_TOKEN_FIELDS = [
|
|
|
430
415
|
/**
|
|
431
416
|
* Reads a settled call's per-call {@link AgentCallUsage} off a RAW executor
|
|
432
417
|
* result's `usage` field, keeping only finite numbers — the same normalization
|
|
433
|
-
*
|
|
418
|
+
* the runtime applies before it delivers `'@agent.usage'`. Returns `undefined`
|
|
434
419
|
* when the result reports no usage at all. Works for our `{ result, usage }`
|
|
435
420
|
* shape, for a raw Vercel AI SDK result (its `LanguageModelUsage` carries
|
|
436
421
|
* the same flat field names), and for any custom executor that follows the
|
|
@@ -585,8 +570,7 @@ function resolveTextLogicValue(value, args) {
|
|
|
585
570
|
* result under `actors:` and invoke it by name (equivalent to what
|
|
586
571
|
* `setupAgent({ requests })` builds internally for each request entry). Pass
|
|
587
572
|
* `execute` here, or bind it later with `.withExecutor(...)`, a runtime
|
|
588
|
-
* adapter's `machine.provide(...)`, or `
|
|
589
|
-
* `streamText` options.
|
|
573
|
+
* adapter's `machine.provide(...)`, or `createAgentRuntime`'s `executors`.
|
|
590
574
|
*
|
|
591
575
|
* @example
|
|
592
576
|
* ```ts
|
|
@@ -639,7 +623,7 @@ function createTextLogic(config, execute) {
|
|
|
639
623
|
};
|
|
640
624
|
const logic = createAsyncLogic({ run: async ({ input, signal, system, self }, enq) => {
|
|
641
625
|
const resolvedRequest = request(input);
|
|
642
|
-
if (!execute) throw new Error("Text logic has no host execution. Pass an executor as the second argument to createTextLogic(...), provide a runtime adapter, or bind it through
|
|
626
|
+
if (!execute) throw new Error("Text logic has no host execution. Pass an executor as the second argument to createTextLogic(...), provide a runtime adapter, or bind it through createAgentRuntime/provideExecutors, or execute the XState effect in your host.");
|
|
643
627
|
const result = await execute({
|
|
644
628
|
input,
|
|
645
629
|
request: resolvedRequest,
|
|
@@ -830,4 +814,4 @@ function invalidGeneratorResult(id) {
|
|
|
830
814
|
return /* @__PURE__ */ new Error(`Executor for '${id}' returned an invalid result: executors must return { result } (the text string or structured object as \`result\`, plus optional \`messages\`, \`usage\` and other passthrough fields). Wrap a raw SDK result with an adapter such as createAiSdkExecutors.`);
|
|
831
815
|
}
|
|
832
816
|
//#endregion
|
|
833
|
-
export {
|
|
817
|
+
export { getMessageText as A, AgentTruncatedError as B, setAgentExecutionOptions as C, getJsonSchema as D, findNonSerializableContextPaths as E, systemMessage as F, toolMessage as I, userMessage as L, getStatePath as M, isStandardSchema as N, getJsonSchemaSync as O, resolveMachineVersion as P, validateSchemaSync as R, missingActor as S, djb2Hex as T, responseMessagesOf as _, bindRequestExecutor as a, getRegisteredAgentExecutionOptions as b, getAgentOutputMode as c, isTextLogic as d, normalizeGeneratorResult as f, resolveTextLogicValue as g, providerOutputSchema as h, STREAM_TEXT_ACTOR as i, getStateMeta as j, getMachineStructuralHash as k, getCallFinishReason as l, parseProviderOutput as m, DECIDE_ACTOR as n, builtinTextActors as o, parseOutput as p, GENERATE_TEXT_ACTOR as r, createTextLogic as s, AGENT_USAGE_TOKEN_FIELDS as t, getCallUsage as u, executorBoundLogics as v, assistantMessage as w, isUnboundPlaceholder as x, getAgentExecutionOptions as y, AgentError as z };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as StandardSchemaV1, c as AllowedEvents, h as InferOutput, i as AgentToolChoice, n as AgentMessage, s as AgentTools, u as ChosenEvent } from "./types-
|
|
1
|
+
import { _ as StandardSchemaV1, c as AllowedEvents, h as InferOutput, i as AgentToolChoice, n as AgentMessage, s as AgentTools, u as ChosenEvent } from "./types-BgNbNKnJ.mjs";
|
|
2
2
|
import { AnyMachineSnapshot, AnyStateMachine, AsyncActorLogic, EventFromLogic, EventObject, MachineSnapshot } from "xstate";
|
|
3
3
|
|
|
4
4
|
//#region src/errors.d.ts
|
|
@@ -77,7 +77,7 @@ interface AgentEventDescriptor {
|
|
|
77
77
|
/** Registered schemas, as attached to a machine by `setupAgent`/`createAgentSchemas`. */
|
|
78
78
|
interface AgentSchemas {
|
|
79
79
|
events?: Record<string, StandardSchemaV1>;
|
|
80
|
-
/** Machine input schema;
|
|
80
|
+
/** Machine input schema; the runtime validates the run's `input` against it. */
|
|
81
81
|
input?: StandardSchemaV1;
|
|
82
82
|
}
|
|
83
83
|
/** Shared options threaded through step discovery ({@link getAgentRequests}/{@link getAcceptedEvents}) — snapshot for event legality, event schemas for payload validation/tool schemas, and registered actor source logics. */
|
|
@@ -94,7 +94,7 @@ type ParsedAgentEvent<TSource> = TSource extends AnyStateMachine ? EventFromLogi
|
|
|
94
94
|
/**
|
|
95
95
|
* Parses a wire payload (a request body, a socket frame) into an
|
|
96
96
|
* event typed as the machine's event union, so it can go straight to
|
|
97
|
-
* `
|
|
97
|
+
* `runToQuiescence(runtime, { event })` / `actor.send(...)` without a cast. Pass the machine
|
|
98
98
|
* itself, or any snapshot of it.
|
|
99
99
|
*
|
|
100
100
|
* It checks exactly what a schema can check: the payload is an object with a
|
|
@@ -111,7 +111,8 @@ type ParsedAgentEvent<TSource> = TSource extends AnyStateMachine ? EventFromLogi
|
|
|
111
111
|
* @example
|
|
112
112
|
* ```ts
|
|
113
113
|
* const event = parseAgentEvent(machine, await request.json());
|
|
114
|
-
* const
|
|
114
|
+
* const runtime = createAgentRuntime(machine, { store, threadId, executors });
|
|
115
|
+
* const result = await runToQuiescence(runtime, { event });
|
|
115
116
|
* ```
|
|
116
117
|
*/
|
|
117
118
|
declare function parseAgentEvent<TSource extends AnyStateMachine | AnyMachineSnapshot>(source: TSource, payload: unknown, options?: Pick<AgentRequestOptions, "events" | "schemas">): ParsedAgentEvent<TSource>;
|
|
@@ -190,7 +191,7 @@ interface DecisionLogicConfig<TInputSchema extends StandardSchemaV1 = StandardSc
|
|
|
190
191
|
}
|
|
191
192
|
/**
|
|
192
193
|
* Actor logic for a decision: an async effect that resolves to exactly one
|
|
193
|
-
* currently-legal {@link ChosenEvent} (never a plain value). Under `
|
|
194
|
+
* currently-legal {@link ChosenEvent} (never a plain value). Under `createAgentRuntime`
|
|
194
195
|
* the chosen event is delivered to the invoking actor automatically — the
|
|
195
196
|
* transition it triggers usually exits the invoking state and ends the invoke.
|
|
196
197
|
* Built by {@link createDecisionLogic}. Register it under `actors:` to reuse/export/
|
|
@@ -208,7 +209,7 @@ interface DecisionLogic<TInputSchema extends StandardSchemaV1 = StandardSchemaV1
|
|
|
208
209
|
* run, resolves to exactly one currently-legal {@link ChosenEvent} by
|
|
209
210
|
* calling the host `decide` executor (passed here as `execute`, or supplied
|
|
210
211
|
* later via {@link DecisionLogic.withExecutor}, `machine.provide(...)`, or
|
|
211
|
-
* `
|
|
212
|
+
* `createAgentRuntime`'s `executors.decide`). Register the result under `actors:` and
|
|
212
213
|
* invoke it by name; for a one-off, state-local decision, prefer the
|
|
213
214
|
* `agent.decide` builtin invoke instead — it needs no separate declaration
|
|
214
215
|
* and types `allowedEvents` against the machine's own event schemas.
|
|
@@ -264,10 +265,10 @@ interface AgentDecisionRequest {
|
|
|
264
265
|
stopSequences?: string[];
|
|
265
266
|
metadata?: Record<string, unknown>;
|
|
266
267
|
/**
|
|
267
|
-
* The
|
|
268
|
-
* events), injected by
|
|
268
|
+
* The run this decision belongs to (`run_<n>`, matching trace
|
|
269
|
+
* events), injected by the runtime like `signal` (symmetric with the text
|
|
269
270
|
* executors' `info.runId`). Runtime-only correlation for executor
|
|
270
|
-
* middleware; unset off the
|
|
271
|
+
* middleware; unset off the runtime path. Per-attempt context is already
|
|
271
272
|
* on the request: `id` is the durable invoke id and `attempts.length` is
|
|
272
273
|
* the current attempt index.
|
|
273
274
|
*/
|
|
@@ -362,7 +363,7 @@ declare function renderDecisionAttempts(request: Pick<AgentDecisionRequest, "eve
|
|
|
362
363
|
* `onResult`/event-sourcing but never affects validation. Like text
|
|
363
364
|
* executors' `{ result, ...extras }`, any extra keys (finish reason,
|
|
364
365
|
* …) flow untouched to `onResult`'s `raw`; `usage` is the one core reads —
|
|
365
|
-
* report this attempt's tokens there and
|
|
366
|
+
* report this attempt's tokens there and the runtime folds them into the run's
|
|
366
367
|
* aggregated {@link AgentUsage}.
|
|
367
368
|
*/
|
|
368
369
|
type AgentDecisionExecutor = (request: AgentExecutorDecisionRequest, info?: AgentRequestExecutorInfo) => PromiseLike<{
|
|
@@ -493,7 +494,7 @@ interface AgentTextRequest<TMetadata = Record<string, unknown>, TMessage = any>
|
|
|
493
494
|
* `stopWhen: stepCountIs(maxSteps)`.
|
|
494
495
|
*
|
|
495
496
|
* This is a REQUEST budget, distinct from the machine-level `maxTurns` a
|
|
496
|
-
* preset uses for its own turn budget, and from `
|
|
497
|
+
* preset uses for its own turn budget, and from `createAgentRuntime`'s run-wide
|
|
497
498
|
* `maxModelCalls`.
|
|
498
499
|
*/
|
|
499
500
|
maxSteps?: number;
|
|
@@ -506,9 +507,9 @@ interface AgentTextRequest<TMetadata = Record<string, unknown>, TMessage = any>
|
|
|
506
507
|
metadata?: TMetadata;
|
|
507
508
|
}
|
|
508
509
|
/**
|
|
509
|
-
* Aggregated model-call usage for ONE
|
|
510
|
-
* attached to every settled {@link
|
|
511
|
-
* `
|
|
510
|
+
* Aggregated model-call usage for ONE run — the run-level total
|
|
511
|
+
* attached to every settled {@link AgentRunResult} (and therefore to
|
|
512
|
+
* `runToQuiescence`'s `{ output, snapshot, persist, usage }`).
|
|
512
513
|
*
|
|
513
514
|
* - `modelCalls` counts every model/decision call this run made (each decision
|
|
514
515
|
* retry counts separately) — the same seam `maxModelCalls` budgets. Always a
|
|
@@ -542,7 +543,7 @@ type AgentCallUsage = Omit<AgentUsage, "modelCalls">;
|
|
|
542
543
|
* - `'content-filter'` — a safety filter stopped it.
|
|
543
544
|
* - `'other'` — anything else, including a provider error the adapter mapped.
|
|
544
545
|
*
|
|
545
|
-
* Adapters set it on their executor result;
|
|
546
|
+
* Adapters set it on their executor result; the runtime copies it onto the
|
|
546
547
|
* `request.end` trace event. A provider's own string stays on the result's
|
|
547
548
|
* `raw`.
|
|
548
549
|
*/
|
|
@@ -550,7 +551,7 @@ type AgentFinishReason = "stop" | "length" | "tool-calls" | "content-filter" | "
|
|
|
550
551
|
/**
|
|
551
552
|
* Reads a settled call's {@link AgentFinishReason} off a RAW executor result's
|
|
552
553
|
* `finishReason` field — the finish-reason sibling of {@link getCallUsage},
|
|
553
|
-
* applied by
|
|
554
|
+
* applied by the runtime before it puts the reason on the `request.end` trace.
|
|
554
555
|
* A provider's `'error'` normalizes to `'other'`; anything else the union does
|
|
555
556
|
* not name (an un-normalized provider string, a missing field) returns
|
|
556
557
|
* `undefined`.
|
|
@@ -559,7 +560,7 @@ declare function getCallFinishReason(raw: unknown): AgentFinishReason | undefine
|
|
|
559
560
|
/**
|
|
560
561
|
* Reads a settled call's per-call {@link AgentCallUsage} off a RAW executor
|
|
561
562
|
* result's `usage` field, keeping only finite numbers — the same normalization
|
|
562
|
-
*
|
|
563
|
+
* the runtime applies before it delivers `'@agent.usage'`. Returns `undefined`
|
|
563
564
|
* when the result reports no usage at all. Works for our `{ result, usage }`
|
|
564
565
|
* shape, for a raw Vercel AI SDK result (its `LanguageModelUsage` carries
|
|
565
566
|
* the same flat field names), and for any custom executor that follows the
|
|
@@ -689,8 +690,7 @@ interface TextLogic<TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TO
|
|
|
689
690
|
* result under `actors:` and invoke it by name (equivalent to what
|
|
690
691
|
* `setupAgent({ requests })` builds internally for each request entry). Pass
|
|
691
692
|
* `execute` here, or bind it later with `.withExecutor(...)`, a runtime
|
|
692
|
-
* adapter's `machine.provide(...)`, or `
|
|
693
|
-
* `streamText` options.
|
|
693
|
+
* adapter's `machine.provide(...)`, or `createAgentRuntime`'s `executors`.
|
|
694
694
|
*
|
|
695
695
|
* @example
|
|
696
696
|
* ```ts
|
|
@@ -732,7 +732,7 @@ declare function bindRequestExecutor<TInputSchema extends StandardSchemaV1, TOut
|
|
|
732
732
|
* without it is a runtime error.
|
|
733
733
|
*
|
|
734
734
|
* `usage` is the one passthrough field core reads: report this call's tokens
|
|
735
|
-
* there and
|
|
735
|
+
* there and the runtime folds them into the run's aggregated
|
|
736
736
|
* {@link AgentUsage}. Optional — an executor that reports nothing still counts
|
|
737
737
|
* toward `modelCalls`.
|
|
738
738
|
*/
|
|
@@ -744,16 +744,15 @@ type AgentRequestExecutorResult<TOutput = unknown, TMessage = unknown> = {
|
|
|
744
744
|
[key: string]: unknown;
|
|
745
745
|
};
|
|
746
746
|
/**
|
|
747
|
-
* Optional second argument passed to executors by `
|
|
748
|
-
*
|
|
749
|
-
* the live path, where `onChunk` (§3.1) needs a way to reach the executor.
|
|
747
|
+
* Optional second argument passed to executors by `createAgentRuntime`: the
|
|
748
|
+
* request's abort signal, and `onChunk` for streamed requests.
|
|
750
749
|
*/
|
|
751
750
|
interface AgentRequestExecutorInfo {
|
|
752
751
|
onChunk?: (chunk: string) => void;
|
|
753
752
|
signal?: AbortSignal;
|
|
754
753
|
/**
|
|
755
|
-
* The
|
|
756
|
-
* events). Undefined off the
|
|
754
|
+
* The run this call belongs to (`run_<n>`, matching trace
|
|
755
|
+
* events). Undefined off the runtime path (bare `provideExecutors` /
|
|
757
756
|
* direct `TextLogic.execute`). Lets executor middleware (caching, rate
|
|
758
757
|
* limits, span parenting) correlate calls without side channels.
|
|
759
758
|
*/
|
|
@@ -780,7 +779,7 @@ interface AgentRequestExecutorInfo {
|
|
|
780
779
|
* lineage id, so cache on `callKey` together with a fingerprint of the
|
|
781
780
|
* request and reuse a cached result only when the request also matches.
|
|
782
781
|
*
|
|
783
|
-
* Undefined off the `
|
|
782
|
+
* Undefined off the `createAgentRuntime` path, and for a log with no `executionId`.
|
|
784
783
|
*/
|
|
785
784
|
callKey?: string;
|
|
786
785
|
}
|
|
@@ -803,11 +802,11 @@ type AgentExecutorTextRequest<TMetadata = Record<string, unknown>> = Omit<AgentT
|
|
|
803
802
|
type AgentRequestExecutor<TResult extends AgentRequestExecutorResult = AgentRequestExecutorResult> = (request: AgentExecutorTextRequest, info?: AgentRequestExecutorInfo) => TResult | PromiseLike<TResult>;
|
|
804
803
|
/**
|
|
805
804
|
* The full set of host executors a machine's agent actors are resolved
|
|
806
|
-
* with — passed to `
|
|
805
|
+
* with — passed to `createAgentRuntime`, `executeAgentRequest`, and
|
|
807
806
|
* `TextLogic.execute`. Every slot is optional: `generateText` is needed only
|
|
808
807
|
* if the machine has a `mode: 'generate'` text request, `streamText` only for
|
|
809
808
|
* a `mode: 'stream'` request, and `decide` only for a decision — omitting
|
|
810
|
-
* a slot the machine actually needs is a clear bind-time error (see `
|
|
809
|
+
* a slot the machine actually needs is a clear bind-time error (see `createAgentRuntime`
|
|
811
810
|
* and `provideExecutors`). Adapter result sets (`AiSdkExecutors`,
|
|
812
811
|
* `OpenAiCompatExecutors`) re-require all three.
|
|
813
812
|
*/
|