@nones/agentflow-strategy-workflow 0.7.0 → 0.8.0
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/README.md +10 -8
- package/package.json +2 -2
- package/src/expansion.ts +26 -2
- package/src/internal.ts +67 -4
package/README.md
CHANGED
|
@@ -44,15 +44,19 @@ The input is already a `RunPlan`:
|
|
|
44
44
|
```ts
|
|
45
45
|
{
|
|
46
46
|
waves: WaveSpec[];
|
|
47
|
+
scripts?: PlanHandlerStep[];
|
|
48
|
+
gates?: PlanHandlerStep[];
|
|
47
49
|
profile?: string;
|
|
48
50
|
artifacts?: ArtifactDeclaration[];
|
|
49
51
|
sealed?: boolean;
|
|
50
52
|
}
|
|
51
53
|
```
|
|
52
54
|
|
|
53
|
-
Compilation validates and deeply clones the plan. Wave IDs must be unique
|
|
54
|
-
IDs must be unique across the whole run
|
|
55
|
-
|
|
55
|
+
Compilation validates and deeply clones the plan. Wave IDs must be unique and
|
|
56
|
+
agent IDs must be unique across the whole run. A wave can contain agents,
|
|
57
|
+
registered script or gate steps, or an empty reservation marked `hole: true`.
|
|
58
|
+
Core waits at a hole until `append` adds work to its wave or closes it empty.
|
|
59
|
+
Artifacts follow the same rules as the agent strategy: unique IDs, a
|
|
56
60
|
`json`, `text` or `file` type, boolean `required` and an object `schema` when
|
|
57
61
|
present. An empty unsealed plan is a valid idle queue; a sealed empty plan is
|
|
58
62
|
preserved.
|
|
@@ -63,14 +67,12 @@ Through the CLI:
|
|
|
63
67
|
|
|
64
68
|
```ts
|
|
65
69
|
const run = await flow.start({
|
|
66
|
-
strategy:
|
|
70
|
+
strategy: workflowStrategy,
|
|
67
71
|
input: plan,
|
|
68
72
|
});
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
await flow.waitWave(runId, "inspect");
|
|
73
|
-
await flow.seal(runId);
|
|
74
|
+
await flow.waitWave(run.id, "inspect");
|
|
75
|
+
await flow.seal(run.id);
|
|
74
76
|
```
|
|
75
77
|
|
|
76
78
|
Programmatically:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nones/agentflow-strategy-workflow",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Wave-based AgentFlow workflow strategy",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"test": "bun test"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@nones/agentflow-core": "0.
|
|
38
|
+
"@nones/agentflow-core": "0.8.0"
|
|
39
39
|
},
|
|
40
40
|
"bugs": {
|
|
41
41
|
"url": "https://github.com/nones-tools/agentflow/issues"
|
package/src/expansion.ts
CHANGED
|
@@ -268,10 +268,15 @@ function expand(
|
|
|
268
268
|
onRoundStep: (step) => round.steps.push(step),
|
|
269
269
|
});
|
|
270
270
|
|
|
271
|
-
if (
|
|
271
|
+
if (
|
|
272
|
+
agents.length === 0 &&
|
|
273
|
+
!round.steps.some(
|
|
274
|
+
(step) => step.kind === "script" || step.kind === "gate",
|
|
275
|
+
)
|
|
276
|
+
) {
|
|
272
277
|
fail(
|
|
273
278
|
`${roundPath}`,
|
|
274
|
-
"must contain at least one agent step
|
|
279
|
+
"must contain at least one agent step, or a trusted script or gate step when the round has no agents",
|
|
275
280
|
);
|
|
276
281
|
}
|
|
277
282
|
phase.rounds.push(round);
|
|
@@ -295,14 +300,33 @@ function expand(
|
|
|
295
300
|
validateDependencies(steps, `${path}`);
|
|
296
301
|
|
|
297
302
|
// Final guard: the expansion must convert into a RunPlan the engine accepts.
|
|
303
|
+
// Trusted handler steps are included so a non-agent-only round is validated
|
|
304
|
+
// against the same plan shape core receives.
|
|
298
305
|
const profile = expectOptionalString(record.profile, `${path}.profile`);
|
|
299
306
|
const sealed = record.sealed as boolean | undefined;
|
|
307
|
+
const guardSteps = steps
|
|
308
|
+
.filter((step) => step.kind === "script" || step.kind === "gate")
|
|
309
|
+
.map((step) => {
|
|
310
|
+
if (step.handler === undefined) {
|
|
311
|
+
fail(step.key, "must have a registered handler reference");
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
id: step.key,
|
|
315
|
+
waveId: step.wave,
|
|
316
|
+
kind: step.kind,
|
|
317
|
+
handler: step.handler,
|
|
318
|
+
};
|
|
319
|
+
});
|
|
320
|
+
const guardScripts = guardSteps.filter((step) => step.kind === "script");
|
|
321
|
+
const guardGates = guardSteps.filter((step) => step.kind === "gate");
|
|
300
322
|
try {
|
|
301
323
|
normalizeRunPlan(
|
|
302
324
|
{
|
|
303
325
|
waves,
|
|
304
326
|
...(profile === undefined ? {} : { profile }),
|
|
305
327
|
...(sealed === undefined ? {} : { sealed }),
|
|
328
|
+
...(guardScripts.length === 0 ? {} : { scripts: guardScripts }),
|
|
329
|
+
...(guardGates.length === 0 ? {} : { gates: guardGates }),
|
|
306
330
|
},
|
|
307
331
|
`${path}`,
|
|
308
332
|
);
|
package/src/internal.ts
CHANGED
|
@@ -22,7 +22,7 @@ const PLAN_FIELDS = [
|
|
|
22
22
|
"gates",
|
|
23
23
|
"metadata",
|
|
24
24
|
] as const;
|
|
25
|
-
const WAVE_FIELDS = ["id", "agents"] as const;
|
|
25
|
+
const WAVE_FIELDS = ["id", "agents", "hole"] as const;
|
|
26
26
|
const AGENT_FIELDS = [
|
|
27
27
|
"id",
|
|
28
28
|
"prompt",
|
|
@@ -261,9 +261,49 @@ export function normalizeArtifacts(
|
|
|
261
261
|
});
|
|
262
262
|
}
|
|
263
263
|
|
|
264
|
+
/**
|
|
265
|
+
* A wave the engine may reserve without agents. Core owns the runtime meaning;
|
|
266
|
+
* the normalizer only preserves the explicit marker and validates its type.
|
|
267
|
+
*/
|
|
268
|
+
type WaveSpecWithHole = WaveSpec & { hole?: boolean };
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* True when the plan declares at least one trusted script or gate step for the
|
|
272
|
+
* wave. An empty wave is only a valid non-agent wave when such a step exists;
|
|
273
|
+
* executable text never counts because only a handler name is accepted.
|
|
274
|
+
*/
|
|
275
|
+
function hasTrustedStep(
|
|
276
|
+
plan: Record<string, unknown>,
|
|
277
|
+
waveId: string,
|
|
278
|
+
waveCount: number,
|
|
279
|
+
): boolean {
|
|
280
|
+
for (const key of ["scripts", "gates"] as const) {
|
|
281
|
+
const steps = plan[key];
|
|
282
|
+
if (!Array.isArray(steps)) continue;
|
|
283
|
+
for (const step of steps) {
|
|
284
|
+
if (!isRecord(step)) continue;
|
|
285
|
+
const stepWave = step.waveId;
|
|
286
|
+
const targetsWave =
|
|
287
|
+
stepWave === waveId || (stepWave === undefined && waveCount === 1);
|
|
288
|
+
if (
|
|
289
|
+
targetsWave &&
|
|
290
|
+
typeof step.handler === "string" &&
|
|
291
|
+
step.handler.trim().length > 0
|
|
292
|
+
) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
|
|
264
300
|
/**
|
|
265
301
|
* Validate and clone an untrusted RunPlan-shaped value. Wave IDs and agent IDs
|
|
266
302
|
* must be unique across the whole plan because core addresses agents by ID.
|
|
303
|
+
*
|
|
304
|
+
* A wave with no agents is accepted only when it explicitly reserves a hole or
|
|
305
|
+
* when a trusted script/gate step fills it. This keeps the direct workflow path
|
|
306
|
+
* usable for non-agent plans without inventing a second plan shape.
|
|
267
307
|
*/
|
|
268
308
|
export function normalizeRunPlan(
|
|
269
309
|
value: unknown,
|
|
@@ -281,6 +321,7 @@ export function normalizeRunPlan(
|
|
|
281
321
|
|
|
282
322
|
const waveIds = new Set<string>();
|
|
283
323
|
const agentIds = new Set<string>();
|
|
324
|
+
const waveCount = record.waves.length;
|
|
284
325
|
|
|
285
326
|
const waves: WaveSpec[] = record.waves.map((waveValue, waveIndex) => {
|
|
286
327
|
const wavePath = `${path}.waves[${waveIndex}]`;
|
|
@@ -299,8 +340,13 @@ export function normalizeRunPlan(
|
|
|
299
340
|
if (!Array.isArray(waveRecord.agents)) {
|
|
300
341
|
fail(`${wavePath}.agents`, "must be an array");
|
|
301
342
|
}
|
|
302
|
-
|
|
303
|
-
|
|
343
|
+
|
|
344
|
+
let hole: boolean | undefined;
|
|
345
|
+
if (waveRecord.hole !== undefined) {
|
|
346
|
+
if (typeof waveRecord.hole !== "boolean") {
|
|
347
|
+
fail(`${wavePath}.hole`, "must be a boolean");
|
|
348
|
+
}
|
|
349
|
+
hole = waveRecord.hole;
|
|
304
350
|
}
|
|
305
351
|
|
|
306
352
|
const agents = waveRecord.agents.map((agentValue, agentIndex) => {
|
|
@@ -313,7 +359,24 @@ export function normalizeRunPlan(
|
|
|
313
359
|
return spec;
|
|
314
360
|
});
|
|
315
361
|
|
|
316
|
-
|
|
362
|
+
if (agents.length === 0) {
|
|
363
|
+
if (hole === true) {
|
|
364
|
+
// A reserved hole is intentionally empty until work fills this wave.
|
|
365
|
+
} else if (!hasTrustedStep(record, id, waveCount)) {
|
|
366
|
+
fail(
|
|
367
|
+
`${wavePath}.agents`,
|
|
368
|
+
"must contain at least one agent, reserve a hole, or attach a trusted script or gate step",
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
} else if (hole === true) {
|
|
372
|
+
fail(`${wavePath}.agents`, "must be empty when the wave reserves a hole");
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const wave: WaveSpecWithHole = { id, agents };
|
|
376
|
+
if (hole !== undefined) {
|
|
377
|
+
wave.hole = hole;
|
|
378
|
+
}
|
|
379
|
+
return wave;
|
|
317
380
|
});
|
|
318
381
|
|
|
319
382
|
const plan: RunPlan = { waves };
|