@statelyai/agent 2.0.0-alpha.7 → 2.0.0-alpha.9
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 +34 -3
- package/dist/ai-sdk.d.cts +34 -5
- package/dist/ai-sdk.d.mts +34 -5
- package/dist/ai-sdk.mjs +33 -4
- package/dist/cli.cjs +3 -2
- package/dist/cli.mjs +2 -1
- package/dist/{decision-mPR_YQd8.mjs → decision-CQdrKc8k.mjs} +4 -1
- package/dist/{decision-BnATHy0W.cjs → decision-b-lkcs4L.cjs} +9 -0
- package/dist/index.cjs +13 -12
- package/dist/index.d.cts +6 -1072
- package/dist/index.d.mts +6 -1072
- package/dist/index.mjs +3 -2
- package/dist/openai-compat.cjs +1 -1
- package/dist/openai-compat.d.cts +3 -3
- package/dist/openai-compat.d.mts +3 -3
- package/dist/openai-compat.mjs +1 -1
- package/dist/{src-MysDmqwT.cjs → run-agent-BFMkuI1F.cjs} +31 -1046
- package/dist/run-agent-BVMd--1l.d.cts +1103 -0
- package/dist/{src-BpQdxsKc.mjs → run-agent-BoAOq_0Z.mjs} +33 -988
- package/dist/run-agent-DzYJb3CK.d.mts +1103 -0
- package/dist/src-BOW6g5zE.mjs +984 -0
- package/dist/src-CdTwCO35.cjs +1043 -0
- package/dist/{text-logic-2wFNEznm.d.mts → text-logic-C7WJpCIc.d.mts} +1 -1
- package/dist/{text-logic-4Q2F9kyr.d.cts → text-logic-CZjyACzQ.d.cts} +1 -1
- package/dist/{types-BHjeDdch.d.cts → types-C9QiMjre.d.cts} +16 -5
- package/dist/{types-Cq1YlAQ6.d.mts → types-qm00QF91.d.mts} +16 -5
- package/dist/{utils-CWUCa3pF.d.mts → utils-Dri7aeEG.d.cts} +1 -1
- package/dist/{utils-lK1wnL2i.d.cts → utils-Y6GDRGGE.d.mts} +1 -1
- package/dist/zod.d.cts +1 -1
- package/dist/zod.d.mts +1 -1
- package/package.json +1 -1
- package/readme.md +21 -23
package/dist/index.d.mts
CHANGED
|
@@ -1,1075 +1,9 @@
|
|
|
1
|
-
import { C as
|
|
2
|
-
import { A as AgentDecisionInput, B as renderDecisionAttempts, C as createTextLogic, D as parseOutput, E as parseModelRef, F as DecisionExhaustedError, G as AgentRequestSource, H as AgentEventDescriptor, I as DecisionLogic, J as matchesEventPattern, K as EVENT_TOOL_PREFIX, L as DecisionLogicConfig, M as AgentPlanInput, N as AgentPlanOutput, O as parseStructuredEnvelope, P as DecisionAttempt, R as PLAN_DONE_EVENT_TYPE, S as buildEnvelopeSchema, T as isStructuredOutputSchema, U as AgentEventToolNameResolver, V as resolveDecision, W as AgentRequestOptions, Y as parseAgentEvent, _ as TextLogicExecuteArgs, a as AgentRequestExecutorInfo, b as TextLogicOutput, c as AgentRequestMode, d as AiSdkShapedStreamResult, f as AiSdkShapedTextResult, g as TextLogicConfig, h as TextLogic, i as AgentRequestExecutor, j as AgentDecisionRequest, k as AgentDecisionExecutor, l as AgentTextRequest, m as StructuredOutputEnvelope, n as AgentModelRef, o as AgentRequestExecutorResult,
|
|
3
|
-
import { a as
|
|
4
|
-
import {
|
|
1
|
+
import { A as UserMessage, C as StandardSchemaV1, D as ToolMessage, E as ToolCallPart, O as ToolResultOutput, S as ProviderOptions, T as TextPart, _ as EventUnion, a as AgentTool, b as InferOutput, c as AgentToolExecute, d as AllowedEventPattern, f as AllowedEvents, g as EventPayload, h as DataContent, i as AgentSnapshotStore, k as ToolResultPart, l as AgentToolSchema, m as ChosenEvent, n as AgentEventSchemaInputMap, o as AgentToolChoice, p as AssistantMessage, r as AgentMessage, s as AgentToolDescriptor, t as AgentEventSchemaInput, u as AgentTools, v as FilePart, w as SystemMessage, x as NormalizedEventSchemas, y as ImagePart } from "./types-qm00QF91.mjs";
|
|
2
|
+
import { A as AgentDecisionInput, B as renderDecisionAttempts, C as createTextLogic, D as parseOutput, E as parseModelRef, F as DecisionExhaustedError, G as AgentRequestSource, H as AgentEventDescriptor, I as DecisionLogic, J as matchesEventPattern, K as EVENT_TOOL_PREFIX, L as DecisionLogicConfig, M as AgentPlanInput, N as AgentPlanOutput, O as parseStructuredEnvelope, P as DecisionAttempt, R as PLAN_DONE_EVENT_TYPE, S as buildEnvelopeSchema, T as isStructuredOutputSchema, U as AgentEventToolNameResolver, V as resolveDecision, W as AgentRequestOptions, Y as parseAgentEvent, _ as TextLogicExecuteArgs, a as AgentRequestExecutorInfo, b as TextLogicOutput, c as AgentRequestMode, d as AiSdkShapedStreamResult, f as AiSdkShapedTextResult, g as TextLogicConfig, h as TextLogic, i as AgentRequestExecutor, j as AgentDecisionRequest, k as AgentDecisionExecutor, l as AgentTextRequest, m as StructuredOutputEnvelope, n as AgentModelRef, o as AgentRequestExecutorResult, q as getAcceptedEvents, r as AgentOutputMode, s as AgentRequestExecutors, t as AgentModelMap, u as AgentUserInput, v as TextLogicExecutor, w as getAgentOutputMode, x as bindRequestExecutor, y as TextLogicInput, z as ResolveDecisionOptions } from "./text-logic-C7WJpCIc.mjs";
|
|
3
|
+
import { A as AgentSchemaPack, B as AgentWorkflowStateConfig, C as initialAgentStep, D as AgentMachine, E as transitionAgentStep, F as AgentWorkflowActionConfig, G as messagesSchema, H as FromConfigOptions, I as AgentWorkflowActorConfig, L as AgentWorkflowConfig, M as AgentStateNarrowing, N as createAgentSchemas, O as AgentMachineConfig, P as setupAgent, R as AgentWorkflowInvokeConfig, S as getAgentRequests, T as resolveAgentStep, U as SchemaCompiler, V as AgentWorkflowTransitionConfig, W as appendMessages, _ as AgentRequest, a as AgentUserInputExecutor, b as ResolveAgentRequestsOptions, c as PendingUserInput, d as SnapshotVersionMismatchError, f as inspectTransitions, g as AgentPlanRequest, h as AgentStateRequest, i as AgentTraceEvent, j as AgentSetupStateSchema, k as AgentRequestConfig, l as RunAgentOptions, m as runAgentToCompletion, n as AgentMessageInfo, o as IllegalResumeEventError, p as runAgent, r as AgentRunMeta, s as InspectedActorRef, t as AgentIdleError, u as RunAgentResult, v as AgentStep, w as resolveAgentRequests, x as executeAgentRequest, y as AgentStepRequest, z as AgentWorkflowRequestConfig } from "./run-agent-DzYJb3CK.mjs";
|
|
4
|
+
import { a as getMachineStructuralHash, c as persistSnapshot, d as userMessage, f as validateSchemaSync, i as getJsonSchemaSync, l as systemMessage, n as getAgentMessages, o as getStateMeta, r as getJsonSchema, s as isStandardSchema, t as assistantMessage, u as toolMessage } from "./utils-Y6GDRGGE.mjs";
|
|
5
|
+
import { AnyMachineSnapshot, AnyStateMachine } from "xstate";
|
|
5
6
|
|
|
6
|
-
//#region src/messages.d.ts
|
|
7
|
-
/**
|
|
8
|
-
* Builds a transition-function result that appends one or more
|
|
9
|
-
* {@link AgentMessage}s to a context's `messages` array. `resolve` is either
|
|
10
|
-
* a message (or array of messages) or a function of `{ context, event }`
|
|
11
|
-
* returning them; the returned function is meant to be used directly as (or
|
|
12
|
-
* composed into) a transition's result, e.g. `on: { USER_REPLIED:
|
|
13
|
-
* agent.appendMessages(({ event }) => userMessage(event.text)) }`. Requires
|
|
14
|
-
* `messages: AgentMessage[]` on context — see {@link messagesSchema} for a
|
|
15
|
-
* ready-made schema for that field.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* on: {
|
|
20
|
-
* USER_REPLIED: appendMessages(({ event }) => userMessage(event.text)),
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
declare function appendMessages<TContext extends {
|
|
25
|
-
messages: AgentMessage[];
|
|
26
|
-
}, TEvent extends EventObject>(resolve: AgentMessage | AgentMessage[] | ((args: {
|
|
27
|
-
context: TContext;
|
|
28
|
-
event: TEvent;
|
|
29
|
-
}) => AgentMessage | AgentMessage[])): (args: {
|
|
30
|
-
context: TContext;
|
|
31
|
-
event: TEvent;
|
|
32
|
-
}) => {
|
|
33
|
-
context: {
|
|
34
|
-
messages: AgentMessage[];
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* A {@link StandardSchemaV1} validating an `AgentMessage[]` context field —
|
|
39
|
-
* checks that every message has a known `role` (`system`/`user`/`assistant`/
|
|
40
|
-
* `tool`) and that `content` is either a string (where the role allows it) or
|
|
41
|
-
* an array of parts with a known `type`. Use it directly as a context
|
|
42
|
-
* schema's `messages` field when authoring with `createAgentSchemas`.
|
|
43
|
-
*/
|
|
44
|
-
declare const messagesSchema: StandardSchemaV1<AgentMessage[]>;
|
|
45
|
-
//#endregion
|
|
46
|
-
//#region src/workflow-config.d.ts
|
|
47
|
-
type JsonSchemaObject = {
|
|
48
|
-
type?: string | string[];
|
|
49
|
-
properties?: Record<string, JsonSchemaObject>;
|
|
50
|
-
required?: string[];
|
|
51
|
-
items?: JsonSchemaObject;
|
|
52
|
-
enum?: unknown[];
|
|
53
|
-
const?: unknown;
|
|
54
|
-
additionalProperties?: unknown;
|
|
55
|
-
[key: string]: unknown;
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Compiles a JSON Schema object (from an `AgentWorkflowConfig`) into a
|
|
59
|
-
* runtime `StandardSchemaV1` validator. `setupAgent.fromConfig(...)` calls
|
|
60
|
-
* this once per schema in the config (context/events/input/output/meta,
|
|
61
|
-
* request input/output) — bring your own engine (Ajv, @cfworker/json-schema,
|
|
62
|
-
* a compiled-Zod-from-JSON-Schema pipeline, ...). Core intentionally ships no
|
|
63
|
-
* JSON Schema engine.
|
|
64
|
-
*/
|
|
65
|
-
type SchemaCompiler = (jsonSchema: Record<string, unknown>, name: string) => StandardSchemaV1;
|
|
66
|
-
/**
|
|
67
|
-
* Serializable JSON/YAML machine definition — the config a database, visual
|
|
68
|
-
* editor, or LLM could produce and hand to `setupAgent.fromConfig(config, {
|
|
69
|
-
* compileSchema })` to get back the same kind of `AnyStateMachine`
|
|
70
|
-
* TypeScript `setupAgent(...)` authoring would build. JS/TS authoring should
|
|
71
|
-
* use `setupAgent(...)` directly instead of this JSON form. Any `unknown`-
|
|
72
|
-
* typed field here (`model`, `guard`, action `params`, …) accepts either a
|
|
73
|
-
* literal JSON value or a `"{{ path.to.value }}"` template-expression string
|
|
74
|
-
* resolved against `{ context, event, input, output }` at machine-build/
|
|
75
|
-
* transition time — see the sibling `evaluateWorkflowConfigValue` lowering.
|
|
76
|
-
*/
|
|
77
|
-
interface AgentWorkflowConfig {
|
|
78
|
-
key?: string;
|
|
79
|
-
id?: string;
|
|
80
|
-
version?: string;
|
|
81
|
-
description?: string;
|
|
82
|
-
schemas?: {
|
|
83
|
-
input?: JsonSchemaObject;
|
|
84
|
-
context?: JsonSchemaObject;
|
|
85
|
-
events?: Record<string, JsonSchemaObject>;
|
|
86
|
-
emitted?: Record<string, JsonSchemaObject>;
|
|
87
|
-
output?: JsonSchemaObject;
|
|
88
|
-
meta?: JsonSchemaObject;
|
|
89
|
-
};
|
|
90
|
-
context?: Record<string, unknown>;
|
|
91
|
-
requests?: Record<string, AgentWorkflowRequestConfig>;
|
|
92
|
-
actors?: Record<string, AgentWorkflowActorConfig>;
|
|
93
|
-
initial: string;
|
|
94
|
-
states: Record<string, AgentWorkflowStateConfig>;
|
|
95
|
-
meta?: Record<string, unknown>;
|
|
96
|
-
}
|
|
97
|
-
/** A `requests` entry in {@link AgentWorkflowConfig} — the JSON equivalent of a `setupAgent({ requests })` `TextLogicConfig`. Fields beyond `input`/`output`/`tools`/`mode`/`description` are `unknown` because they accept template-expression strings (see {@link AgentWorkflowConfig}). */
|
|
98
|
-
interface AgentWorkflowRequestConfig {
|
|
99
|
-
mode?: AgentRequestMode;
|
|
100
|
-
description?: string;
|
|
101
|
-
model: unknown;
|
|
102
|
-
system?: unknown;
|
|
103
|
-
prompt?: unknown;
|
|
104
|
-
messages?: unknown;
|
|
105
|
-
input: JsonSchemaObject;
|
|
106
|
-
output: JsonSchemaObject;
|
|
107
|
-
tools?: AgentTools;
|
|
108
|
-
toolChoice?: AgentToolChoice | unknown;
|
|
109
|
-
/** Opt into the structured-output envelope's `reasoning` field (see `AgentTextRequest.reasoning`). */
|
|
110
|
-
reasoning?: boolean;
|
|
111
|
-
temperature?: unknown;
|
|
112
|
-
maxOutputTokens?: unknown;
|
|
113
|
-
topP?: unknown;
|
|
114
|
-
topK?: unknown;
|
|
115
|
-
seed?: unknown;
|
|
116
|
-
stopSequences?: unknown;
|
|
117
|
-
metadata?: unknown;
|
|
118
|
-
}
|
|
119
|
-
/** An `actors` entry in {@link AgentWorkflowConfig} — declares a placeholder actor source (by key) with no host execution wired from JSON; provide it via `machine.provide({ actorSources })` after `setupAgent.fromConfig(...)`. */
|
|
120
|
-
interface AgentWorkflowActorConfig {
|
|
121
|
-
input?: JsonSchemaObject;
|
|
122
|
-
output?: JsonSchemaObject;
|
|
123
|
-
description?: string;
|
|
124
|
-
}
|
|
125
|
-
/** A `states` entry in {@link AgentWorkflowConfig} — the JSON equivalent of an XState state node config. */
|
|
126
|
-
interface AgentWorkflowStateConfig {
|
|
127
|
-
description?: string;
|
|
128
|
-
type?: "parallel" | "history" | "final" | "choice";
|
|
129
|
-
initial?: string;
|
|
130
|
-
states?: Record<string, AgentWorkflowStateConfig>;
|
|
131
|
-
choice?: AgentWorkflowTransitionConfig | AgentWorkflowTransitionConfig[];
|
|
132
|
-
invoke?: AgentWorkflowInvokeConfig | AgentWorkflowInvokeConfig[];
|
|
133
|
-
on?: Record<string, AgentWorkflowTransitionConfig | AgentWorkflowTransitionConfig[]>;
|
|
134
|
-
always?: AgentWorkflowTransitionConfig | AgentWorkflowTransitionConfig[];
|
|
135
|
-
onDone?: AgentWorkflowTransitionConfig | AgentWorkflowTransitionConfig[];
|
|
136
|
-
after?: Record<string, AgentWorkflowTransitionConfig | AgentWorkflowTransitionConfig[]>;
|
|
137
|
-
entry?: AgentWorkflowActionConfig | AgentWorkflowActionConfig[];
|
|
138
|
-
exit?: AgentWorkflowActionConfig | AgentWorkflowActionConfig[];
|
|
139
|
-
tags?: string[];
|
|
140
|
-
output?: unknown;
|
|
141
|
-
meta?: Record<string, unknown>;
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* An `invoke` entry in {@link AgentWorkflowStateConfig}. For `src:
|
|
145
|
-
* 'agent.decide'`, the chosen event is delivered automatically — its
|
|
146
|
-
* transition usually exits the state and ends the invoke, so an `onDone` is
|
|
147
|
-
* rarely needed; declare one only to observe a chosen event whose transition
|
|
148
|
-
* stays in-state. `onError` handles retries-exhausted.
|
|
149
|
-
*/
|
|
150
|
-
interface AgentWorkflowInvokeConfig {
|
|
151
|
-
id?: string;
|
|
152
|
-
src: string;
|
|
153
|
-
input?: unknown;
|
|
154
|
-
onDone?: AgentWorkflowTransitionConfig | AgentWorkflowTransitionConfig[];
|
|
155
|
-
onError?: AgentWorkflowTransitionConfig | AgentWorkflowTransitionConfig[];
|
|
156
|
-
meta?: Record<string, unknown>;
|
|
157
|
-
}
|
|
158
|
-
/** A transition target in {@link AgentWorkflowConfig} (`on`/`always`/`onDone`/`after`/invoke `onDone`/`onError`) — the JSON equivalent of an XState transition config. `guard`, when a string, is a template expression evaluated as truthy/falsy. */
|
|
159
|
-
interface AgentWorkflowTransitionConfig {
|
|
160
|
-
target?: string | string[];
|
|
161
|
-
guard?: unknown;
|
|
162
|
-
assign?: Record<string, unknown>;
|
|
163
|
-
actions?: AgentWorkflowActionConfig | AgentWorkflowActionConfig[];
|
|
164
|
-
description?: string;
|
|
165
|
-
reenter?: boolean;
|
|
166
|
-
meta?: Record<string, unknown>;
|
|
167
|
-
}
|
|
168
|
-
/** An `entry`/`exit`/transition `actions` entry in {@link AgentWorkflowConfig} — either a named action `type` (with template-expression `params`) or a bare context `assign`. */
|
|
169
|
-
interface AgentWorkflowActionConfig {
|
|
170
|
-
type?: string;
|
|
171
|
-
params?: unknown;
|
|
172
|
-
assign?: Record<string, unknown>;
|
|
173
|
-
emit?: unknown;
|
|
174
|
-
[key: string]: unknown;
|
|
175
|
-
}
|
|
176
|
-
/** Options for `setupAgent.fromConfig(...)`. */
|
|
177
|
-
interface FromConfigOptions {
|
|
178
|
-
/**
|
|
179
|
-
* Compile a JSON Schema from the config into a runtime validator. Bring
|
|
180
|
-
* your own engine (Ajv, @cfworker/json-schema, a compiled-Zod-from-JSON-Schema
|
|
181
|
-
* pipeline, ...). Core intentionally ships no JSON Schema engine.
|
|
182
|
-
*/
|
|
183
|
-
compileSchema: SchemaCompiler;
|
|
184
|
-
}
|
|
185
|
-
//#endregion
|
|
186
|
-
//#region src/setup-agent.d.ts
|
|
187
|
-
type Constrain<T, TConstraint> = T extends TConstraint ? T : TConstraint;
|
|
188
|
-
type ContextOf<TContextSchema extends StandardSchemaV1> = Constrain<InferOutput<TContextSchema>, MachineContext>;
|
|
189
|
-
type EventsOf<TEventSchemas extends Record<string, StandardSchemaV1>> = Constrain<EventUnion<TEventSchemas>, EventObject>;
|
|
190
|
-
type SetupActors<TActors extends { [K in keyof TActors]: AnyActorLogic }> = { [K in keyof TActors]: TActors[K] extends AsyncActorLogic<infer TOutput, infer TInput> ? AsyncActorLogic<TOutput, TInput> : TActors[K] };
|
|
191
|
-
type AgentSetupActors<TActors extends { [K in keyof TActors]: AnyActorLogic }, TEvent extends string = string, TModel extends string = string> = TActors & BuiltinAgentActors<TEvent, TModel>;
|
|
192
|
-
/**
|
|
193
|
-
* A machine's full schema set — context, event payloads, machine input/
|
|
194
|
-
* output, and state/transition meta — as returned by {@link createAgentSchemas}
|
|
195
|
-
* and retained on `setupAgent(...)`'s `result.schemas` for runtime
|
|
196
|
-
* validation (e.g. by the step path to validate `initialAgentStep` input, or
|
|
197
|
-
* by `getAcceptedEvents` to attach event payload schemas). Unlike
|
|
198
|
-
* `AgentSchemaConfig` (the input to `createAgentSchemas`), every field here
|
|
199
|
-
* is required — `events`/`input`/`output`/`meta` default to empty/unknown
|
|
200
|
-
* schemas when not supplied.
|
|
201
|
-
*/
|
|
202
|
-
interface AgentSchemaPack<TContextSchema extends StandardSchemaV1<Record<string, unknown>> = StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1 = StandardSchemaV1<NonReducibleUnknown>, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1<NonReducibleUnknown>, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1<MetaObject>, TEmittedSchemas extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>> {
|
|
203
|
-
context: TContextSchema;
|
|
204
|
-
events: TEventSchemas;
|
|
205
|
-
input: TInputSchema;
|
|
206
|
-
output: TOutputSchema;
|
|
207
|
-
meta: TMetaSchema;
|
|
208
|
-
/** Schemas for events the machine emits (`enq.emit(...)`), keyed by event type — they type `enq.emit` in the machine and the `on` handlers of {@link runAgent}. Optional: omitted means emitted events stay untyped. */
|
|
209
|
-
emitted?: TEmittedSchemas;
|
|
210
|
-
}
|
|
211
|
-
type AgentSchemaConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends Record<string, StandardSchemaV1>, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TEmittedSchemas extends Record<string, StandardSchemaV1> = Record<string, StandardSchemaV1>> = {
|
|
212
|
-
context: TContextSchema;
|
|
213
|
-
events?: TEventSchemas;
|
|
214
|
-
input?: TInputSchema;
|
|
215
|
-
output?: TOutputSchema;
|
|
216
|
-
meta?: TMetaSchema;
|
|
217
|
-
emitted?: TEmittedSchemas;
|
|
218
|
-
};
|
|
219
|
-
/**
|
|
220
|
-
* Builds a machine's {@link AgentSchemaPack} from a partial schema
|
|
221
|
-
* declaration — only `context` is required; `events`/`input`/`output`/`meta`
|
|
222
|
-
* default to empty/unknown schemas when omitted. Pass the result as
|
|
223
|
-
* `setupAgent({ schemas })`'s `schemas` (or spread the individual fields
|
|
224
|
-
* directly into `setupAgent({ context, events, ... })` — both forms are
|
|
225
|
-
* accepted).
|
|
226
|
-
*/
|
|
227
|
-
declare function createAgentSchemas<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends Record<string, StandardSchemaV1> = {}, TInputSchema extends StandardSchemaV1 = StandardSchemaV1<NonReducibleUnknown>, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1<NonReducibleUnknown>, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1<MetaObject>, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}>(schemas: AgentSchemaConfig<TContextSchema, TEventSchemas, TInputSchema, TOutputSchema, TMetaSchema, TEmittedSchemas>): AgentSchemaPack<TContextSchema, TEventSchemas, TInputSchema, TOutputSchema, TMetaSchema, TEmittedSchemas>;
|
|
228
|
-
type AgentRequestConfig<TInputSchema extends StandardSchemaV1 = StandardSchemaV1, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1, TMetadata = Record<string, unknown>, TModel extends string = string> = TextLogicConfig<TInputSchema, TOutputSchema, TMetadata, TModel> & {
|
|
229
|
-
mode?: AgentRequestMode;
|
|
230
|
-
};
|
|
231
|
-
type AgentRequestSchemaMap = Record<string, {
|
|
232
|
-
input: StandardSchemaV1;
|
|
233
|
-
output: StandardSchemaV1;
|
|
234
|
-
}>;
|
|
235
|
-
type AgentRequestInput<TRequestSchemas extends AgentRequestSchemaMap, TModel extends string = string> = { [K in keyof TRequestSchemas]: AgentRequestConfig<TRequestSchemas[K]["input"], TRequestSchemas[K]["output"], Record<string, unknown>, TModel> & {
|
|
236
|
-
schemas: TRequestSchemas[K];
|
|
237
|
-
} };
|
|
238
|
-
type RequestActors<TRequestSchemas extends AgentRequestSchemaMap> = { [K in keyof TRequestSchemas]: TextLogic<TRequestSchemas[K]["input"], TRequestSchemas[K]["output"]> };
|
|
239
|
-
type AgentAllActors<TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap> = TActors & RequestActors<TRequestSchemas>;
|
|
240
|
-
type AgentSetupEventsSchema<TEventSchemas extends Record<string, StandardSchemaV1>> = [keyof TEventSchemas] extends [never] ? {} : {
|
|
241
|
-
events: TEventSchemas;
|
|
242
|
-
};
|
|
243
|
-
type AgentSetupEmittedSchema<TEmittedSchemas extends Record<string, StandardSchemaV1>> = [keyof TEmittedSchemas] extends [never] ? {} : {
|
|
244
|
-
emitted: TEmittedSchemas;
|
|
245
|
-
};
|
|
246
|
-
type AgentSetupXStateConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends Record<string, StandardSchemaV1>, TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, SetupStateSchema> = Record<string, SetupStateSchema>> = {
|
|
247
|
-
schemas: {
|
|
248
|
-
context: TContextSchema;
|
|
249
|
-
input: TInputSchema;
|
|
250
|
-
output: TOutputSchema;
|
|
251
|
-
meta: TMetaSchema;
|
|
252
|
-
} & AgentSetupEventsSchema<TEventSchemas> & AgentSetupEmittedSchema<TEmittedSchemas>;
|
|
253
|
-
states?: TStateSchemas;
|
|
254
|
-
actorSources: SetupActors<AgentSetupActors<AgentAllActors<TActors, TRequestSchemas>, keyof TEventSchemas & string, AgentModelRef<TModels>>>;
|
|
255
|
-
actions?: NonNullable<AnySetupConfig["actions"]>;
|
|
256
|
-
guards?: NonNullable<AnySetupConfig["guards"]>;
|
|
257
|
-
delays?: NonNullable<AnySetupConfig["delays"]>;
|
|
258
|
-
};
|
|
259
|
-
/**
|
|
260
|
-
* Field-level context-narrowing sugar for one `setupAgent({ states })` entry:
|
|
261
|
-
* each `context` entry overrides that field's schema inside the state; every
|
|
262
|
-
* other field keeps the base context schema. Sugar for the full xstate form —
|
|
263
|
-
* `{ context: { draft: z.string() } }` resolves to
|
|
264
|
-
* `{ schemas: { context: <base with draft: string> } }` — so only the fields
|
|
265
|
-
* that change are declared, not the whole context schema.
|
|
266
|
-
*/
|
|
267
|
-
interface AgentStateNarrowing {
|
|
268
|
-
context: Record<string, StandardSchemaV1>;
|
|
269
|
-
states?: Record<string, AgentSetupStateSchema>;
|
|
270
|
-
}
|
|
271
|
-
/** One `setupAgent({ states })` entry: xstate's {@link SetupStateSchema} full form, or the {@link AgentStateNarrowing} field-level sugar. */
|
|
272
|
-
type AgentSetupStateSchema = SetupStateSchema | AgentStateNarrowing;
|
|
273
|
-
type NarrowedContext<TContextSchema extends StandardSchemaV1, TFields extends Record<string, StandardSchemaV1>> = Omit<InferOutput<TContextSchema>, keyof TFields> & { [K in keyof TFields]: InferOutput<TFields[K]> };
|
|
274
|
-
type ResolveAgentStateSchema<TContextSchema extends StandardSchemaV1, T> = T extends {
|
|
275
|
-
context: infer TFields extends Record<string, StandardSchemaV1>;
|
|
276
|
-
} ? {
|
|
277
|
-
schemas: {
|
|
278
|
-
context: StandardSchemaV1<NarrowedContext<TContextSchema, TFields>>;
|
|
279
|
-
};
|
|
280
|
-
} & (T extends {
|
|
281
|
-
states: infer TChildren extends Record<string, AgentSetupStateSchema>;
|
|
282
|
-
} ? {
|
|
283
|
-
states: ResolveAgentStateSchemas<TContextSchema, TChildren>;
|
|
284
|
-
} : {}) : T extends {
|
|
285
|
-
states: infer TChildren extends Record<string, AgentSetupStateSchema>;
|
|
286
|
-
} ? Omit<T, "states"> & {
|
|
287
|
-
states: ResolveAgentStateSchemas<TContextSchema, TChildren>;
|
|
288
|
-
} : T;
|
|
289
|
-
type ResolveAgentStateSchemas<TContextSchema extends StandardSchemaV1, TStates extends Record<string, AgentSetupStateSchema>> = Constrain<{ [K in keyof TStates]: ResolveAgentStateSchema<TContextSchema, TStates[K]> }, Record<string, SetupStateSchema>>;
|
|
290
|
-
type SetupAgentBaseConfig<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends Record<string, StandardSchemaV1>, TActors extends { [K in keyof TActors]: AnyActorLogic }, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TRequestSchemas extends AgentRequestSchemaMap, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, AgentSetupStateSchema> = Record<string, AgentSetupStateSchema>> = ({
|
|
291
|
-
schemas: AgentSchemaPack<TContextSchema, TEventSchemas, TInputSchema, TOutputSchema, TMetaSchema, TEmittedSchemas>;
|
|
292
|
-
} | AgentSchemaConfig<TContextSchema, TEventSchemas, TInputSchema, TOutputSchema, TMetaSchema, TEmittedSchemas>) & {
|
|
293
|
-
models?: TModels;
|
|
294
|
-
actorSources?: TActors;
|
|
295
|
-
/**
|
|
296
|
-
* Per-state schemas, mirroring xstate's `setup({ states })`: narrow
|
|
297
|
-
* `context` inside a state (invoke `input`, transition fns, final `output`)
|
|
298
|
-
* — e.g. mark a field non-null in states only reachable after it is set.
|
|
299
|
-
* Two forms per state: the {@link AgentStateNarrowing} sugar
|
|
300
|
-
* (`{ context: { draft: z.string() } }` — only the fields that change) or
|
|
301
|
-
* xstate's full `{ schemas: { context } }` with a complete context schema.
|
|
302
|
-
*/
|
|
303
|
-
states?: TStateSchemas;
|
|
304
|
-
requests?: AgentRequestInput<TRequestSchemas, AgentModelRef<TModels>>;
|
|
305
|
-
actions?: NonNullable<AnySetupConfig["actions"]>;
|
|
306
|
-
guards?: NonNullable<AnySetupConfig["guards"]>;
|
|
307
|
-
delays?: NonNullable<AnySetupConfig["delays"]>;
|
|
308
|
-
/**
|
|
309
|
-
* Detects a snapshot that is an INTENTIONAL wait for an external event (a
|
|
310
|
-
* human approval, an inbound webhook, …) — the machine's own declaration of
|
|
311
|
-
* what "suspended" means for it, so `runAgent` settles those snapshots idle
|
|
312
|
-
* deterministically instead of using its timing heuristic. Travels with the
|
|
313
|
-
* machine through `machine.provide(...)`. A `runAgent({ isSuspended })` host
|
|
314
|
-
* override takes precedence; with neither, `runAgent` falls back to the timing
|
|
315
|
-
* heuristic. Declare your own signal — e.g. `(s) => s.hasTag('awaiting-review')`
|
|
316
|
-
* or `(s) => getStateMeta(s).interaction !== undefined`.
|
|
317
|
-
*/
|
|
318
|
-
isSuspended?: (snapshot: AnyMachineSnapshot) => boolean;
|
|
319
|
-
};
|
|
320
|
-
type SetupAgentXStateResult<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends Record<string, StandardSchemaV1>, TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, AgentSetupStateSchema> = Record<string, AgentSetupStateSchema>> = SetupReturnFromConfig<AgentSetupXStateConfig<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, ResolveAgentStateSchemas<TContextSchema, TStateSchemas>>>;
|
|
321
|
-
/**
|
|
322
|
-
* The object returned by {@link setupAgent}: an xstate `setup(...)` result
|
|
323
|
-
* (`createMachine`, `assign`, …) extended with `schemas` (the resolved
|
|
324
|
-
* {@link AgentSchemaPack}), `models`, `requests` (the built request actors),
|
|
325
|
-
* and {@link appendMessages}. Machines created here are registered so
|
|
326
|
-
* `runAgent` and the free step helpers can resolve their schemas/actors
|
|
327
|
-
* without re-passing them each call.
|
|
328
|
-
*/
|
|
329
|
-
type SetupAgentResult<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends Record<string, StandardSchemaV1>, TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap, TInputSchema extends StandardSchemaV1, TOutputSchema extends StandardSchemaV1, TMetaSchema extends StandardSchemaV1, TModels extends AgentModelMap, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, TStateSchemas extends Record<string, AgentSetupStateSchema> = Record<string, AgentSetupStateSchema>> = Omit<SetupAgentXStateResult<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas>, "createMachine"> & {
|
|
330
|
-
/**
|
|
331
|
-
* Creates the agent machine — XState's own `createMachine`, plus: the
|
|
332
|
-
* machine is registered so step helpers and {@link runAgent} can resolve
|
|
333
|
-
* its schemas/actors without re-passing them, and a single final state's
|
|
334
|
-
* `output` is copied to the machine root when the root declares none.
|
|
335
|
-
*/
|
|
336
|
-
createMachine: SetupAgentXStateResult<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas>["createMachine"]; /** The retained schema pack ({@link AgentSchemaPack}) for host-side validation and tooling. */
|
|
337
|
-
schemas: AgentSchemaPack<TContextSchema, TEventSchemas, TInputSchema, TOutputSchema, TMetaSchema, TEmittedSchemas>; /** The `models` registry passed to `setupAgent(...)`, if any (used to type-narrow `AgentModelRef`). */
|
|
338
|
-
readonly models: TModels; /** The {@link TextLogic} actors built from `setupAgent({ requests })`, keyed the same way. */
|
|
339
|
-
readonly requests: RequestActors<TRequestSchemas>; /** {@link appendMessages}, typed against this agent's context/event schemas. */
|
|
340
|
-
appendMessages(resolve: AgentMessage | AgentMessage[] | ((args: {
|
|
341
|
-
context: ContextOf<TContextSchema> & {
|
|
342
|
-
messages: AgentMessage[];
|
|
343
|
-
};
|
|
344
|
-
event: any;
|
|
345
|
-
}) => AgentMessage | AgentMessage[])): ReturnType<typeof appendMessages<ContextOf<TContextSchema> & {
|
|
346
|
-
messages: AgentMessage[];
|
|
347
|
-
}, EventsOf<TEventSchemas>>>;
|
|
348
|
-
};
|
|
349
|
-
/**
|
|
350
|
-
* Schema-first `setup(...)` for agent machines — the standard entry point
|
|
351
|
-
* for authoring a machine (the blueprint) that this library then runs (via
|
|
352
|
-
* {@link runAgent} or the step helpers) against host-supplied model/decision
|
|
353
|
-
* executors. Context, events, machine input, machine output, and
|
|
354
|
-
* state/transition meta are all standard schemas — no `{} as Type` casts —
|
|
355
|
-
* and are retained on `result.schemas` for runtime validation. Also
|
|
356
|
-
* registers the `agent.generateText`/`agent.streamText`/`agent.userInput`/
|
|
357
|
-
* `agent.decide` builtin actors and lowers `requests`/`actorSources` into the
|
|
358
|
-
* machine's actor sources. The result is the xstate `setup(...)` object with
|
|
359
|
-
* a wrapped `result.createMachine(...)` plus `result.schemas`/`models`/
|
|
360
|
-
* `requests`/`appendMessages` attached. Also has a
|
|
361
|
-
* `setupAgent.fromConfig(...)` namespace member for building a machine from
|
|
362
|
-
* a serializable {@link AgentWorkflowConfig} instead of this TS API.
|
|
363
|
-
*
|
|
364
|
-
* @example
|
|
365
|
-
* ```ts
|
|
366
|
-
* const schemas = createAgentSchemas({
|
|
367
|
-
* context: z.object({ topic: z.string(), joke: z.string().nullable() }),
|
|
368
|
-
* input: z.object({ topic: z.string() }),
|
|
369
|
-
* output: z.object({ joke: z.string() }),
|
|
370
|
-
* });
|
|
371
|
-
*
|
|
372
|
-
* const agent = setupAgent({
|
|
373
|
-
* schemas,
|
|
374
|
-
* actorSources: { tellJoke },
|
|
375
|
-
* });
|
|
376
|
-
*
|
|
377
|
-
* const jokeMachine = agent.createMachine({
|
|
378
|
-
* context: ({ input }) => ({ topic: input.topic, joke: null }),
|
|
379
|
-
* initial: 'telling',
|
|
380
|
-
* states: {
|
|
381
|
-
* telling: {
|
|
382
|
-
* invoke: {
|
|
383
|
-
* id: 'joke',
|
|
384
|
-
* src: 'tellJoke',
|
|
385
|
-
* input: ({ context }) => ({ topic: context.topic }),
|
|
386
|
-
* onDone: ({ output }) => ({ target: 'done', context: { joke: output } }),
|
|
387
|
-
* },
|
|
388
|
-
* },
|
|
389
|
-
* done: { type: 'final', output: ({ context }) => ({ joke: context.joke ?? '' }) },
|
|
390
|
-
* },
|
|
391
|
-
* });
|
|
392
|
-
* ```
|
|
393
|
-
*/
|
|
394
|
-
declare function setupAgent<TContextSchema extends StandardSchemaV1<Record<string, unknown>>, TEventSchemas extends Record<string, StandardSchemaV1>, TActors extends { [K in keyof TActors]: AnyActorLogic }, TRequestSchemas extends AgentRequestSchemaMap = {}, TInputSchema extends StandardSchemaV1 = StandardSchemaV1<NonReducibleUnknown>, TOutputSchema extends StandardSchemaV1 = StandardSchemaV1<NonReducibleUnknown>, TMetaSchema extends StandardSchemaV1 = StandardSchemaV1<MetaObject>, TModels extends AgentModelMap = {}, TEmittedSchemas extends Record<string, StandardSchemaV1> = {}, const TStateSchemas extends Record<string, AgentSetupStateSchema> = Record<string, AgentSetupStateSchema>>(config: SetupAgentBaseConfig<TContextSchema, TEventSchemas, TActors, TInputSchema, TOutputSchema, TMetaSchema, TRequestSchemas, TModels, TEmittedSchemas, TStateSchemas>): SetupAgentResult<TContextSchema, TEventSchemas, TActors, TRequestSchemas, TInputSchema, TOutputSchema, TMetaSchema, TModels, TEmittedSchemas, TStateSchemas>;
|
|
395
|
-
declare namespace setupAgent {
|
|
396
|
-
/**
|
|
397
|
-
* Builds a state machine from a serializable {@link AgentWorkflowConfig}
|
|
398
|
-
* (JSON/YAML) instead of the TypeScript `setupAgent(...)` API — the same
|
|
399
|
-
* kind of machine a database, visual editor, or LLM could produce and hand
|
|
400
|
-
* back. Requires a `compileSchema` (see {@link FromConfigOptions}) since
|
|
401
|
-
* the library bundles no JSON Schema engine itself; bring Ajv,
|
|
402
|
-
* @cfworker/json-schema, or another compiler that returns Standard Schema.
|
|
403
|
-
*
|
|
404
|
-
* @example
|
|
405
|
-
* ```ts
|
|
406
|
-
* const machine = setupAgent.fromConfig(workflowConfig, {
|
|
407
|
-
* compileSchema,
|
|
408
|
-
* });
|
|
409
|
-
* const result = await runAgent(machine, { input: { ticket }, executors: { generateText, decide } });
|
|
410
|
-
* ```
|
|
411
|
-
*/
|
|
412
|
-
function fromConfig(config: AgentWorkflowConfig, options: FromConfigOptions): AnyStateMachine;
|
|
413
|
-
}
|
|
414
|
-
//#endregion
|
|
415
|
-
//#region src/internal/registry.d.ts
|
|
416
|
-
type AgentExecutionOptions = Pick<AgentRequestOptions, "schemas" | "actorSources">;
|
|
417
|
-
//#endregion
|
|
418
|
-
//#region src/steps.d.ts
|
|
419
|
-
/**
|
|
420
|
-
* A pending text request surfaced by step discovery ({@link getAgentRequests}
|
|
421
|
-
* / {@link AgentStep.requests}): the machine has spawned a
|
|
422
|
-
* `TextLogic`-backed invoke and is waiting on its result. Resolve it with
|
|
423
|
-
* {@link executeAgentRequest} (or by hand, then feed the output into
|
|
424
|
-
* {@link resolveAgentStep} via `xstate.done.actor.<id>`).
|
|
425
|
-
*/
|
|
426
|
-
interface AgentRequest<TInput extends AgentTextRequest = AgentTextRequest> {
|
|
427
|
-
kind: "text";
|
|
428
|
-
id: string;
|
|
429
|
-
src: AgentRequestSource;
|
|
430
|
-
mode?: AgentRequestMode;
|
|
431
|
-
input: TInput;
|
|
432
|
-
tools: AgentTools;
|
|
433
|
-
events: AgentEventDescriptor[];
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* A pending **plan** request re-surfaced by step discovery: the machine
|
|
437
|
-
* invoked `agent.plan`, which applies an ordered sequence of legal events
|
|
438
|
-
* (each one a decision) rather than a single one. Unlike text/decision
|
|
439
|
-
* requests — surfaced once and resolved once — a plan request **re-surfaces on
|
|
440
|
-
* every step** while the plan is in flight, its `events`/`applied`/
|
|
441
|
-
* `stepsRemaining` updated each time, until it terminates.
|
|
442
|
-
*
|
|
443
|
-
* All fields are plain serializable data. Resolve ONE decision per step from
|
|
444
|
-
* `events` (via {@link resolveDecision}, wiring `canTake` to
|
|
445
|
-
* `snapshot.can` exactly like a single decision) then apply it: a real machine
|
|
446
|
-
* event advances the plan (the next step re-surfaces this request); the
|
|
447
|
-
* reserved `agent.plan.done` move, a `stopOn` event, an exhausted budget, or no
|
|
448
|
-
* legal events completes it (its invoke resolves with `{ steps, stopped }`).
|
|
449
|
-
* {@link resolveAgentRequests} does all of this natively — one decision (or one
|
|
450
|
-
* completion) per call.
|
|
451
|
-
*
|
|
452
|
-
* The in-progress plan state (`applied` trail + remaining budget) lives in the
|
|
453
|
-
* plan invoke child's own `createLogic` snapshot `context`
|
|
454
|
-
* (`children.<id>.snapshot.context`), so it survives a full JSON
|
|
455
|
-
* `getPersistedSnapshot` → restore round-trip: a host that persists the step
|
|
456
|
-
* after every event and reloads resumes the plan identically.
|
|
457
|
-
*/
|
|
458
|
-
interface AgentPlanRequest {
|
|
459
|
-
kind: "plan";
|
|
460
|
-
/** Durable invoke id of the `agent.plan` invoke. */
|
|
461
|
-
id: string;
|
|
462
|
-
/** Invoke src (`'agent.plan'` or a registered plan-logic source name). */
|
|
463
|
-
src: AgentRequestSource;
|
|
464
|
-
/** The resolved plan input (`model`/`system`/`prompt`/`allowedEvents`/`stopOn`/`maxSteps`/…). */
|
|
465
|
-
input: AgentPlanInput;
|
|
466
|
-
/**
|
|
467
|
-
* The legal candidates for the NEXT plan step: the currently
|
|
468
|
-
* snapshot-legal machine events (∩ declared `allowedEvents`) plus the
|
|
469
|
-
* reserved `agent.plan.done` move.
|
|
470
|
-
*/
|
|
471
|
-
events: AgentEventDescriptor[];
|
|
472
|
-
/** The events applied so far in this plan, in order (the trail). */
|
|
473
|
-
applied: ChosenEvent[];
|
|
474
|
-
/** How many more events the plan may apply (`maxSteps - applied.length`). */
|
|
475
|
-
stepsRemaining: number;
|
|
476
|
-
}
|
|
477
|
-
/** `AgentStep.requests` element: a text, decision, or plan request. */
|
|
478
|
-
type AgentStepRequest = AgentRequest | AgentDecisionRequest | AgentPlanRequest;
|
|
479
|
-
/**
|
|
480
|
-
* One durable checkpoint on the step path: the machine's current snapshot,
|
|
481
|
-
* the executable actions that produced it, the pending
|
|
482
|
-
* {@link AgentStepRequest}s (text/decision work still to resolve), and
|
|
483
|
-
* whether the machine has reached a final state. This is the
|
|
484
|
-
* per-model-call-checkpoint path for durable hosts (Workflows, Temporal,
|
|
485
|
-
* queues, …) — a peer of `runAgent`, not a lesser version of it. Produced by
|
|
486
|
-
* {@link initialAgentStep}/{@link transitionAgentStep}/{@link resolveAgentStep}.
|
|
487
|
-
*/
|
|
488
|
-
interface AgentStep<TSnapshot extends AnyMachineSnapshot = AnyMachineSnapshot> {
|
|
489
|
-
snapshot: TSnapshot;
|
|
490
|
-
actions: readonly {
|
|
491
|
-
type?: string;
|
|
492
|
-
params?: unknown;
|
|
493
|
-
}[];
|
|
494
|
-
requests: AgentStepRequest[];
|
|
495
|
-
done: boolean;
|
|
496
|
-
}
|
|
497
|
-
/**
|
|
498
|
-
* Starts a machine and returns its first {@link AgentStep} — the step-path
|
|
499
|
-
* equivalent of `initialTransition` plus request discovery. Begins the
|
|
500
|
-
* durable/per-model-call-checkpoint loop: resolve each `step.requests` entry
|
|
501
|
-
* (via {@link executeAgentRequest} for `kind: 'text'`, or
|
|
502
|
-
* {@link resolveDecision} for `kind: 'decision'`), then advance with
|
|
503
|
-
* {@link resolveAgentStep} or {@link transitionAgentStep}.
|
|
504
|
-
*/
|
|
505
|
-
declare function initialAgentStep<TMachine extends AnyActorLogic>(machine: TMachine, input?: unknown, options?: Partial<AgentExecutionOptions>): AgentStep<SnapshotFrom<TMachine>>;
|
|
506
|
-
/**
|
|
507
|
-
* Applies an externally-sent event (e.g. a decision's chosen event, or a
|
|
508
|
-
* human's reply) and returns the next {@link AgentStep}. Accepts **either**
|
|
509
|
-
* a raw snapshot **or** a prior `AgentStep` as the second argument —
|
|
510
|
-
* `.snapshot` is unwrapped automatically, so callers can thread the whole
|
|
511
|
-
* step object through without manually plucking the snapshot out.
|
|
512
|
-
*/
|
|
513
|
-
declare function transitionAgentStep<TMachine extends AnyActorLogic>(machine: TMachine, snapshotOrStep: SnapshotFrom<TMachine> | AgentStep<SnapshotFrom<TMachine>>, event: EventFromLogic<TMachine>, options?: Partial<AgentExecutionOptions>): AgentStep<SnapshotFrom<TMachine>>;
|
|
514
|
-
/**
|
|
515
|
-
* Applies a resolved text request's output (a `kind: 'text'`
|
|
516
|
-
* {@link AgentRequest} — not a decision) as a done event and returns the
|
|
517
|
-
* next {@link AgentStep}. For decisions, resolve with `resolveDecision`
|
|
518
|
-
* (which returns a {@link ChosenEvent}) and apply it with
|
|
519
|
-
* {@link transitionAgentStep} instead — a decision has no output value of
|
|
520
|
-
* its own to feed here.
|
|
521
|
-
*/
|
|
522
|
-
declare function resolveAgentStep<TMachine extends AnyActorLogic>(machine: TMachine, step: AgentStep<SnapshotFrom<TMachine>>, request: Pick<AgentRequest, "id"> | string, output: unknown, options?: Partial<AgentExecutionOptions>): AgentStep<SnapshotFrom<TMachine>>;
|
|
523
|
-
/**
|
|
524
|
-
* Snapshot in, requests out: scans executable actions for spawned agent
|
|
525
|
-
* invokes and lowers each into an {@link AgentStepRequest}, pre-filled with
|
|
526
|
-
* the machine's registered `setupAgent` schemas/actorSources (so callers
|
|
527
|
-
* don't pass them by hand each call) — merged with any `options` passed here,
|
|
528
|
-
* which take precedence. The step path's public discovery primitive;
|
|
529
|
-
* `initialAgentStep`/`transitionAgentStep`/`resolveAgentStep` call it
|
|
530
|
-
* internally to populate `AgentStep.requests`.
|
|
531
|
-
*/
|
|
532
|
-
declare function getAgentRequests(machine: AnyActorLogic, actions: readonly {
|
|
533
|
-
type?: string;
|
|
534
|
-
params?: unknown;
|
|
535
|
-
}[], snapshot?: AnyMachineSnapshot, options?: Pick<AgentRequestOptions, "eventToolName"> & Partial<AgentExecutionOptions>): AgentStepRequest[];
|
|
536
|
-
/**
|
|
537
|
-
* Resolves one **text** {@link AgentRequest} against a host's
|
|
538
|
-
* {@link AgentRequestExecutors} — merges the request's tools, dispatches to
|
|
539
|
-
* `generateText`/`streamText` per `request.mode`, and validates the result
|
|
540
|
-
* against `request.input.outputSchema` if present. **Text-only**: passing a
|
|
541
|
-
* `kind: 'decision'` request throws, directing the caller to
|
|
542
|
-
* `resolveDecision(request, executors.decide, ...)` instead. By default
|
|
543
|
-
* returns the normalized output; pass `{ verbose: true }` to also get the
|
|
544
|
-
* raw executor result (tool calls, usage, finish reason — needed for
|
|
545
|
-
* observability and event-sourced replay).
|
|
546
|
-
*/
|
|
547
|
-
declare function executeAgentRequest(request: AgentRequest, executors: Partial<AgentRequestExecutors>): Promise<unknown>;
|
|
548
|
-
declare function executeAgentRequest(request: AgentRequest, executors: Partial<AgentRequestExecutors>, options: {
|
|
549
|
-
verbose: true;
|
|
550
|
-
}): Promise<{
|
|
551
|
-
output: unknown;
|
|
552
|
-
raw: unknown;
|
|
553
|
-
}>;
|
|
554
|
-
/**
|
|
555
|
-
* Options for {@link resolveAgentRequests}.
|
|
556
|
-
*/
|
|
557
|
-
interface ResolveAgentRequestsOptions extends Partial<AgentExecutionOptions> {
|
|
558
|
-
/** Retries per decision, passed to `resolveDecision`. Default `2`. */
|
|
559
|
-
maxRetries?: number;
|
|
560
|
-
}
|
|
561
|
-
/**
|
|
562
|
-
* Resolves the current step's pending requests and returns the next
|
|
563
|
-
* {@link AgentStep} — one iteration of the durable step loop, collapsing the
|
|
564
|
-
* manual `request.kind` dispatch a host would otherwise write by hand.
|
|
565
|
-
*
|
|
566
|
-
* For each pending request, in order: a `kind: 'text'` request is run with
|
|
567
|
-
* {@link executeAgentRequest} then fed back via {@link resolveAgentStep}; a
|
|
568
|
-
* `kind: 'decision'` request is resolved with `resolveDecision` (wiring
|
|
569
|
-
* `canTake` to `step.snapshot.can` so guard-rejected choices retry) then
|
|
570
|
-
* applied with {@link transitionAgentStep}. The **current** step is re-read
|
|
571
|
-
* after each application — the machine may advance and its `requests` change —
|
|
572
|
-
* so this always resolves against the live step, never a stale list.
|
|
573
|
-
*
|
|
574
|
-
* A `kind: 'plan'` request (`agent.plan`) is resolved natively too: one plan
|
|
575
|
-
* step per call. It resolves a single decision from `request.events` (wiring
|
|
576
|
-
* `canTake` to `step.snapshot.can`, exempting the reserved `agent.plan.done`
|
|
577
|
-
* move and `stopOn` events), then either applies the chosen machine event and
|
|
578
|
-
* lets the next step re-surface the plan, or completes the plan (feeding its
|
|
579
|
-
* `{ steps, stopped }` output back) on the done move / a `stopOn` event / an
|
|
580
|
-
* exhausted budget / no legal events. The plan's applied trail is carried in
|
|
581
|
-
* the invoke child's snapshot, so persisting the step between calls resumes the
|
|
582
|
-
* plan identically.
|
|
583
|
-
*
|
|
584
|
-
* Missing the executor a request needs throws a clear error
|
|
585
|
-
* (`generateText`/`streamText` for text, `decide` for decisions and plans).
|
|
586
|
-
*
|
|
587
|
-
* A complete durable host is two lines:
|
|
588
|
-
*
|
|
589
|
-
* ```ts
|
|
590
|
-
* let step = initialAgentStep(machine, input);
|
|
591
|
-
* while (!step.done) step = await resolveAgentRequests(machine, step, executors);
|
|
592
|
-
* ```
|
|
593
|
-
*
|
|
594
|
-
* All pending **text** requests of a step are resolved in parallel
|
|
595
|
-
* (`Promise.all`) — parallel statechart regions are genuinely concurrent, so
|
|
596
|
-
* their model calls run concurrently — then their outputs apply in
|
|
597
|
-
* **request-array order** (deterministic for durable replay regardless of which
|
|
598
|
-
* call finishes first). Decisions and plans stay **one at a time**: applying
|
|
599
|
-
* either changes the set of legal candidates for what follows, so they cannot be
|
|
600
|
-
* resolved against a stale snapshot. A host that instead wants strictly
|
|
601
|
-
* sequential text resolution loops the manual per-request helpers
|
|
602
|
-
* ({@link executeAgentRequest} + {@link resolveAgentStep}) one at a time.
|
|
603
|
-
*/
|
|
604
|
-
declare function resolveAgentRequests<TMachine extends AnyActorLogic>(machine: TMachine, step: AgentStep<SnapshotFrom<TMachine>>, executors: Partial<AgentRequestExecutors>, options?: ResolveAgentRequestsOptions): Promise<AgentStep<SnapshotFrom<TMachine>>>;
|
|
605
|
-
//#endregion
|
|
606
|
-
//#region src/internal/state-request-pass.d.ts
|
|
607
|
-
/**
|
|
608
|
-
* One model request read off the machine's CURRENT snapshot by a
|
|
609
|
-
* `RunAgentOptions.getRequests` hook. `model` is an executor model NAME — the
|
|
610
|
-
* same string every {@link AgentTextRequest.model} carries, resolved by the
|
|
611
|
-
* run's executors (e.g. a `defineModels` key when using
|
|
612
|
-
* `createAiSdkExecutors`) — never a model instance.
|
|
613
|
-
*/
|
|
614
|
-
interface AgentStateRequest {
|
|
615
|
-
/** Instruction for this request's model call, appended to the run's message log as a user message. */
|
|
616
|
-
prompt: string;
|
|
617
|
-
/** System prompt for this request's model call(s). */
|
|
618
|
-
system?: string;
|
|
619
|
-
/** Executor model name (resolved by the run's executors). */
|
|
620
|
-
model: string;
|
|
621
|
-
/**
|
|
622
|
-
* `'text'` (default): a `generateText` call with the message log +
|
|
623
|
-
* `prompt`; the reply is appended to the log, then the machine is advanced
|
|
624
|
-
* per {@link AgentStateRequest.onDone}. `'decision'`: no text call — a
|
|
625
|
-
* single `decide` call (log + `prompt`) chooses the event. Use for pure
|
|
626
|
-
* routing states.
|
|
627
|
-
*/
|
|
628
|
-
kind?: "text" | "decision";
|
|
629
|
-
/**
|
|
630
|
-
* What to send when this request's text call resolves — the EXPLICIT
|
|
631
|
-
* advancement contract, always an event OBJECT (the same shape
|
|
632
|
-
* `actor.send` takes; no string shorthand). A literal event sends exactly
|
|
633
|
-
* that; a function receives the text output (plus the live snapshot and
|
|
634
|
-
* message log) and returns the event to send — payload included — or
|
|
635
|
-
* `undefined` to send nothing. Omitted: a `decide` call chooses among the
|
|
636
|
-
* candidate events (requires a `decide` executor) — there is no implicit
|
|
637
|
-
* auto-send. A resolved event whose type the state does not accept throws
|
|
638
|
-
* (programmer error); one a guard rejects is simply not sent. Ignored for
|
|
639
|
-
* `kind: 'decision'` (the decide call IS the advancement).
|
|
640
|
-
*/
|
|
641
|
-
onDone?: ChosenEvent | ((args: {
|
|
642
|
-
output: unknown;
|
|
643
|
-
snapshot: AnyMachineSnapshot;
|
|
644
|
-
messages: readonly AgentMessage[];
|
|
645
|
-
}) => ChosenEvent | undefined);
|
|
646
|
-
/** Restricts this request's candidate outcome events for the `decide` fallback (default: every currently-accepted event). */
|
|
647
|
-
allowedEvents?: readonly string[];
|
|
648
|
-
/** Trace/request id; defaults to `interpret_<n>`. */
|
|
649
|
-
id?: string;
|
|
650
|
-
}
|
|
651
|
-
//#endregion
|
|
652
|
-
//#region src/run-agent.d.ts
|
|
653
|
-
/**
|
|
654
|
-
* Thrown by {@link runAgent} when resuming with a `snapshot` + `event` whose
|
|
655
|
-
* `type` the restored state cannot accept (a type-level check via
|
|
656
|
-
* {@link getAcceptedEvents}). A programmer/integration error, in the same
|
|
657
|
-
* class as runAgent's bind-time throws — it throws rather than settling an
|
|
658
|
-
* `error` result. A type-legal event a guard rejects is NOT this error (the
|
|
659
|
-
* machine simply takes no transition). Opt out with
|
|
660
|
-
* {@link RunAgentOptions.onIllegalResumeEvent} `'ignore'`.
|
|
661
|
-
*/
|
|
662
|
-
declare class IllegalResumeEventError extends Error {
|
|
663
|
-
readonly eventType: string;
|
|
664
|
-
readonly acceptedTypes: string[];
|
|
665
|
-
constructor(eventType: string, acceptedTypes: string[]);
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Thrown by {@link runAgent} when resuming from a `snapshot` whose stamped
|
|
669
|
-
* `agentMeta.version` differs from the current machine's version, under the
|
|
670
|
-
* default `onVersionMismatch: 'throw'` and with no `migrateSnapshot` hook. The
|
|
671
|
-
* structural fingerprint of the machine changed since the snapshot was
|
|
672
|
-
* persisted (a state/transition/invoke was added, removed, or retargeted), so
|
|
673
|
-
* the snapshot may no longer resume cleanly. `from` is the snapshot's version,
|
|
674
|
-
* `to` the current machine's.
|
|
675
|
-
*/
|
|
676
|
-
declare class SnapshotVersionMismatchError extends Error {
|
|
677
|
-
readonly from: string;
|
|
678
|
-
readonly to: string;
|
|
679
|
-
readonly machineId: string;
|
|
680
|
-
constructor(from: string, to: string, machineId: string);
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* Thrown by {@link runAgentToCompletion} when the run settles `idle` instead of
|
|
684
|
-
* `done`: the machine paused for external input. Carries the idle `snapshot`
|
|
685
|
-
* and `acceptedTypes` (the event types that could resume it, via
|
|
686
|
-
* {@link getAcceptedEvents}). Use {@link runAgent} directly when idle is an
|
|
687
|
-
* expected outcome you handle.
|
|
688
|
-
*/
|
|
689
|
-
declare class AgentIdleError extends Error {
|
|
690
|
-
readonly snapshot: AnyMachineSnapshot;
|
|
691
|
-
readonly acceptedTypes: string[];
|
|
692
|
-
constructor(snapshot: AnyMachineSnapshot, acceptedTypes: string[]);
|
|
693
|
-
}
|
|
694
|
-
/** Handler for `agent.userInput` invokes passed as {@link RunAgentOptions.userInput}. Resolves to what the human typed. */
|
|
695
|
-
interface AgentUserInputExecutor {
|
|
696
|
-
(input: AgentUserInput): PromiseLike<string>;
|
|
697
|
-
}
|
|
698
|
-
type AgentTraceEvent<TMachine extends AnyStateMachine = AnyStateMachine> = {
|
|
699
|
-
runId: string;
|
|
700
|
-
seq: number;
|
|
701
|
-
timestamp: string;
|
|
702
|
-
} & ({
|
|
703
|
-
type: "run.start";
|
|
704
|
-
input?: InputFrom<TMachine>;
|
|
705
|
-
snapshot?: Snapshot<unknown>;
|
|
706
|
-
event?: EventFromLogic<TMachine>;
|
|
707
|
-
} | {
|
|
708
|
-
type: "request.start";
|
|
709
|
-
request: AgentStepRequest;
|
|
710
|
-
} | {
|
|
711
|
-
type: "request.end";
|
|
712
|
-
request: AgentStepRequest;
|
|
713
|
-
output: unknown;
|
|
714
|
-
raw: unknown;
|
|
715
|
-
/** The model's reasoning, lifted off the raw executor result when the
|
|
716
|
-
* request opted into the structured-output envelope's `reasoning` field.
|
|
717
|
-
* Present only when the executor surfaced a string `reasoning`. */
|
|
718
|
-
reasoning?: string;
|
|
719
|
-
} | {
|
|
720
|
-
type: "request.error";
|
|
721
|
-
request: AgentStepRequest;
|
|
722
|
-
error: unknown;
|
|
723
|
-
} | {
|
|
724
|
-
type: "stream.chunk";
|
|
725
|
-
request: AgentRequest;
|
|
726
|
-
chunk: string;
|
|
727
|
-
} | {
|
|
728
|
-
type: "machine.transition";
|
|
729
|
-
snapshot: SnapshotFrom<TMachine>;
|
|
730
|
-
event: EventFromLogic<TMachine>;
|
|
731
|
-
} | {
|
|
732
|
-
type: "emit";
|
|
733
|
-
event: EmittedFrom<TMachine>;
|
|
734
|
-
} | ({
|
|
735
|
-
type: "run.end";
|
|
736
|
-
status: "done";
|
|
737
|
-
output: OutputFrom<TMachine>;
|
|
738
|
-
snapshot: SnapshotFrom<TMachine>;
|
|
739
|
-
} | {
|
|
740
|
-
type: "run.end";
|
|
741
|
-
status: "idle";
|
|
742
|
-
snapshot: SnapshotFrom<TMachine>;
|
|
743
|
-
pendingUserInputs?: PendingUserInput[];
|
|
744
|
-
persistedSnapshot?: Snapshot<unknown>;
|
|
745
|
-
} | {
|
|
746
|
-
type: "run.end";
|
|
747
|
-
status: "error";
|
|
748
|
-
cause: RunAgentErrorCause;
|
|
749
|
-
error: unknown;
|
|
750
|
-
snapshot: SnapshotFrom<TMachine>;
|
|
751
|
-
}));
|
|
752
|
-
/**
|
|
753
|
-
* Options for {@link runAgent}.
|
|
754
|
-
*
|
|
755
|
-
* Host executors are passed as a single {@link AgentRequestExecutors}-shaped
|
|
756
|
-
* set under `executors` (the same shape the step path takes). Each executor
|
|
757
|
-
* kind is required only if the machine actually reaches a request of that kind
|
|
758
|
-
* — checked at bind time, before any actor runs. The whole `executors` field is
|
|
759
|
-
* optional: a machine whose agent sources all carry their own executor
|
|
760
|
-
* (`.withExecutor(...)`) needs none.
|
|
761
|
-
*/
|
|
762
|
-
interface RunAgentOptions<TMachine extends AnyStateMachine> {
|
|
763
|
-
/**
|
|
764
|
-
* The host executor set backing the machine's agent actors — build it with
|
|
765
|
-
* `createAiSdkExecutors({ models })` from '@statelyai/agent/ai-sdk', or supply
|
|
766
|
-
* `{ generateText?, streamText?, decide? }` by hand. Every slot is optional
|
|
767
|
-
* here (unlike the step path's {@link AgentRequestExecutors}): each kind is
|
|
768
|
-
* bind-time-checked only when the machine actually reaches a request of that
|
|
769
|
-
* kind, so e.g. a stream-only machine may pass `{ streamText }` alone.
|
|
770
|
-
*/
|
|
771
|
-
executors?: Partial<AgentRequestExecutors>;
|
|
772
|
-
/** Machine input, passed straight to `createActor(machine, { input })`. Omit when resuming via `snapshot`. */
|
|
773
|
-
input?: InputFrom<TMachine>;
|
|
774
|
-
/** A previously-settled run's `result.snapshot`, to resume from instead of starting fresh. Pair with `event` to deliver the event that unblocks the resumed idle state. */
|
|
775
|
-
snapshot?: Snapshot<unknown>;
|
|
776
|
-
/** An event to send immediately after starting/resuming the actor (e.g. the human's answer to an idle-state prompt). */
|
|
777
|
-
event?: EventFromLogic<TMachine>;
|
|
778
|
-
/**
|
|
779
|
-
* How to handle a resume `event` the restored state cannot accept (a
|
|
780
|
-
* type-level check via {@link getAcceptedEvents}, only applied when resuming
|
|
781
|
-
* from a `snapshot`). `'throw'` (default) throws {@link IllegalResumeEventError}
|
|
782
|
-
* before delivering the event; `'ignore'` restores the older silent behavior
|
|
783
|
-
* (the event is sent and the machine drops it). A type-legal event a guard
|
|
784
|
-
* rejects is never an illegal resume event.
|
|
785
|
-
*/
|
|
786
|
-
onIllegalResumeEvent?: "throw" | "ignore";
|
|
787
|
-
/**
|
|
788
|
-
* The version stamped onto every settled snapshot's `agentMeta` and compared
|
|
789
|
-
* against an incoming snapshot's stamp on resume. Defaults to
|
|
790
|
-
* {@link getMachineStructuralHash} of the machine (a structural fingerprint).
|
|
791
|
-
* Set an explicit value (e.g. a semver or build id) to control migration
|
|
792
|
-
* boundaries yourself.
|
|
793
|
-
*/
|
|
794
|
-
machineVersion?: string;
|
|
795
|
-
/**
|
|
796
|
-
* How to handle a resume `snapshot` whose stamped `agentMeta.version` differs
|
|
797
|
-
* from the current machine's version. `'throw'` (default) throws
|
|
798
|
-
* {@link SnapshotVersionMismatchError} with `from`/`to`; `'warn'`
|
|
799
|
-
* `console.warn`s once and proceeds; `'ignore'` proceeds silently. Ignored
|
|
800
|
-
* when {@link migrateSnapshot} is provided (that runs instead), and never
|
|
801
|
-
* triggers for an unstamped snapshot (no `agentMeta`).
|
|
802
|
-
*/
|
|
803
|
-
onVersionMismatch?: "throw" | "warn" | "ignore";
|
|
804
|
-
/**
|
|
805
|
-
* Called instead of {@link onVersionMismatch} when a resume snapshot's
|
|
806
|
-
* version mismatches the current machine's: receives the incoming snapshot
|
|
807
|
-
* and `{ from, to }`, and its return value is used as the snapshot to resume
|
|
808
|
-
* from. A throw propagates.
|
|
809
|
-
*/
|
|
810
|
-
migrateSnapshot?: (snapshot: Snapshot<unknown>, info: {
|
|
811
|
-
from: string;
|
|
812
|
-
to: string;
|
|
813
|
-
}) => Snapshot<unknown>;
|
|
814
|
-
/** Actor source implementations, merged onto the machine before binding — sugar for `machine.provide({ actorSources })` ahead of the run. */
|
|
815
|
-
actorSources?: Record<string, AnyActorLogic>;
|
|
816
|
-
/**
|
|
817
|
-
* Optional human-input handler for `agent.userInput` invokes (CLI prompt,
|
|
818
|
-
* web form, Slack, …). With a handler, input is gathered inline without
|
|
819
|
-
* settling. Without one, an `agent.userInput` invoke becomes a *pending
|
|
820
|
-
* placeholder*: it waits indefinitely, does not block idle detection, and
|
|
821
|
-
* the run settles `{ status: 'idle', pendingUserInputs, persistedSnapshot }`
|
|
822
|
-
* once no other work is in flight — resume by passing `persistedSnapshot`
|
|
823
|
-
* back as `snapshot` together with a `userInput` handler that answers it.
|
|
824
|
-
*/
|
|
825
|
-
userInput?: AgentUserInputExecutor;
|
|
826
|
-
/**
|
|
827
|
-
* Host override for detecting a snapshot that is an INTENTIONAL wait for an
|
|
828
|
-
* external event — the deterministic replacement for the timing heuristic
|
|
829
|
-
* runAgent uses to settle idle. Resolution order: this option (host override)
|
|
830
|
-
* → the machine-carried predicate declared via `setupAgent({ isSuspended })`
|
|
831
|
-
* → the timing heuristic (when neither is present). When the resolved
|
|
832
|
-
* predicate returns true and nothing is in flight (no live requests/plans/
|
|
833
|
-
* invokes; the `agent.userInput` placeholder exemption still applies), runAgent
|
|
834
|
-
* settles idle immediately, without the `setTimeout` heuristic. It does NOT
|
|
835
|
-
* force-settle while agent work is in flight, and whole-machine idle semantics
|
|
836
|
-
* are unchanged; a machine with no predicate falls back to the heuristic
|
|
837
|
-
* exactly as before. Declare your own signal, e.g.
|
|
838
|
-
* `(s) => s.hasTag('awaiting-review')`.
|
|
839
|
-
*
|
|
840
|
-
* Provisional name — may change before 2.0.
|
|
841
|
-
*/
|
|
842
|
-
isSuspended?: (snapshot: AnyMachineSnapshot) => boolean;
|
|
843
|
-
/**
|
|
844
|
-
* The override to runAgent's DEFAULT contract. By default agent work is
|
|
845
|
-
* whatever the machine *invokes* (`agent.generateText`, TextLogic,
|
|
846
|
-
* `agent.decide`, …). With `getRequests`, whenever the machine would
|
|
847
|
-
* otherwise settle idle, this hook reads the snapshot and returns the model
|
|
848
|
-
* request(s) to run instead — prompts from state `description`s, `meta`,
|
|
849
|
-
* tags, a lookup table keyed by state value, wherever you keep them. Return
|
|
850
|
-
* nothing to settle idle (human-wait states).
|
|
851
|
-
*
|
|
852
|
-
* There is no blessed source for the prompts — this is a recipe seam.
|
|
853
|
-
* Prompts-in-descriptions, copy-paste and adapt:
|
|
854
|
-
*
|
|
855
|
-
* ```ts
|
|
856
|
-
* getRequests: (snapshot) =>
|
|
857
|
-
* snapshot._nodes
|
|
858
|
-
* .filter((node) => node.description && !node.tags.includes('waiting'))
|
|
859
|
-
* .map((node) => ({
|
|
860
|
-
* model: 'writer',
|
|
861
|
-
* prompt: node.description!,
|
|
862
|
-
* kind: node.tags.includes('decision') ? 'decision' : 'text',
|
|
863
|
-
* // single-outcome states advance deterministically; else `decide`
|
|
864
|
-
* onDone: node.ownEvents.length === 1 ? { type: node.ownEvents[0] } : undefined,
|
|
865
|
-
* allowedEvents: node.ownEvents,
|
|
866
|
-
* })),
|
|
867
|
-
* ```
|
|
868
|
-
*
|
|
869
|
-
* Each request runs per {@link AgentStateRequest.kind}, appends to the
|
|
870
|
-
* run's message log (see {@link RunAgentOptions.messages}), and advances
|
|
871
|
-
* the machine per {@link AgentStateRequest.onDone} — explicitly named/
|
|
872
|
-
* computed event, or a `decide` call when omitted — always gated by
|
|
873
|
-
* `snapshot.can`. Multiple requests run concurrently (parallel regions —
|
|
874
|
-
* scope each with `allowedEvents`, e.g. the node's `ownEvents`). A pass
|
|
875
|
-
* that sends no event settles idle. Every model call counts against
|
|
876
|
-
* `maxModelCalls`.
|
|
877
|
-
*/
|
|
878
|
-
getRequests?: (snapshot: SnapshotFrom<TMachine>, agentContext: {
|
|
879
|
-
messages: readonly AgentMessage[];
|
|
880
|
-
}) => AgentStateRequest | readonly AgentStateRequest[] | undefined;
|
|
881
|
-
/**
|
|
882
|
-
* Adds to the run's aggregated message log (the working memory
|
|
883
|
-
* `getRequests` requests read and append to). The log starts as the resume
|
|
884
|
-
* `snapshot`'s stamped `messages` (else `[]`); an ARRAY here is APPENDED to
|
|
885
|
-
* that history — the safe default for folding in a user reply on resume,
|
|
886
|
-
* never silently erasing prior conversation. Pass a FUNCTION
|
|
887
|
-
* `(prior) => AgentMessage[]` to take full control (replace, filter,
|
|
888
|
-
* compact). The final log is stamped onto every settled result's
|
|
889
|
-
* `snapshot.messages` (like `agentMeta`), so persist/resume round-trips it
|
|
890
|
-
* with no extra wiring — read it with `getAgentMessages(snapshot)`.
|
|
891
|
-
*/
|
|
892
|
-
messages?: AgentMessage[] | ((prior: AgentMessage[]) => AgentMessage[]);
|
|
893
|
-
/** Fires for each streamed chunk of a `mode: 'stream'` text request, alongside the {@link AgentRequest} that produced it (parallel states can interleave multiple streams). Purely observational. */
|
|
894
|
-
onChunk?: (chunk: string, info: {
|
|
895
|
-
request: AgentRequest;
|
|
896
|
-
}) => void;
|
|
897
|
-
/** Fires once per resolved text/decision request with its normalized output and the raw executor result (tool calls, usage, …) — the seam for tracing/observability and event-sourced replay logging. */
|
|
898
|
-
onResult?: (request: AgentStepRequest, result: {
|
|
899
|
-
output: unknown;
|
|
900
|
-
raw: unknown;
|
|
901
|
-
}) => void;
|
|
902
|
-
/** Fires a single ordered stream of run/request/chunk/transition/emit/end events. Intended for eval traces, JSONL logs, and adapter-owned telemetry/exporters. */
|
|
903
|
-
onTrace?: (event: AgentTraceEvent<TMachine>) => void;
|
|
904
|
-
/**
|
|
905
|
-
* Fires on every machine transition (snapshot + causing event). Pure
|
|
906
|
-
* observation — progress UIs, logging, tracing. Cannot send events.
|
|
907
|
-
*/
|
|
908
|
-
onTransition?: (snapshot: SnapshotFrom<TMachine>, event: EventFromLogic<TMachine>) => void;
|
|
909
|
-
/**
|
|
910
|
-
* Fires for each message appended to the run's aggregated log (see
|
|
911
|
-
* {@link RunAgentOptions.messages}) the moment a `getRequests` request
|
|
912
|
-
* appends it — the live view of the log a caller otherwise only reads off
|
|
913
|
-
* the settled snapshot via `getAgentMessages`. Purely observational, like
|
|
914
|
-
* {@link onTransition}. Never fires for the seeded history, and never fires
|
|
915
|
-
* on a default invoke-driven run (nothing appends there).
|
|
916
|
-
*/
|
|
917
|
-
onMessage?: (message: AgentMessage) => void;
|
|
918
|
-
/**
|
|
919
|
-
* Handlers for events the machine emits (`enq.emit(...)`), keyed by emitted
|
|
920
|
-
* event type — `'*'` catches all. Typed from the machine's `emitted`
|
|
921
|
-
* schemas (`setupAgent({ emitted: { ... } })`). Purely observational, like
|
|
922
|
-
* {@link onTransition}: the machine narrates progress on its own vocabulary
|
|
923
|
-
* (not xstate internals) and the host renders it — a progress UI, an SSE
|
|
924
|
-
* stream, a log line.
|
|
925
|
-
*/
|
|
926
|
-
on?: { [TType in EmittedFrom<TMachine>["type"] | "*"]?: (emitted: EmittedFrom<TMachine> & (TType extends "*" ? unknown : {
|
|
927
|
-
type: TType;
|
|
928
|
-
})) => void };
|
|
929
|
-
/**
|
|
930
|
-
* Raw xstate inspection passthrough: fires for every inspection event in
|
|
931
|
-
* the whole actor system — root machine, invoked child machines, spawned
|
|
932
|
-
* actors — each carrying its `actorRef` (`event.actorRef.id`/`.src`). This
|
|
933
|
-
* is the system-wide seam {@link onTransition} (root transitions only)
|
|
934
|
-
* cannot give you: filter `event.type === '@xstate.transition'` and read
|
|
935
|
-
* `event.actorRef` to attribute a child machine's states to the child.
|
|
936
|
-
* Purely observational, like the other callbacks. Unlike them it also
|
|
937
|
-
* fires during the final settle (a child's last transition and stop events
|
|
938
|
-
* arrive while the run is tearing down).
|
|
939
|
-
*/
|
|
940
|
-
inspect?: (inspectionEvent: InspectionEvent) => void;
|
|
941
|
-
/** Caps the number of model/decision calls this run may make (each retry of a decision counts separately); exceeding it settles `{ status: 'error', cause: 'max-model-calls' }`. Default 100. */
|
|
942
|
-
maxModelCalls?: number;
|
|
943
|
-
/** Aborts the run; settles `{ status: 'error', cause: 'aborted' }` with `signal.reason` as the error. */
|
|
944
|
-
signal?: AbortSignal;
|
|
945
|
-
}
|
|
946
|
-
/**
|
|
947
|
-
* The outcome of a {@link runAgent} call — always exactly one of three
|
|
948
|
-
* variants, never a throw for a waiting or failed machine (programmer
|
|
949
|
-
* errors like a missing executor still throw, at bind time before any actor
|
|
950
|
-
* runs). `done`: a final state was reached (`output` is the machine's
|
|
951
|
-
* `OutputFrom`). `idle`: the run settled with no in-flight work — resume by
|
|
952
|
-
* calling `runAgent` again with `{ snapshot, event }`. `error`: a run-level
|
|
953
|
-
* failure, discriminated by `cause` (`'aborted'`, `'max-model-calls'`,
|
|
954
|
-
* `'decision-exhausted'`, `'machine'` for any other machine error state, or
|
|
955
|
-
* `'stopped'` for an external stop — see {@link RunAgentErrorCause}). Every
|
|
956
|
-
* variant carries the final `snapshot`, and the underlying
|
|
957
|
-
* actor is stopped on every settle path — there is no live actor to resume;
|
|
958
|
-
* resume is always by snapshot.
|
|
959
|
-
*/
|
|
960
|
-
/** A pending unhandled `agent.userInput` invoke surfaced on an idle settle — `id` is the invoke's id, `input` its resolved invoke input (prompt, metadata). Answer it by resuming with a `userInput` handler. */
|
|
961
|
-
interface PendingUserInput {
|
|
962
|
-
id: string;
|
|
963
|
-
input: AgentUserInput | undefined;
|
|
964
|
-
}
|
|
965
|
-
type RunAgentResult<TMachine extends AnyStateMachine> = {
|
|
966
|
-
status: "done";
|
|
967
|
-
output: OutputFrom<TMachine>;
|
|
968
|
-
snapshot: SnapshotFrom<TMachine>;
|
|
969
|
-
} | {
|
|
970
|
-
status: "idle";
|
|
971
|
-
snapshot: SnapshotFrom<TMachine>; /** Present when the machine is waiting on unhandled `agent.userInput` invokes: one entry per pending invoke. */
|
|
972
|
-
pendingUserInputs?: PendingUserInput[];
|
|
973
|
-
/**
|
|
974
|
-
* Present alongside `pendingUserInputs`: the JSON-serializable persisted
|
|
975
|
-
* snapshot (in-flight children included). Persist THIS one and resume
|
|
976
|
-
* with `runAgent(machine, { snapshot: persistedSnapshot, userInput })` —
|
|
977
|
-
* the live `snapshot` above cannot round-trip active children.
|
|
978
|
-
*/
|
|
979
|
-
persistedSnapshot?: Snapshot<unknown>;
|
|
980
|
-
} | {
|
|
981
|
-
status: "error";
|
|
982
|
-
cause: RunAgentErrorCause;
|
|
983
|
-
error: unknown;
|
|
984
|
-
snapshot: SnapshotFrom<TMachine>;
|
|
985
|
-
};
|
|
986
|
-
/**
|
|
987
|
-
* Discriminates a {@link RunAgentResult} `error`:
|
|
988
|
-
* - `'aborted'` — the run's `signal` fired.
|
|
989
|
-
* - `'max-model-calls'` — the `maxModelCalls` budget was exceeded.
|
|
990
|
-
* - `'decision-exhausted'` — the machine reached an error state whose error is
|
|
991
|
-
* (or wraps) a {@link DecisionExhaustedError} that no `onError` handled.
|
|
992
|
-
* - `'machine'` — any other machine error state.
|
|
993
|
-
* - `'stopped'` — the actor was stopped externally (`status === 'stopped'`).
|
|
994
|
-
*/
|
|
995
|
-
type RunAgentErrorCause = "aborted" | "max-model-calls" | "decision-exhausted" | "machine" | "stopped";
|
|
996
|
-
/**
|
|
997
|
-
* Runs an agent machine to completion or idle: a `createActor` host that
|
|
998
|
-
* binds `options`' host executors onto the machine's `agent.*`/`TextLogic`/
|
|
999
|
-
* `DecisionLogic` actor sources, starts (or resumes) the actor, and drives
|
|
1000
|
-
* it until it settles — {@link RunAgentResult} `done | idle | error`. Unlike
|
|
1001
|
-
* the step helpers ({@link initialAgentStep} etc — a pure
|
|
1002
|
-
* transition-at-a-time path for durable hosts), `runAgent` owns a live actor
|
|
1003
|
-
* internally; there is no continuation callback, so **idle always settles**
|
|
1004
|
-
* and the caller resumes explicitly by passing the settled `{ snapshot,
|
|
1005
|
-
* event }` back in. The actor is stopped on every settle path (`done`,
|
|
1006
|
-
* `idle`, and `error` alike) — resume is always by snapshot, never by
|
|
1007
|
-
* holding a reference to a live actor.
|
|
1008
|
-
*
|
|
1009
|
-
* Binding happens **before** the actor starts: every invoke the machine
|
|
1010
|
-
* could reach is walked and checked against the effective actor sources
|
|
1011
|
-
* (`options.actorSources` merged onto the machine), so a missing
|
|
1012
|
-
* `streamText`/`decide` executor or any other unbound actor source throws
|
|
1013
|
-
* immediately — a bind-time error, not a mid-run failure. The one exception
|
|
1014
|
-
* is `agent.userInput`: unhandled, it binds as a pending placeholder that
|
|
1015
|
-
* settles the run idle (with `pendingUserInputs`) instead of erroring.
|
|
1016
|
-
*
|
|
1017
|
-
* @example
|
|
1018
|
-
* ```ts
|
|
1019
|
-
* const executors = createAiSdkExecutors({ models });
|
|
1020
|
-
* let r = await runAgent(machine, { input, executors });
|
|
1021
|
-
* while (r.status === 'idle') {
|
|
1022
|
-
* const event = await promptUser(getAcceptedEvents(r.snapshot));
|
|
1023
|
-
* r = await runAgent(machine, { snapshot: r.snapshot, event, executors });
|
|
1024
|
-
* }
|
|
1025
|
-
* if (r.status !== 'done') throw new Error(`Run did not complete: ${r.status}`);
|
|
1026
|
-
* console.log(r.output);
|
|
1027
|
-
* ```
|
|
1028
|
-
*
|
|
1029
|
-
* The `executors`' `generateText`/`streamText` accept the raw Vercel AI SDK
|
|
1030
|
-
* functions directly (`executors: { generateText, streamText }` with them
|
|
1031
|
-
* imported from `ai`) — their `{ text }`/`{ textStream }` results are unwrapped
|
|
1032
|
-
* natively. `decide` cannot be a raw AI SDK function: the tool-per-event mapping
|
|
1033
|
-
* lives in an adapter — use `createAiSdkExecutors` from '@statelyai/agent/ai-sdk'.
|
|
1034
|
-
*/
|
|
1035
|
-
declare function runAgent<TMachine extends AnyStateMachine>(machine: TMachine, options: RunAgentOptions<TMachine>): Promise<RunAgentResult<TMachine>>;
|
|
1036
|
-
/**
|
|
1037
|
-
* Runs an agent machine to a **final state** and returns its output, for
|
|
1038
|
-
* run-to-done flows where an idle pause is unexpected. Wraps {@link runAgent}:
|
|
1039
|
-
*
|
|
1040
|
-
* - `done` → resolves with `result.output` (the machine's `OutputFrom`).
|
|
1041
|
-
* - `idle` → throws {@link AgentIdleError} carrying the idle snapshot and the
|
|
1042
|
-
* event types that could resume it.
|
|
1043
|
-
* - `error` → throws `result.error` when it is an `Error`; otherwise wraps it
|
|
1044
|
-
* in an `Error` whose `.cause` is the {@link RunAgentErrorCause} and whose
|
|
1045
|
-
* `.error` is the raw thrown value.
|
|
1046
|
-
*
|
|
1047
|
-
* Use {@link runAgent} directly when idle is an expected outcome you handle
|
|
1048
|
-
* (human-in-the-loop, resumable flows); use `runAgentToCompletion` when the
|
|
1049
|
-
* machine is meant to run straight through to a final state.
|
|
1050
|
-
*/
|
|
1051
|
-
declare function runAgentToCompletion<TMachine extends AnyStateMachine>(machine: TMachine, options: RunAgentOptions<TMachine>): Promise<OutputFrom<TMachine>>;
|
|
1052
|
-
/**
|
|
1053
|
-
* The actor handed to an {@link inspectTransitions} handler: an
|
|
1054
|
-
* {@link AnyActorRef} widened with the runtime `id`/`src` used to attribute a
|
|
1055
|
-
* transition to the root machine or a specific invoked child (xstate's static
|
|
1056
|
-
* `ActorRef` type omits them, but they are always present at runtime).
|
|
1057
|
-
*/
|
|
1058
|
-
type InspectedActorRef = AnyActorRef & {
|
|
1059
|
-
id: string;
|
|
1060
|
-
src?: string | AnyActorLogic;
|
|
1061
|
-
};
|
|
1062
|
-
/**
|
|
1063
|
-
* Wraps a `(snapshot, actorRef) => void` handler into a function usable as
|
|
1064
|
-
* {@link RunAgentOptions.inspect}: it filters the raw inspection stream to
|
|
1065
|
-
* `@xstate.transition` events and hands the handler the typed
|
|
1066
|
-
* {@link AnyMachineSnapshot} and the {@link InspectedActorRef} that
|
|
1067
|
-
* transitioned. Attribute a child actor via `actorRef.id`/`actorRef.src`. Saves
|
|
1068
|
-
* the manual `event.type === '@xstate.transition'` filtering and the snapshot/
|
|
1069
|
-
* actorRef casts.
|
|
1070
|
-
*/
|
|
1071
|
-
declare function inspectTransitions(handler: (snapshot: AnyMachineSnapshot, actorRef: InspectedActorRef) => void): (inspectionEvent: InspectionEvent) => void;
|
|
1072
|
-
//#endregion
|
|
1073
7
|
//#region src/verify.d.ts
|
|
1074
8
|
/** Severity of an {@link AgentLintDiagnostic}. `error` findings fail CI/the CLI; `warning`s are advisory. */
|
|
1075
9
|
type AgentLintSeverity = "error" | "warning";
|
|
@@ -1247,4 +181,4 @@ interface CanReachResult {
|
|
|
1247
181
|
*/
|
|
1248
182
|
declare function canReach(machine: AnyStateMachine, statePath: string, options?: ExplorePathsOptions): Promise<CanReachResult>;
|
|
1249
183
|
//#endregion
|
|
1250
|
-
export { type AgentDecisionExecutor, type AgentDecisionInput, type AgentDecisionRequest, type AgentEventDescriptor, type AgentEventToolNameResolver, AgentIdleError, type AgentLintDiagnostic, type AgentLintSeverity, type AgentMessage, type AgentModelMap, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal, type AgentPlanInput, type AgentPlanOutput, type AgentPlanRequest, type AgentRequest, type AgentRequestConfig, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestMode, type AgentRequestOptions, type AgentRequestSource, type AgentSchemaPack, type AgentSetupStateSchema, type AgentSnapshotStore, type AgentStateNarrowing, type AgentStateRequest, type AgentStep, type AgentStepRequest, type AgentTextRequest, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentToolSchema, type AgentTools, type AgentTraceEvent, type AgentUserInput, type AgentUserInputExecutor, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AiSdkShapedStreamResult, type AiSdkShapedTextResult, type AllowedEventPattern, type AllowedEvents, type AssistantMessage, type CanReachResult, type ChosenEvent, type DataContent, type DecisionAttempt, DecisionExhaustedError, type DecisionLogic, type DecisionLogicConfig, EVENT_TOOL_PREFIX, type EventPayload, type EventUnion, type ExplorePathsOptions, type FilePart, type FromConfigOptions, IllegalResumeEventError, type ImagePart, type InferOutput, type InspectedActorRef, type LintAgentMachineOptions, PLAN_DONE_EVENT_TYPE, type PendingUserInput, type ProviderOptions, type ResolveAgentRequestsOptions, type ResolveDecisionOptions, type RunAgentOptions, type RunAgentResult, type SchemaCompiler, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, SnapshotVersionMismatchError, type StandardSchemaV1, type StructuredOutputEnvelope, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextLogicInput, type TextLogicOutput, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultOutput, type ToolResultPart, type UserMessage, appendMessages, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentSchemas, createTextLogic, executeAgentRequest, explorePaths, getAcceptedEvents, getAgentMessages, getAgentOutputMode, getAgentRequests, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getStateMeta, initialAgentStep, inspectTransitions, isStandardSchema, isStructuredOutputSchema, lintAgentMachine, matchesEventPattern, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, persistSnapshot, renderDecisionAttempts, resolveAgentRequests, resolveAgentStep, resolveDecision, runAgent, runAgentToCompletion, setupAgent, simulateAgent, systemMessage, toolMessage, transitionAgentStep, userMessage, validateSchemaSync };
|
|
184
|
+
export { type AgentDecisionExecutor, type AgentDecisionInput, type AgentDecisionRequest, type AgentEventDescriptor, type AgentEventSchemaInput, type AgentEventSchemaInputMap, type AgentEventToolNameResolver, AgentIdleError, type AgentLintDiagnostic, type AgentLintSeverity, type AgentMachine, type AgentMachineConfig, type AgentMessage, type AgentMessageInfo, type AgentModelMap, type AgentModelRef, type AgentOutputMode, type AgentPathReport, type AgentPathTerminal, type AgentPlanInput, type AgentPlanOutput, type AgentPlanRequest, type AgentRequest, type AgentRequestConfig, type AgentRequestExecutor, type AgentRequestExecutorInfo, type AgentRequestExecutorResult, type AgentRequestExecutors, type AgentRequestMode, type AgentRequestOptions, type AgentRequestSource, type AgentRunMeta, type AgentSchemaPack, type AgentSetupStateSchema, type AgentSnapshotStore, type AgentStateNarrowing, type AgentStateRequest, type AgentStep, type AgentStepRequest, type AgentTextRequest, type AgentTool, type AgentToolChoice, type AgentToolDescriptor, type AgentToolExecute, type AgentToolSchema, type AgentTools, type AgentTraceEvent, type AgentUserInput, type AgentUserInputExecutor, type AgentWorkflowActionConfig, type AgentWorkflowActorConfig, type AgentWorkflowConfig, type AgentWorkflowInvokeConfig, type AgentWorkflowRequestConfig, type AgentWorkflowStateConfig, type AgentWorkflowTransitionConfig, type AiSdkShapedStreamResult, type AiSdkShapedTextResult, type AllowedEventPattern, type AllowedEvents, type AssistantMessage, type CanReachResult, type ChosenEvent, type DataContent, type DecisionAttempt, DecisionExhaustedError, type DecisionLogic, type DecisionLogicConfig, EVENT_TOOL_PREFIX, type EventPayload, type EventUnion, type ExplorePathsOptions, type FilePart, type FromConfigOptions, IllegalResumeEventError, type ImagePart, type InferOutput, type InspectedActorRef, type LintAgentMachineOptions, type NormalizedEventSchemas, PLAN_DONE_EVENT_TYPE, type PendingUserInput, type ProviderOptions, type ResolveAgentRequestsOptions, type ResolveDecisionOptions, type RunAgentOptions, type RunAgentResult, type SchemaCompiler, type SimulateAgentOptions, type SimulateAgentResult, type SimulationScript, type SimulationTrailEntry, SnapshotVersionMismatchError, type StandardSchemaV1, type StructuredOutputEnvelope, type SystemMessage, type TextLogic, type TextLogicConfig, type TextLogicExecuteArgs, type TextLogicExecutor, type TextLogicInput, type TextLogicOutput, type TextPart, type ToolCallPart, type ToolMessage, type ToolResultOutput, type ToolResultPart, type UserMessage, appendMessages, assistantMessage, bindRequestExecutor, buildEnvelopeSchema, canReach, createAgentSchemas, createTextLogic, executeAgentRequest, explorePaths, getAcceptedEvents, getAgentMessages, getAgentOutputMode, getAgentRequests, getJsonSchema, getJsonSchemaSync, getMachineStructuralHash, getStateMeta, initialAgentStep, inspectTransitions, isStandardSchema, isStructuredOutputSchema, lintAgentMachine, matchesEventPattern, messagesSchema, parseAgentEvent, parseModelRef, parseOutput, parseStructuredEnvelope, persistSnapshot, renderDecisionAttempts, resolveAgentRequests, resolveAgentStep, resolveDecision, runAgent, runAgentToCompletion, setupAgent, simulateAgent, systemMessage, toolMessage, transitionAgentStep, userMessage, validateSchemaSync };
|