@statelyai/agent 2.0.0-alpha.18 → 2.0.0-alpha.19
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 -2
- package/dist/ai-sdk.d.cts +1 -1
- package/dist/ai-sdk.d.mts +1 -1
- package/dist/ai-sdk.mjs +3 -2
- package/dist/{decision-C11xuud2.mjs → decision-DsIkEuHz.mjs} +48 -28
- package/dist/{decision-DnQCQPew.cjs → decision-t26zsnSR.cjs} +64 -43
- package/dist/{event-log-store-CQJq8_v4.d.cts → event-log-store-Bz7HDBkE.d.cts} +11 -12
- package/dist/{event-log-store-B-1fcfkT.mjs → event-log-store-DmIDosD6.mjs} +22 -14
- package/dist/{event-log-store-yquOV1TX.cjs → event-log-store-a_TKy1gk.cjs} +22 -14
- package/dist/{event-log-store-BrC9Q1xW.d.mts → event-log-store-hrA1vqtN.d.mts} +11 -12
- package/dist/index.cjs +265 -109
- package/dist/index.d.cts +136 -80
- package/dist/index.d.mts +136 -80
- package/dist/index.mjs +262 -107
- package/dist/machines.cjs +13 -17
- package/dist/machines.d.cts +14 -17
- package/dist/machines.d.mts +14 -17
- package/dist/machines.mjs +13 -17
- package/dist/otel.cjs +1 -0
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/{run-agent-r9OD4z8F.d.cts → run-agent--4bbms-D.d.cts} +121 -48
- package/dist/{run-agent-DQIDikfd.d.mts → run-agent-CwmzAZwj.d.mts} +121 -48
- package/dist/{setup-agent-C3ETi_HZ.cjs → setup-agent-BFA4VKpN.cjs} +31 -33
- package/dist/{setup-agent-BrE2zFDy.mjs → setup-agent-CPFPN06s.mjs} +31 -28
- package/dist/sqlite.cjs +3 -9
- package/dist/sqlite.d.cts +1 -1
- package/dist/sqlite.d.mts +1 -1
- package/dist/sqlite.mjs +3 -9
- package/dist/{text-logic-VcWqO-Cl.d.cts → text-logic-Cavva1W6.d.cts} +24 -8
- package/dist/{text-logic-RvnlD-An.d.mts → text-logic-Er5KkTX6.d.mts} +24 -8
- package/dist/validate.cjs +436 -0
- package/dist/validate.d.cts +31 -0
- package/dist/validate.d.mts +31 -0
- package/dist/validate.mjs +411 -0
- package/package.json +15 -1
- package/schemas/agent-workflow.json +2 -2
- package/skills/generate-machine/SKILL.md +12 -14
package/dist/machines.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_setup_agent = require("./setup-agent-
|
|
2
|
+
const require_setup_agent = require("./setup-agent-BFA4VKpN.cjs");
|
|
3
3
|
//#region src/machines/internal.ts
|
|
4
4
|
/** The builtin inline text request every preset lowers a request entry to. */
|
|
5
5
|
const GENERATE_TEXT_SRC = "agent.generateText";
|
|
@@ -69,7 +69,7 @@ function requestInput(name, entry, defaultModel, prompt) {
|
|
|
69
69
|
prompt,
|
|
70
70
|
...entry.tools ? { tools: entry.tools } : {},
|
|
71
71
|
...entry.outputSchema ? { outputSchema: entry.outputSchema } : {},
|
|
72
|
-
...entry.
|
|
72
|
+
...entry.maxSteps !== void 0 ? { maxSteps: entry.maxSteps } : {}
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
@@ -100,7 +100,7 @@ const inputSchema$6 = objectSchema({ prompt: jsonString }, ["prompt"]);
|
|
|
100
100
|
const outputSchema$5 = objectSchema({ result: jsonAny }, ["result"]);
|
|
101
101
|
/**
|
|
102
102
|
* The single-state tool loop: one text request carries the `tools`, and the
|
|
103
|
-
* host runs the tool loop inside it (`
|
|
103
|
+
* host runs the tool loop inside it (`maxSteps` bounds it). Selecting and
|
|
104
104
|
* executing tools is the model + host's business, not machine states.
|
|
105
105
|
*
|
|
106
106
|
* States: `answering` → `done`.
|
|
@@ -110,7 +110,7 @@ const outputSchema$5 = objectSchema({ result: jsonAny }, ["result"]);
|
|
|
110
110
|
* model: "quick",
|
|
111
111
|
* instructions: "Answer using the tools.",
|
|
112
112
|
* tools: { calculate },
|
|
113
|
-
*
|
|
113
|
+
* maxSteps: 5,
|
|
114
114
|
* });
|
|
115
115
|
*
|
|
116
116
|
* const result = await runAgent(machine, {
|
|
@@ -121,11 +121,7 @@ const outputSchema$5 = objectSchema({ result: jsonAny }, ["result"]);
|
|
|
121
121
|
* ```
|
|
122
122
|
*/
|
|
123
123
|
function createToolLoopMachine(config) {
|
|
124
|
-
const { model, instructions, tools, outputSchema: resultSchema,
|
|
125
|
-
const metadata = {
|
|
126
|
-
...maxTurns !== void 0 ? { maxSteps: maxTurns } : {},
|
|
127
|
-
...interruptOn && interruptOn.length > 0 ? { interruptOn: [...interruptOn] } : {}
|
|
128
|
-
};
|
|
124
|
+
const { model, instructions, tools, outputSchema: resultSchema, maxSteps } = config;
|
|
129
125
|
return require_setup_agent.setupAgent({
|
|
130
126
|
context: contextSchema$6,
|
|
131
127
|
input: inputSchema$6,
|
|
@@ -149,7 +145,7 @@ function createToolLoopMachine(config) {
|
|
|
149
145
|
prompt: context.prompt,
|
|
150
146
|
...tools ? { tools } : {},
|
|
151
147
|
...resultSchema ? { outputSchema: resultSchema } : {},
|
|
152
|
-
...
|
|
148
|
+
...maxSteps !== void 0 ? { maxSteps } : {}
|
|
153
149
|
}),
|
|
154
150
|
onDone: ({ output }) => ({
|
|
155
151
|
target: "done",
|
|
@@ -212,7 +208,7 @@ function createSequentialMachine(config) {
|
|
|
212
208
|
model: step.model,
|
|
213
209
|
outputSchema: step.outputSchema,
|
|
214
210
|
tools: step.tools,
|
|
215
|
-
|
|
211
|
+
maxSteps: step.maxSteps
|
|
216
212
|
}, model, step.prompt ? step.prompt({
|
|
217
213
|
prompt: context.prompt,
|
|
218
214
|
results: context.results,
|
|
@@ -448,7 +444,7 @@ const outputSchema$1 = objectSchema({
|
|
|
448
444
|
}, ["iterations", "results"]);
|
|
449
445
|
/**
|
|
450
446
|
* A bounded repeat: run the body, check `until` over the accumulated state,
|
|
451
|
-
* and either stop or go again. `
|
|
447
|
+
* and either stop or go again. `maxTurns` is a guard, so the loop cannot
|
|
452
448
|
* run away even if `until` never returns `true`.
|
|
453
449
|
*
|
|
454
450
|
* States: `running` → `checking` → (`running` | `done`).
|
|
@@ -458,13 +454,13 @@ const outputSchema$1 = objectSchema({
|
|
|
458
454
|
* model: "quick",
|
|
459
455
|
* body: { instructions: "Improve the draft. Return only the draft." },
|
|
460
456
|
* until: ({ last }) => String(last).length > 500,
|
|
461
|
-
*
|
|
457
|
+
* maxTurns: 4,
|
|
462
458
|
* });
|
|
463
459
|
* ```
|
|
464
460
|
*/
|
|
465
461
|
function createLoopMachine(config) {
|
|
466
|
-
const { model, body, until,
|
|
467
|
-
if (!Number.isInteger(
|
|
462
|
+
const { model, body, until, maxTurns } = config;
|
|
463
|
+
if (!Number.isInteger(maxTurns) || maxTurns < 1) throw new Error("createLoopMachine: maxTurns must be an integer >= 1.");
|
|
468
464
|
const agentSetup = require_setup_agent.setupAgent({
|
|
469
465
|
context: contextSchema$2,
|
|
470
466
|
input: inputSchema$2,
|
|
@@ -503,7 +499,7 @@ function createLoopMachine(config) {
|
|
|
503
499
|
} },
|
|
504
500
|
checking: {
|
|
505
501
|
type: "choice",
|
|
506
|
-
choice: ({ context }) => context.iterations >=
|
|
502
|
+
choice: ({ context }) => context.iterations >= maxTurns || until(loopState(context)) ? { target: "done" } : { target: "running" }
|
|
507
503
|
},
|
|
508
504
|
done: {
|
|
509
505
|
type: "final",
|
|
@@ -700,7 +696,7 @@ function createHandoffMachine(config) {
|
|
|
700
696
|
input: inputSchema,
|
|
701
697
|
events: Object.fromEntries(names.map((name) => [transferEventType(name), transferPayload])),
|
|
702
698
|
actors: machineActors(agents),
|
|
703
|
-
|
|
699
|
+
isIdle: (snapshot) => snapshot.matches("waiting")
|
|
704
700
|
});
|
|
705
701
|
const turnState = (name) => `${name}Turn`;
|
|
706
702
|
const states = {
|
package/dist/machines.d.cts
CHANGED
|
@@ -12,15 +12,12 @@ interface CreateToolLoopMachineConfig {
|
|
|
12
12
|
tools?: AgentTools;
|
|
13
13
|
/** Structured output schema. Omitted means the output is plain text. */
|
|
14
14
|
outputSchema?: StandardSchemaV1;
|
|
15
|
-
/** Bounds the host-side tool loop — lowered to `metadata.maxSteps`. */
|
|
16
|
-
maxTurns?: number;
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* approval gate as machine states, eject to `examples/review-tool-calls`.
|
|
16
|
+
* Bounds the host-side tool loop — lowered to the request's typed
|
|
17
|
+
* {@link AgentTextRequest.maxSteps}. It bounds MODEL STEPS inside one
|
|
18
|
+
* request, not machine turns, hence the name.
|
|
22
19
|
*/
|
|
23
|
-
|
|
20
|
+
maxSteps?: number;
|
|
24
21
|
}
|
|
25
22
|
/** Context of a {@link createToolLoopMachine} machine. */
|
|
26
23
|
type ToolLoopContext = {
|
|
@@ -29,7 +26,7 @@ type ToolLoopContext = {
|
|
|
29
26
|
};
|
|
30
27
|
/**
|
|
31
28
|
* The single-state tool loop: one text request carries the `tools`, and the
|
|
32
|
-
* host runs the tool loop inside it (`
|
|
29
|
+
* host runs the tool loop inside it (`maxSteps` bounds it). Selecting and
|
|
33
30
|
* executing tools is the model + host's business, not machine states.
|
|
34
31
|
*
|
|
35
32
|
* States: `answering` → `done`.
|
|
@@ -39,7 +36,7 @@ type ToolLoopContext = {
|
|
|
39
36
|
* model: "quick",
|
|
40
37
|
* instructions: "Answer using the tools.",
|
|
41
38
|
* tools: { calculate },
|
|
42
|
-
*
|
|
39
|
+
* maxSteps: 5,
|
|
43
40
|
* });
|
|
44
41
|
*
|
|
45
42
|
* const result = await runAgent(machine, {
|
|
@@ -75,8 +72,8 @@ interface SequentialStep {
|
|
|
75
72
|
model?: string;
|
|
76
73
|
/** Tools the host runs inside this step's request. */
|
|
77
74
|
tools?: AgentTools;
|
|
78
|
-
/** Bounds this step's host-side tool loop (`
|
|
79
|
-
|
|
75
|
+
/** Bounds this step's host-side tool loop (the request's typed `maxSteps`). */
|
|
76
|
+
maxSteps?: number;
|
|
80
77
|
}
|
|
81
78
|
/** Config for {@link createSequentialMachine}. */
|
|
82
79
|
interface CreateSequentialMachineConfig {
|
|
@@ -124,8 +121,8 @@ interface PresetRequestEntry {
|
|
|
124
121
|
outputSchema?: StandardSchemaV1;
|
|
125
122
|
/** Tools the host runs inside this one request. */
|
|
126
123
|
tools?: AgentTools;
|
|
127
|
-
/** Bounds the host-side tool loop (lowered to `
|
|
128
|
-
|
|
124
|
+
/** Bounds the host-side tool loop (lowered to the request's typed `maxSteps`). */
|
|
125
|
+
maxSteps?: number;
|
|
129
126
|
}
|
|
130
127
|
/** One delegated unit of work, lowered to an invoked child machine. */
|
|
131
128
|
interface PresetMachineEntry {
|
|
@@ -240,8 +237,8 @@ interface CreateLoopMachineConfig {
|
|
|
240
237
|
};
|
|
241
238
|
/** Stop condition, checked after each iteration. */
|
|
242
239
|
until: (state: LoopState) => boolean;
|
|
243
|
-
/** Hard upper bound on iterations, enforced by a guard. */
|
|
244
|
-
|
|
240
|
+
/** Hard upper bound on machine turns (iterations), enforced by a guard. */
|
|
241
|
+
maxTurns: number;
|
|
245
242
|
}
|
|
246
243
|
/** Context of a {@link createLoopMachine} machine. */
|
|
247
244
|
type LoopContext = {
|
|
@@ -252,7 +249,7 @@ type LoopContext = {
|
|
|
252
249
|
};
|
|
253
250
|
/**
|
|
254
251
|
* A bounded repeat: run the body, check `until` over the accumulated state,
|
|
255
|
-
* and either stop or go again. `
|
|
252
|
+
* and either stop or go again. `maxTurns` is a guard, so the loop cannot
|
|
256
253
|
* run away even if `until` never returns `true`.
|
|
257
254
|
*
|
|
258
255
|
* States: `running` → `checking` → (`running` | `done`).
|
|
@@ -262,7 +259,7 @@ type LoopContext = {
|
|
|
262
259
|
* model: "quick",
|
|
263
260
|
* body: { instructions: "Improve the draft. Return only the draft." },
|
|
264
261
|
* until: ({ last }) => String(last).length > 500,
|
|
265
|
-
*
|
|
262
|
+
* maxTurns: 4,
|
|
266
263
|
* });
|
|
267
264
|
* ```
|
|
268
265
|
*/
|
package/dist/machines.d.mts
CHANGED
|
@@ -12,15 +12,12 @@ interface CreateToolLoopMachineConfig {
|
|
|
12
12
|
tools?: AgentTools;
|
|
13
13
|
/** Structured output schema. Omitted means the output is plain text. */
|
|
14
14
|
outputSchema?: StandardSchemaV1;
|
|
15
|
-
/** Bounds the host-side tool loop — lowered to `metadata.maxSteps`. */
|
|
16
|
-
maxTurns?: number;
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* approval gate as machine states, eject to `examples/review-tool-calls`.
|
|
16
|
+
* Bounds the host-side tool loop — lowered to the request's typed
|
|
17
|
+
* {@link AgentTextRequest.maxSteps}. It bounds MODEL STEPS inside one
|
|
18
|
+
* request, not machine turns, hence the name.
|
|
22
19
|
*/
|
|
23
|
-
|
|
20
|
+
maxSteps?: number;
|
|
24
21
|
}
|
|
25
22
|
/** Context of a {@link createToolLoopMachine} machine. */
|
|
26
23
|
type ToolLoopContext = {
|
|
@@ -29,7 +26,7 @@ type ToolLoopContext = {
|
|
|
29
26
|
};
|
|
30
27
|
/**
|
|
31
28
|
* The single-state tool loop: one text request carries the `tools`, and the
|
|
32
|
-
* host runs the tool loop inside it (`
|
|
29
|
+
* host runs the tool loop inside it (`maxSteps` bounds it). Selecting and
|
|
33
30
|
* executing tools is the model + host's business, not machine states.
|
|
34
31
|
*
|
|
35
32
|
* States: `answering` → `done`.
|
|
@@ -39,7 +36,7 @@ type ToolLoopContext = {
|
|
|
39
36
|
* model: "quick",
|
|
40
37
|
* instructions: "Answer using the tools.",
|
|
41
38
|
* tools: { calculate },
|
|
42
|
-
*
|
|
39
|
+
* maxSteps: 5,
|
|
43
40
|
* });
|
|
44
41
|
*
|
|
45
42
|
* const result = await runAgent(machine, {
|
|
@@ -75,8 +72,8 @@ interface SequentialStep {
|
|
|
75
72
|
model?: string;
|
|
76
73
|
/** Tools the host runs inside this step's request. */
|
|
77
74
|
tools?: AgentTools;
|
|
78
|
-
/** Bounds this step's host-side tool loop (`
|
|
79
|
-
|
|
75
|
+
/** Bounds this step's host-side tool loop (the request's typed `maxSteps`). */
|
|
76
|
+
maxSteps?: number;
|
|
80
77
|
}
|
|
81
78
|
/** Config for {@link createSequentialMachine}. */
|
|
82
79
|
interface CreateSequentialMachineConfig {
|
|
@@ -124,8 +121,8 @@ interface PresetRequestEntry {
|
|
|
124
121
|
outputSchema?: StandardSchemaV1;
|
|
125
122
|
/** Tools the host runs inside this one request. */
|
|
126
123
|
tools?: AgentTools;
|
|
127
|
-
/** Bounds the host-side tool loop (lowered to `
|
|
128
|
-
|
|
124
|
+
/** Bounds the host-side tool loop (lowered to the request's typed `maxSteps`). */
|
|
125
|
+
maxSteps?: number;
|
|
129
126
|
}
|
|
130
127
|
/** One delegated unit of work, lowered to an invoked child machine. */
|
|
131
128
|
interface PresetMachineEntry {
|
|
@@ -240,8 +237,8 @@ interface CreateLoopMachineConfig {
|
|
|
240
237
|
};
|
|
241
238
|
/** Stop condition, checked after each iteration. */
|
|
242
239
|
until: (state: LoopState) => boolean;
|
|
243
|
-
/** Hard upper bound on iterations, enforced by a guard. */
|
|
244
|
-
|
|
240
|
+
/** Hard upper bound on machine turns (iterations), enforced by a guard. */
|
|
241
|
+
maxTurns: number;
|
|
245
242
|
}
|
|
246
243
|
/** Context of a {@link createLoopMachine} machine. */
|
|
247
244
|
type LoopContext = {
|
|
@@ -252,7 +249,7 @@ type LoopContext = {
|
|
|
252
249
|
};
|
|
253
250
|
/**
|
|
254
251
|
* A bounded repeat: run the body, check `until` over the accumulated state,
|
|
255
|
-
* and either stop or go again. `
|
|
252
|
+
* and either stop or go again. `maxTurns` is a guard, so the loop cannot
|
|
256
253
|
* run away even if `until` never returns `true`.
|
|
257
254
|
*
|
|
258
255
|
* States: `running` → `checking` → (`running` | `done`).
|
|
@@ -262,7 +259,7 @@ type LoopContext = {
|
|
|
262
259
|
* model: "quick",
|
|
263
260
|
* body: { instructions: "Improve the draft. Return only the draft." },
|
|
264
261
|
* until: ({ last }) => String(last).length > 500,
|
|
265
|
-
*
|
|
262
|
+
* maxTurns: 4,
|
|
266
263
|
* });
|
|
267
264
|
* ```
|
|
268
265
|
*/
|
package/dist/machines.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as setupAgent } from "./setup-agent-
|
|
1
|
+
import { r as setupAgent } from "./setup-agent-CPFPN06s.mjs";
|
|
2
2
|
//#region src/machines/internal.ts
|
|
3
3
|
/** The builtin inline text request every preset lowers a request entry to. */
|
|
4
4
|
const GENERATE_TEXT_SRC = "agent.generateText";
|
|
@@ -68,7 +68,7 @@ function requestInput(name, entry, defaultModel, prompt) {
|
|
|
68
68
|
prompt,
|
|
69
69
|
...entry.tools ? { tools: entry.tools } : {},
|
|
70
70
|
...entry.outputSchema ? { outputSchema: entry.outputSchema } : {},
|
|
71
|
-
...entry.
|
|
71
|
+
...entry.maxSteps !== void 0 ? { maxSteps: entry.maxSteps } : {}
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
@@ -99,7 +99,7 @@ const inputSchema$6 = objectSchema({ prompt: jsonString }, ["prompt"]);
|
|
|
99
99
|
const outputSchema$5 = objectSchema({ result: jsonAny }, ["result"]);
|
|
100
100
|
/**
|
|
101
101
|
* The single-state tool loop: one text request carries the `tools`, and the
|
|
102
|
-
* host runs the tool loop inside it (`
|
|
102
|
+
* host runs the tool loop inside it (`maxSteps` bounds it). Selecting and
|
|
103
103
|
* executing tools is the model + host's business, not machine states.
|
|
104
104
|
*
|
|
105
105
|
* States: `answering` → `done`.
|
|
@@ -109,7 +109,7 @@ const outputSchema$5 = objectSchema({ result: jsonAny }, ["result"]);
|
|
|
109
109
|
* model: "quick",
|
|
110
110
|
* instructions: "Answer using the tools.",
|
|
111
111
|
* tools: { calculate },
|
|
112
|
-
*
|
|
112
|
+
* maxSteps: 5,
|
|
113
113
|
* });
|
|
114
114
|
*
|
|
115
115
|
* const result = await runAgent(machine, {
|
|
@@ -120,11 +120,7 @@ const outputSchema$5 = objectSchema({ result: jsonAny }, ["result"]);
|
|
|
120
120
|
* ```
|
|
121
121
|
*/
|
|
122
122
|
function createToolLoopMachine(config) {
|
|
123
|
-
const { model, instructions, tools, outputSchema: resultSchema,
|
|
124
|
-
const metadata = {
|
|
125
|
-
...maxTurns !== void 0 ? { maxSteps: maxTurns } : {},
|
|
126
|
-
...interruptOn && interruptOn.length > 0 ? { interruptOn: [...interruptOn] } : {}
|
|
127
|
-
};
|
|
123
|
+
const { model, instructions, tools, outputSchema: resultSchema, maxSteps } = config;
|
|
128
124
|
return setupAgent({
|
|
129
125
|
context: contextSchema$6,
|
|
130
126
|
input: inputSchema$6,
|
|
@@ -148,7 +144,7 @@ function createToolLoopMachine(config) {
|
|
|
148
144
|
prompt: context.prompt,
|
|
149
145
|
...tools ? { tools } : {},
|
|
150
146
|
...resultSchema ? { outputSchema: resultSchema } : {},
|
|
151
|
-
...
|
|
147
|
+
...maxSteps !== void 0 ? { maxSteps } : {}
|
|
152
148
|
}),
|
|
153
149
|
onDone: ({ output }) => ({
|
|
154
150
|
target: "done",
|
|
@@ -211,7 +207,7 @@ function createSequentialMachine(config) {
|
|
|
211
207
|
model: step.model,
|
|
212
208
|
outputSchema: step.outputSchema,
|
|
213
209
|
tools: step.tools,
|
|
214
|
-
|
|
210
|
+
maxSteps: step.maxSteps
|
|
215
211
|
}, model, step.prompt ? step.prompt({
|
|
216
212
|
prompt: context.prompt,
|
|
217
213
|
results: context.results,
|
|
@@ -447,7 +443,7 @@ const outputSchema$1 = objectSchema({
|
|
|
447
443
|
}, ["iterations", "results"]);
|
|
448
444
|
/**
|
|
449
445
|
* A bounded repeat: run the body, check `until` over the accumulated state,
|
|
450
|
-
* and either stop or go again. `
|
|
446
|
+
* and either stop or go again. `maxTurns` is a guard, so the loop cannot
|
|
451
447
|
* run away even if `until` never returns `true`.
|
|
452
448
|
*
|
|
453
449
|
* States: `running` → `checking` → (`running` | `done`).
|
|
@@ -457,13 +453,13 @@ const outputSchema$1 = objectSchema({
|
|
|
457
453
|
* model: "quick",
|
|
458
454
|
* body: { instructions: "Improve the draft. Return only the draft." },
|
|
459
455
|
* until: ({ last }) => String(last).length > 500,
|
|
460
|
-
*
|
|
456
|
+
* maxTurns: 4,
|
|
461
457
|
* });
|
|
462
458
|
* ```
|
|
463
459
|
*/
|
|
464
460
|
function createLoopMachine(config) {
|
|
465
|
-
const { model, body, until,
|
|
466
|
-
if (!Number.isInteger(
|
|
461
|
+
const { model, body, until, maxTurns } = config;
|
|
462
|
+
if (!Number.isInteger(maxTurns) || maxTurns < 1) throw new Error("createLoopMachine: maxTurns must be an integer >= 1.");
|
|
467
463
|
const agentSetup = setupAgent({
|
|
468
464
|
context: contextSchema$2,
|
|
469
465
|
input: inputSchema$2,
|
|
@@ -502,7 +498,7 @@ function createLoopMachine(config) {
|
|
|
502
498
|
} },
|
|
503
499
|
checking: {
|
|
504
500
|
type: "choice",
|
|
505
|
-
choice: ({ context }) => context.iterations >=
|
|
501
|
+
choice: ({ context }) => context.iterations >= maxTurns || until(loopState(context)) ? { target: "done" } : { target: "running" }
|
|
506
502
|
},
|
|
507
503
|
done: {
|
|
508
504
|
type: "final",
|
|
@@ -699,7 +695,7 @@ function createHandoffMachine(config) {
|
|
|
699
695
|
input: inputSchema,
|
|
700
696
|
events: Object.fromEntries(names.map((name) => [transferEventType(name), transferPayload])),
|
|
701
697
|
actors: machineActors(agents),
|
|
702
|
-
|
|
698
|
+
isIdle: (snapshot) => snapshot.matches("waiting")
|
|
703
699
|
});
|
|
704
700
|
const turnState = (name) => `${name}Turn`;
|
|
705
701
|
const states = {
|
package/dist/otel.cjs
CHANGED
package/dist/otel.d.cts
CHANGED
package/dist/otel.d.mts
CHANGED