@nylorun/core 0.7.0-beta → 0.8.0-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +37 -0
- package/dist/contracts.js +150 -3
- package/dist/define.d.ts +10 -2
- package/dist/define.js +5 -1
- package/dist/definition/assemble.js +7 -0
- package/dist/definition/builder.d.ts +122 -16
- package/dist/definition/builder.js +354 -53
- package/dist/definition/capability.d.ts +55 -0
- package/dist/definition/capability.js +104 -0
- package/dist/definition/delegate.d.ts +25 -4
- package/dist/definition/delegate.js +34 -6
- package/dist/definition/flow/compile.d.ts +25 -0
- package/dist/definition/flow/compile.js +302 -0
- package/dist/definition/flow/from.d.ts +11 -0
- package/dist/definition/flow/from.js +78 -0
- package/dist/definition/flow/index.d.ts +11 -0
- package/dist/definition/flow/index.js +11 -0
- package/dist/definition/flow/paths.d.ts +60 -0
- package/dist/definition/flow/paths.js +90 -0
- package/dist/definition/flow/spec.d.ts +66 -0
- package/dist/definition/flow/spec.js +130 -0
- package/dist/definition/flow/types.d.ts +159 -0
- package/dist/definition/flow/types.js +1 -0
- package/dist/definition/from.js +5 -1
- package/dist/definition/helpers.d.ts +1 -16
- package/dist/definition/helpers.js +1 -30
- package/dist/definition/mcp.d.ts +37 -0
- package/dist/definition/mcp.js +81 -0
- package/dist/definition/sandbox.d.ts +29 -0
- package/dist/definition/sandbox.js +93 -0
- package/dist/definition/workflow/loop.js +2 -2
- package/dist/definition/workflow/runnable.d.ts +13 -1
- package/dist/definition/workflow/runnable.js +11 -7
- package/dist/types/manifest.d.ts +4 -2
- package/dist/types/workflow.d.ts +72 -3
- package/dist/utils/deprecate.d.ts +3 -0
- package/dist/utils/deprecate.js +25 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,42 @@
|
|
|
1
1
|
# @nylorun/core
|
|
2
2
|
|
|
3
|
+
## 0.8.0-beta
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- e537a82: **One `Agent` builder: named methods and flow agents.** Every capability has its own method, and deterministic workflows are written on the same builder. ReAct agent manifests are unchanged: the new syntax compiles to exactly what the old syntax produced.
|
|
8
|
+
|
|
9
|
+
- ReAct agents: `.instructions()`, `.tools()`, `.subagents()`, `.mcp()` (a server's `name` defaults to its key; calls merge), `.skills()`, `.plugin()`, `.capability()`, `.sandbox()`, `.beforeTurn()`, `.beforeModel()`, `.afterModel()`, `.afterTurn()`, `.output()`. `capability({ id })` returns a builder with the same methods.
|
|
10
|
+
- Flow agents: `.step()`, `.switch({ ...cases, default }, { on })`, `.parallel()`, `.map()` (runs over its input), `.loop(body, { verify, max | decide })`, plus `.input()`, `.output()`, `.sandbox()`, `flow()` for nested sequences and `.withId()`. Functions receive `{ input, results, flowInput }`, typed from each step's output schema. A flow agent compiles to a workflow manifest (v2, see the flow-manifest-v2 changeset).
|
|
11
|
+
- Build diagnostics: `agent.mixed-body`, `flow.no-model`, `agent.single-value`, `flow.empty`, `loop.max-required`, `loop.invalid-max`, `mcp.duplicate-server`, `delegation.flow-unsupported`.
|
|
12
|
+
- `sandbox()` and `mcp()` move to `@nylorun/core/define` (still exported from `@nylorun/agents`).
|
|
13
|
+
- Deprecated, warning once each: options-form `instructions`/`tools`/`outputSchema` (`NYLORUN_DEP_AGENT_OPTIONS`), `.use(capability)` (`NYLORUN_DEP_USE`), `.before()`/`.after()` (`NYLORUN_DEP_HOOKS`), and `capability({ tools, instructions, … })` (`NYLORUN_DEP_CAPABILITY_OPTIONS`). See MIGRATION.md.
|
|
14
|
+
|
|
15
|
+
- 5278b4e: **Flow agents on workflow manifest v2.** A flow agent compiles to `workflowSchemaVersion: 2` and runs on the new `flow-2` engine; v1 workflows (`Chain`, `Switch`, `Parallel`, `Map`, `Loop`) keep running on `flow-1`, so in-flight runs finish as they began.
|
|
16
|
+
|
|
17
|
+
- **Manifest (core).** Any node may carry `id` and `input`; there are no slots. `chain` and `parallel` are bare collections, a Map is `{ map: { each } }` over its input, and a Loop has `max?` and `decide?`. The header adds `name`, `description`, `metadata`, `inputSchema` and `outputSchema`, and `agents` embeds every agent the flow runs, so one manifest hash covers the whole flow. `Agent.from(json, { nodes, agents })` rebuilds a flow agent. Path and key helpers (`leafPath`, `stageKey`, `forEachFlowNode`, `embeddedAgent`, …) are exported from `@nylorun/core/define`.
|
|
18
|
+
- **Paths (harness).** Linked agent sessions are named by the agent: its id, `[i]` per Map item, and a nested flow agent's id in front. Control stages add nothing, so wrapping a step in a Loop keeps its session. Functions are bound under stage keys (`route:on`, `@1.default.1:input`) and all receive `{ input, results, flowInput }`; `flowInput` works inside nested `flow()`. A Loop without `decide` retries with the verifier's feedback up to `max` and then fails with `loop.exhausted`. Nested flow agents run inline.
|
|
19
|
+
- **Runtime.** Leaves of a v2 workflow resolve from its embedded `agents` (with the workflow's plugin roots, keyed `<agent>/<capability>`) instead of the registry. `loop.iteration` is emitted only for a Loop's own agent turns.
|
|
20
|
+
- **Agents SDK.** `saveAgent(flowAgent)` PUTs one document; application mode registers the flow's executor with its manifest hash. An executor leaves `fn`, `verify` and tool actions of a v2 flow unclaimed when they belong to another manifest hash, because stage keys can shift between deploys; it reports each skipped action once through `onError`.
|
|
21
|
+
- **Studio.** Draws v2 manifests: agents and tools at their session paths, control stages at their stage keys, nested flow agents inline, and lights a Map's agent from its item sessions.
|
|
22
|
+
- Build diagnostics: `flow.duplicate-leaf`, `flow.duplicate-id`, `flow.agent-conflict`, `flow.v1-workflow`, `loop.invalid-verify`, `workflow.flow-agent-child`. Also fixes v1 flows passing an agent step's output to the next step still wrapped in the runtime's turn marker.
|
|
23
|
+
|
|
24
|
+
- 426fd27: **Flow agents as subagents.** `.subagents(flowAgent)` lets a ReAct agent delegate to a flow agent. The flow's workflow manifest v2 is inlined in the delegating tool (`ToolManifest.agent` may be a workflow manifest), so it is saved with the parent and served by the parent's executor, plugin roots included (`<flow>/<agent>/<capability>`).
|
|
25
|
+
|
|
26
|
+
- **Engine (harness).** A call to a flow subagent is one durable `agent` effect (`role: "delegate"`) between the delegation's start and settle points; the flow's output is the tool result, and a failed flow is a failed tool result. Local `run()` refuses flow subagents, which need the Runtime.
|
|
27
|
+
- **Runtime.** The effect starts a linked flow session from the parent's pinned manifest, fresh per call, and settles when the flow's turn ends. Cancelling any session now cascades to the linked sessions it started, not only a workflow's.
|
|
28
|
+
- **Core.** `delegation.flow-unsupported` now only reports a workflow built with `Chain`, `Switch`, `Parallel`, `Map` or `Loop`. New helpers: `flowDelegatesOf`, `flowDelegateManifest`, `isFlowDelegate`; `delegatesOf` lists only the ReAct agents run in-process.
|
|
29
|
+
|
|
30
|
+
### Patch Changes
|
|
31
|
+
|
|
32
|
+
- 8cda500: **Workflow functions and tool steps reach the executor.** Several workflow nodes asked the executor for a key that core never registered, so the executor never found the function and the turn waited forever.
|
|
33
|
+
|
|
34
|
+
- A Map's `over` and a slot's `input` now use the keys core registers (`<path>/over`, `<path>/input`), as Switch's `on` already did.
|
|
35
|
+
- A slot `input` that wraps a Map or Switch gets its own effect id, so it no longer collides with the `over` or `on` effect on the same path.
|
|
36
|
+
- A slot `id` that renames a nested workflow now renames the keys inside it too.
|
|
37
|
+
- A verifier slot's `input` is keyed under the verifier's path (`<loop>/<part>/input`).
|
|
38
|
+
- A tool step passes its output to the next step, not the `{ kind: "completed", output }` outcome around it. A denied tool call fails the flow with `tool.denied`.
|
|
39
|
+
|
|
3
40
|
## 0.7.0-beta
|
|
4
41
|
|
|
5
42
|
### Minor Changes
|
package/dist/contracts.js
CHANGED
|
@@ -92,7 +92,9 @@ const toolManifestSchema = z
|
|
|
92
92
|
description: z.string().optional(),
|
|
93
93
|
inputSchema: jsonObject,
|
|
94
94
|
outputSchema: jsonObject.optional(),
|
|
95
|
-
agent: z
|
|
95
|
+
agent: z
|
|
96
|
+
.lazy(() => z.union([workflowV2ManifestSchema, AgentManifestSchema]))
|
|
97
|
+
.optional(),
|
|
96
98
|
})
|
|
97
99
|
.strict();
|
|
98
100
|
const hookPointSchema = z
|
|
@@ -220,6 +222,20 @@ function delegationIssues(manifest, issue) {
|
|
|
220
222
|
const child = tool.agent;
|
|
221
223
|
if (!child)
|
|
222
224
|
continue;
|
|
225
|
+
if ("kind" in child) {
|
|
226
|
+
// A flow agent runs in its own linked session; its leaves may delegate in turn.
|
|
227
|
+
if (tool.name !== child.id)
|
|
228
|
+
issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
|
|
229
|
+
if (!child.description?.trim() || tool.description !== child.description)
|
|
230
|
+
issue(`Agent tool '${tool.name}' must carry the agent's non-empty description`);
|
|
231
|
+
if (canonical(tool.inputSchema) !== canonical(DELEGATE_INPUT_SCHEMA))
|
|
232
|
+
issue(`Agent tool '${tool.name}' must take the standard { task } input`);
|
|
233
|
+
if (tool.outputSchema !== undefined)
|
|
234
|
+
issue(`Agent tool '${tool.name}' must not declare outputSchema; the agent's outputSchema applies`);
|
|
235
|
+
if (child.sandbox !== undefined && Object.keys(child.sandbox).length > 0)
|
|
236
|
+
sandboxes.add(canonical(child.sandbox));
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
223
239
|
if (tool.name !== child.id)
|
|
224
240
|
issue(`Tool '${tool.name}' must be named after the agent it runs ('${child.id}')`);
|
|
225
241
|
if (!child.description?.trim() || tool.description !== child.description)
|
|
@@ -333,8 +349,7 @@ const workflowNodeSchema = z.lazy(() => z.union([
|
|
|
333
349
|
})
|
|
334
350
|
.strict(),
|
|
335
351
|
]));
|
|
336
|
-
|
|
337
|
-
export const WorkflowManifestSchema = z
|
|
352
|
+
const workflowV1ManifestSchema = z
|
|
338
353
|
.object({
|
|
339
354
|
kind: z.literal("workflow"),
|
|
340
355
|
workflowSchemaVersion: z.literal(1),
|
|
@@ -343,6 +358,138 @@ export const WorkflowManifestSchema = z
|
|
|
343
358
|
sandbox: sandboxManifestSchema.optional(),
|
|
344
359
|
})
|
|
345
360
|
.strict();
|
|
361
|
+
// v2 (Flow Agents): `id` and `input` on any node, no slots, embedded agents.
|
|
362
|
+
const workflowNodeOptionsV2 = {
|
|
363
|
+
id: z.string().min(1).optional(),
|
|
364
|
+
input: workflowFnRefSchema.optional(),
|
|
365
|
+
};
|
|
366
|
+
const workflowAgentNodeV2Schema = z
|
|
367
|
+
.object({ agent: z.string().min(1), ...workflowNodeOptionsV2 })
|
|
368
|
+
.strict();
|
|
369
|
+
const workflowNodeV2Schema = z.lazy(() => z.union([
|
|
370
|
+
workflowAgentNodeV2Schema,
|
|
371
|
+
z
|
|
372
|
+
.object({
|
|
373
|
+
tool: z
|
|
374
|
+
.object({
|
|
375
|
+
name: z.string().min(1),
|
|
376
|
+
description: z.string().optional(),
|
|
377
|
+
inputSchema: jsonObject.optional(),
|
|
378
|
+
outputSchema: jsonObject.optional(),
|
|
379
|
+
})
|
|
380
|
+
.strict(),
|
|
381
|
+
...workflowNodeOptionsV2,
|
|
382
|
+
})
|
|
383
|
+
.strict(),
|
|
384
|
+
z.object({ chain: z.array(workflowNodeV2Schema).min(1), ...workflowNodeOptionsV2 }).strict(),
|
|
385
|
+
z
|
|
386
|
+
.object({
|
|
387
|
+
switch: z
|
|
388
|
+
.object({
|
|
389
|
+
on: workflowFnRefSchema,
|
|
390
|
+
cases: z.record(z.string(), workflowNodeV2Schema),
|
|
391
|
+
default: workflowNodeV2Schema.optional(),
|
|
392
|
+
})
|
|
393
|
+
.strict(),
|
|
394
|
+
...workflowNodeOptionsV2,
|
|
395
|
+
})
|
|
396
|
+
.strict(),
|
|
397
|
+
z
|
|
398
|
+
.object({
|
|
399
|
+
parallel: z
|
|
400
|
+
.record(z.string(), workflowNodeV2Schema)
|
|
401
|
+
.refine((branches) => Object.keys(branches).length > 0, {
|
|
402
|
+
message: "parallel needs at least one branch",
|
|
403
|
+
}),
|
|
404
|
+
...workflowNodeOptionsV2,
|
|
405
|
+
})
|
|
406
|
+
.strict(),
|
|
407
|
+
z
|
|
408
|
+
.object({
|
|
409
|
+
map: z.object({ each: workflowNodeV2Schema }).strict(),
|
|
410
|
+
...workflowNodeOptionsV2,
|
|
411
|
+
})
|
|
412
|
+
.strict(),
|
|
413
|
+
z
|
|
414
|
+
.object({
|
|
415
|
+
loop: z
|
|
416
|
+
.object({
|
|
417
|
+
run: workflowNodeV2Schema,
|
|
418
|
+
verify: z.union([workflowFnRefSchema, workflowAgentNodeV2Schema]),
|
|
419
|
+
max: z.number().int().positive().optional(),
|
|
420
|
+
decide: workflowFnRefSchema.optional(),
|
|
421
|
+
})
|
|
422
|
+
.strict()
|
|
423
|
+
.refine((loop) => loop.max !== undefined || loop.decide !== undefined, {
|
|
424
|
+
message: "loop needs max or decide",
|
|
425
|
+
}),
|
|
426
|
+
...workflowNodeOptionsV2,
|
|
427
|
+
})
|
|
428
|
+
.strict(),
|
|
429
|
+
]));
|
|
430
|
+
const workflowV2ManifestSchema = z.lazy(() => z
|
|
431
|
+
.object({
|
|
432
|
+
kind: z.literal("workflow"),
|
|
433
|
+
workflowSchemaVersion: z.literal(2),
|
|
434
|
+
id: z.string().min(1),
|
|
435
|
+
name: z.string().min(1).optional(),
|
|
436
|
+
description: z.string().optional(),
|
|
437
|
+
metadata: jsonObject.optional(),
|
|
438
|
+
inputSchema: jsonObject.optional(),
|
|
439
|
+
outputSchema: jsonObject.optional(),
|
|
440
|
+
sandbox: sandboxManifestSchema.optional(),
|
|
441
|
+
root: workflowNodeV2Schema,
|
|
442
|
+
agents: z.record(z.string().min(1), z.union([workflowV2ManifestSchema, AgentManifestSchema])),
|
|
443
|
+
})
|
|
444
|
+
.strict()
|
|
445
|
+
.superRefine((manifest, ctx) => {
|
|
446
|
+
for (const agentId of referencedAgents(manifest.root)) {
|
|
447
|
+
if (!(agentId in manifest.agents))
|
|
448
|
+
ctx.addIssue({
|
|
449
|
+
code: "custom",
|
|
450
|
+
path: ["agents"],
|
|
451
|
+
message: `Agent '${agentId}' is used in the flow but not embedded in agents`,
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
for (const [key, agent] of Object.entries(manifest.agents)) {
|
|
455
|
+
if (agent.id !== key)
|
|
456
|
+
ctx.addIssue({
|
|
457
|
+
code: "custom",
|
|
458
|
+
path: ["agents", key],
|
|
459
|
+
message: `Embedded agent '${agent.id}' must be keyed by its id`,
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}));
|
|
463
|
+
function referencedAgents(node) {
|
|
464
|
+
const out = [];
|
|
465
|
+
const visit = (child) => {
|
|
466
|
+
if ("agent" in child)
|
|
467
|
+
out.push(child.agent);
|
|
468
|
+
else if ("chain" in child)
|
|
469
|
+
child.chain.forEach(visit);
|
|
470
|
+
else if ("switch" in child) {
|
|
471
|
+
Object.values(child.switch.cases).forEach(visit);
|
|
472
|
+
if (child.switch.default)
|
|
473
|
+
visit(child.switch.default);
|
|
474
|
+
}
|
|
475
|
+
else if ("parallel" in child)
|
|
476
|
+
Object.values(child.parallel).forEach(visit);
|
|
477
|
+
else if ("map" in child)
|
|
478
|
+
visit(child.map.each);
|
|
479
|
+
else if ("loop" in child) {
|
|
480
|
+
visit(child.loop.run);
|
|
481
|
+
if ("agent" in child.loop.verify)
|
|
482
|
+
visit(child.loop.verify);
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
visit(node);
|
|
486
|
+
return out;
|
|
487
|
+
}
|
|
488
|
+
/** Workflow definition document. `kind: "workflow"`; a missing `kind` is never a workflow. */
|
|
489
|
+
export const WorkflowManifestSchema = z.union([
|
|
490
|
+
workflowV1ManifestSchema,
|
|
491
|
+
workflowV2ManifestSchema,
|
|
492
|
+
]);
|
|
346
493
|
/** Registry document: agent (no `kind`, or legacy) or workflow (`kind: "workflow"`). */
|
|
347
494
|
export const DefinitionDocumentSchema = z.union([
|
|
348
495
|
AgentManifestSchema,
|
package/dist/define.d.ts
CHANGED
|
@@ -3,9 +3,17 @@ export type { AgentOptions } from "./definition/builder.js";
|
|
|
3
3
|
export { HarnessError, isHarnessError } from "./errors.js";
|
|
4
4
|
export type { HarnessErrorCode, HarnessErrorDetails, HarnessErrorOptions, } from "./errors.js";
|
|
5
5
|
export type { AgentTool, BuiltAgent } from "./types/agent.js";
|
|
6
|
-
export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, } from "./definition/delegate.js";
|
|
6
|
+
export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
|
|
7
7
|
export type { Delegate } from "./definition/delegate.js";
|
|
8
8
|
export { capability, middleware, model, tool } from "./definition/helpers.js";
|
|
9
|
+
export { sandbox, SandboxError } from "./definition/sandbox.js";
|
|
10
|
+
export type { SandboxCapability, SandboxCapabilityOptions, SandboxOptions, } from "./definition/sandbox.js";
|
|
11
|
+
export { mcp, McpError, normalizeMcpServers } from "./definition/mcp.js";
|
|
12
|
+
export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
|
|
13
|
+
export type { CapabilityIdentity, CapabilityOptions } from "./definition/capability.js";
|
|
14
|
+
export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, forEachFlowNode, functionKey, indexSuffix, isLeafNode, isWorkflowManifestV2, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
|
|
15
|
+
export type { FlowAgentBuilder, Flow, Named, StageArgs, NestedStageArgs, FlowOut, LoopChoice, LoopDecideArgs as FlowLoopDecideArgs, LoopVerifyFn as FlowLoopVerifyFn, FlowFunctionRole, FlowNodeVisit, FlowImplementations, } from "./definition/flow/index.js";
|
|
16
|
+
export type { McpCapability, McpOptions, McpServerSpec } from "./definition/mcp.js";
|
|
9
17
|
export { ToolError, isToolError } from "./definition/tool-error.js";
|
|
10
18
|
export { defineSchema } from "./definition/schema.js";
|
|
11
19
|
export { hashManifest } from "./utils/hash.js";
|
|
@@ -28,7 +36,7 @@ export type { AgentBinding } from "./definition/binding.js";
|
|
|
28
36
|
export { Loop, Chain, Switch, Parallel, Map, VerdictSchema, isVerdict, withInstructions, withoutTools, WorkflowBuildError, isSlot, isBuiltWorkflow, } from "./definition/workflow/index.js";
|
|
29
37
|
export type { BuiltWorkflow, OutputOf, InputOf, LoopOptions, LoopRunnable, LoopVerify, LoopVerifyFn, LoopDecideFn, LoopVerifyArgs, LoopDecideArgs, LoopDecision, ChainOptions, ChainStep, ChainResults, ChainSlot, SwitchOptions, SwitchCases, ParallelOptions, ParallelBranches, MapOptions, MapOver, Slot, SlotInputArgs, WorkflowRunnable, } from "./definition/workflow/index.js";
|
|
30
38
|
export { isVariantOf } from "./definition/variant.js";
|
|
31
|
-
export type { Verdict, WorkflowBinding, WorkflowManifest } from "./types/workflow.js";
|
|
39
|
+
export type { Verdict, WorkflowBinding, WorkflowManifest, WorkflowManifestV1, WorkflowManifestV2, WorkflowNodeV2, } from "./types/workflow.js";
|
|
32
40
|
export type { BoundMiddleware, BoundToolDefinition, } from "./definition/bound.js";
|
|
33
41
|
export { bindTool } from "./definition/bind-tool.js";
|
|
34
42
|
export { bindOutputContract } from "./definition/output-contract.js";
|
package/dist/define.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
export { Agent, AgentBuilder, AgentBuildError, AgentLifecycleError, } from "./definition/builder.js";
|
|
2
2
|
export { HarnessError, isHarnessError } from "./errors.js";
|
|
3
|
-
export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, } from "./definition/delegate.js";
|
|
3
|
+
export { DELEGATE_INPUT_SCHEMA, delegateManifest, delegateOf, delegatesOf, flowDelegatesOf, flowDelegateManifest, isFlowDelegate, } from "./definition/delegate.js";
|
|
4
4
|
export { capability, middleware, model, tool } from "./definition/helpers.js";
|
|
5
|
+
export { sandbox, SandboxError } from "./definition/sandbox.js";
|
|
6
|
+
export { mcp, McpError, normalizeMcpServers } from "./definition/mcp.js";
|
|
7
|
+
export { CapabilityBuilder, isCapabilityBuilder } from "./definition/capability.js";
|
|
8
|
+
export { flow, FlowBuilder, isFlowBuilder, ROOT_POSITION, childPosition, embeddedAgent, forEachFlowNode, functionKey, indexSuffix, isLeafNode, isWorkflowManifestV2, leafPart, leafPath, stageKey, stripIndices, } from "./definition/flow/index.js";
|
|
5
9
|
export { ToolError, isToolError } from "./definition/tool-error.js";
|
|
6
10
|
export { defineSchema } from "./definition/schema.js";
|
|
7
11
|
export { hashManifest } from "./utils/hash.js";
|
|
@@ -111,6 +111,13 @@ function delegationDiagnostics(items) {
|
|
|
111
111
|
found.push(diagnostic("delegation.invalid-name", `Agent '${child.id}' is used as a tool, so its id must be 1-64 letters, digits, '_' or '-'`, extra));
|
|
112
112
|
if (!child.description?.trim())
|
|
113
113
|
found.push(diagnostic("delegation.description-required", `Agent '${child.id}' is used as a tool by capability '${item.id}' and needs a description: the parent's model reads it to decide when to delegate`, extra));
|
|
114
|
+
if (child.kind === "workflow") {
|
|
115
|
+
// A flow agent runs in its own linked session; its agents may delegate in turn.
|
|
116
|
+
const spec = child.sandbox;
|
|
117
|
+
if (spec && Object.keys(spec).length > 0)
|
|
118
|
+
sandboxes.add(canonical(spec));
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
114
121
|
const nested = delegatesOf(child)[0];
|
|
115
122
|
if (nested)
|
|
116
123
|
found.push(diagnostic("delegation.nested", `'${child.id}' delegates to '${nested.manifest.id}'; nested delegation is not supported yet`, extra));
|
|
@@ -4,30 +4,49 @@ import type { BuildDiagnostic, JsonObject } from "../types/shared.js";
|
|
|
4
4
|
import { HarnessError } from "../errors.js";
|
|
5
5
|
import type { ToolDefinition, ToolSchemaSource, SchemaOutput } from "../types/tool.js";
|
|
6
6
|
import type { AgentTool, BuiltAgent } from "../types/agent.js";
|
|
7
|
-
import type { AgentManifest } from "../types/manifest.js";
|
|
7
|
+
import type { AgentManifest, McpServerManifest, SandboxManifest } from "../types/manifest.js";
|
|
8
|
+
import type { WorkflowBinding, WorkflowManifest } from "../types/workflow.js";
|
|
8
9
|
import type { AfterHook, BeforeHook, HookScope } from "../types/dynamics.js";
|
|
9
10
|
import type { Implementations } from "./implementations.js";
|
|
10
11
|
import { type CapabilityDynamics } from "./assemble.js";
|
|
12
|
+
import { type McpServerSpec } from "./mcp.js";
|
|
13
|
+
import { type FlowImplementations } from "./flow/from.js";
|
|
14
|
+
import { type BuiltWorkflow } from "./workflow/types.js";
|
|
15
|
+
import { type FlowStage } from "./flow/spec.js";
|
|
16
|
+
import type { AddResult, BranchesOut, CaseKey, CasesOut, FlowAgentBuilder, FlowOut, IdOf, LoopChoice, LoopDecideArgs, LoopVerifyFn, Named, StageArgs } from "./flow/types.js";
|
|
11
17
|
export interface AgentOptions<Schema extends ToolSchemaSource | undefined = undefined> {
|
|
18
|
+
/** @deprecated Use `.output(schema)`. */
|
|
12
19
|
readonly outputSchema?: Schema;
|
|
13
20
|
readonly id: string;
|
|
14
21
|
readonly name?: string;
|
|
15
22
|
readonly description?: string;
|
|
16
23
|
readonly metadata?: JsonObject;
|
|
24
|
+
/** @deprecated Use `.instructions(...)`. */
|
|
17
25
|
readonly instructions?: string | readonly string[];
|
|
18
|
-
/**
|
|
26
|
+
/** @deprecated Use `.tools(...)` and `.subagents(...)`. */
|
|
19
27
|
readonly tools?: readonly (ToolDefinition<any, any, any> | AgentTool)[];
|
|
20
28
|
}
|
|
29
|
+
type Body = "none" | "react" | "flow";
|
|
21
30
|
interface BuilderSnapshot {
|
|
22
31
|
readonly id: string;
|
|
23
32
|
readonly name?: string;
|
|
24
33
|
readonly description?: string;
|
|
25
34
|
readonly metadata?: JsonObject;
|
|
26
35
|
readonly outputSchema?: ToolSchemaSource;
|
|
36
|
+
readonly inputSchema?: ToolSchemaSource;
|
|
27
37
|
readonly entries: readonly BoundMiddleware[];
|
|
28
38
|
readonly dynamics: ReadonlyMap<string, CapabilityDynamics>;
|
|
29
39
|
/** Builder-level problems, reported with the assembly diagnostics. */
|
|
30
40
|
readonly diagnostics?: readonly BuildDiagnostic[];
|
|
41
|
+
readonly body: Body;
|
|
42
|
+
/** Raw items of the `"agent"` capability, so later calls can add to it. */
|
|
43
|
+
readonly agentPart?: {
|
|
44
|
+
readonly instructions?: readonly string[];
|
|
45
|
+
readonly tools?: readonly (ToolDefinition<any, any, any> | AgentTool)[];
|
|
46
|
+
};
|
|
47
|
+
readonly mcpServers?: Readonly<Record<string, McpServerManifest>>;
|
|
48
|
+
readonly sandbox?: SandboxManifest;
|
|
49
|
+
readonly stages: readonly FlowStage[];
|
|
31
50
|
}
|
|
32
51
|
export declare class AgentBuildError extends HarnessError {
|
|
33
52
|
readonly diagnostics: readonly BuildDiagnostic[];
|
|
@@ -36,39 +55,126 @@ export declare class AgentBuildError extends HarnessError {
|
|
|
36
55
|
export declare class AgentLifecycleError extends HarnessError {
|
|
37
56
|
constructor(message: string);
|
|
38
57
|
}
|
|
39
|
-
export declare function Agent<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined>(options: AgentOptions<Schema>
|
|
58
|
+
export declare function Agent<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined, const Id extends string = string>(options: AgentOptions<Schema> & {
|
|
59
|
+
readonly id: Id;
|
|
60
|
+
}): AgentBuilder<Info, Schema, Id>;
|
|
40
61
|
export declare namespace Agent {
|
|
62
|
+
/** Rebuild a flow agent from its workflow manifest v2 and the code its stage keys name. */
|
|
63
|
+
function from(json: import("../types/workflow.js").WorkflowManifestV2, implementations?: FlowImplementations): BuiltWorkflow;
|
|
64
|
+
/** Rebuild an agent from its manifest and the code its capabilities name. */
|
|
41
65
|
function from<Info = unknown>(json: AgentManifest | import("../types/shared.js").JsonObject, implementations: Implementations<Info>): BuiltAgent<Info>;
|
|
42
66
|
}
|
|
43
67
|
declare const SNAPSHOT: unique symbol;
|
|
44
|
-
|
|
68
|
+
type SchemaOut<Schema> = Schema extends ToolSchemaSource ? SchemaOutput<Schema> : never;
|
|
69
|
+
type ReactOutput<Schema> = Schema extends ToolSchemaSource ? SchemaOutput<Schema> : string;
|
|
70
|
+
type StartFlow<Info, Schema, Id extends string, Cur, Results> = FlowAgentBuilder<Info, any, Cur, Results, SchemaOut<Schema>, Id>;
|
|
71
|
+
export declare class AgentBuilder<Info = unknown, Schema extends ToolSchemaSource | undefined = undefined, Id extends string = string> {
|
|
45
72
|
#private;
|
|
73
|
+
/** Phantom carriers for flow typing (never set at runtime). */
|
|
74
|
+
readonly __output?: ReactOutput<Schema>;
|
|
75
|
+
readonly __id?: Id;
|
|
46
76
|
getBinding(): import("./binding.js").AgentBinding;
|
|
47
77
|
constructor(options: AgentOptions<Schema>);
|
|
48
78
|
/** @internal */
|
|
49
79
|
constructor(snapshot: BuilderSnapshot, brand: typeof SNAPSHOT);
|
|
50
|
-
static create<Info, Schema extends ToolSchemaSource | undefined>(options: AgentOptions<Schema>): AgentBuilder<Info, Schema>;
|
|
51
|
-
|
|
80
|
+
static create<Info, Schema extends ToolSchemaSource | undefined, Id extends string = string>(options: AgentOptions<Schema>): AgentBuilder<Info, Schema, Id>;
|
|
81
|
+
/** @internal True for an agent whose body is a flow. */
|
|
82
|
+
static isFlowAgent(value: unknown): boolean;
|
|
83
|
+
/** A new builder of the same class (subclasses survive chaining). */
|
|
84
|
+
protected spawn(snapshot: BuilderSnapshot): this;
|
|
52
85
|
/** Compose-time identity — available before `.build()`. */
|
|
53
|
-
get id():
|
|
86
|
+
get id(): Id;
|
|
54
87
|
get name(): string | undefined;
|
|
55
88
|
get manifest(): AgentManifest;
|
|
89
|
+
/** A flow agent's input and output schemas (local; not on the v1 wire). */
|
|
90
|
+
get inputSchema(): ToolSchemaSource | undefined;
|
|
91
|
+
get outputSchema(): ToolSchemaSource | undefined;
|
|
56
92
|
toJSON(): AgentManifest;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
93
|
+
/** Add instructions. Repeated calls add more. */
|
|
94
|
+
instructions(...text: readonly string[]): this;
|
|
95
|
+
/** Add tools. Repeated calls add more. Agents belong in `.subagents()`. */
|
|
96
|
+
tools(...tools: readonly (ToolDefinition<any, any, any> | AgentTool)[]): this;
|
|
97
|
+
/** Add agents the model may delegate a self-contained task to. */
|
|
98
|
+
subagents(...agents: readonly AgentTool[]): this;
|
|
99
|
+
/** Declare MCP servers. A server's `name` defaults to its key; calls merge. */
|
|
100
|
+
mcp(servers: Readonly<Record<string, McpServerSpec>>): this;
|
|
101
|
+
/** Attach a reusable bundle made with `capability({ id })`. */
|
|
102
|
+
capability(bundle: CapabilityInput<Info> | {
|
|
103
|
+
toDeclaration(): CapabilityInput<Info>;
|
|
104
|
+
}): this;
|
|
60
105
|
/**
|
|
106
|
+
* Give the agent a Runtime-owned sandbox. On a flow agent, declares the one sandbox
|
|
107
|
+
* every agent in the flow shares.
|
|
108
|
+
*/
|
|
109
|
+
sandbox(spec?: SandboxManifest): this;
|
|
110
|
+
/** Run `fn` before each turn. */
|
|
111
|
+
beforeTurn(fn: BeforeHook<"turn", Info>): this;
|
|
112
|
+
/** Run `fn` before every model call. */
|
|
113
|
+
beforeModel(fn: BeforeHook<"step", Info>): this;
|
|
114
|
+
/** Run `fn` after every model call. */
|
|
115
|
+
afterModel(fn: AfterHook<"step", Info>): this;
|
|
116
|
+
/** Run `fn` after the turn's final answer. */
|
|
117
|
+
afterTurn(fn: AfterHook<"turn", Info>): this;
|
|
118
|
+
/** The structured output. Set once. */
|
|
119
|
+
output<S extends ToolSchemaSource>(schema: S): AgentBuilder<Info, S, Id>;
|
|
120
|
+
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()`, `.plugin()` or `.sandbox()`. */
|
|
121
|
+
use(middleware: StepMiddleware<Info>): this;
|
|
122
|
+
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()`, `.plugin()` or `.sandbox()`. */
|
|
123
|
+
use(id: string, middleware: StepMiddleware<Info>): this;
|
|
124
|
+
/** @deprecated Use `.capability()`, `.mcp()`, `.skills()`, `.plugin()` or `.sandbox()`. */
|
|
125
|
+
use(declaration: CapabilityInput<Info>): this;
|
|
126
|
+
/**
|
|
127
|
+
* @deprecated Use `.beforeTurn()` or `.beforeModel()`.
|
|
61
128
|
* Run `fn` before each turn (`"turn"`) or before every model call (`"step"`).
|
|
62
|
-
* The returned Patch applies to the whole turn or to that one model call.
|
|
63
129
|
*/
|
|
64
|
-
before<S extends HookScope>(scope: S, fn: BeforeHook<S, Info>):
|
|
130
|
+
before<S extends HookScope>(scope: S, fn: BeforeHook<S, Info>): this;
|
|
65
131
|
/**
|
|
132
|
+
* @deprecated Use `.afterModel()` or `.afterTurn()`.
|
|
66
133
|
* Run `fn` after every model call (`"step"`) or after the turn's final answer (`"turn"`).
|
|
67
134
|
*/
|
|
68
|
-
after<S extends HookScope>(scope: S, fn: AfterHook<S, Info>):
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
135
|
+
after<S extends HookScope>(scope: S, fn: AfterHook<S, Info>): this;
|
|
136
|
+
/** The flow agent's input. Set once. */
|
|
137
|
+
input<S extends ToolSchemaSource>(schema: S): FlowAgentBuilder<Info, SchemaOutput<S>, SchemaOutput<S>, {}, SchemaOut<Schema>, Id>;
|
|
138
|
+
step<C, const StepId extends string = IdOf<C>>(child: C, options?: {
|
|
139
|
+
readonly id?: StepId;
|
|
140
|
+
readonly input?: (args: StageArgs<any, {}, any>) => unknown;
|
|
141
|
+
}): StartFlow<Info, Schema, Id, FlowOut<C>, AddResult<{}, StepId, FlowOut<C>>>;
|
|
142
|
+
switch<const Cases extends Readonly<Record<string, unknown>>, T, const StageId extends string = string>(cases: Cases, options: {
|
|
143
|
+
readonly input: (args: StageArgs<any, {}, any>) => T;
|
|
144
|
+
readonly on: (args: StageArgs<T, {}, any>) => CaseKey<Cases>;
|
|
145
|
+
readonly id?: StageId;
|
|
146
|
+
}): StartFlow<Info, Schema, Id, CasesOut<Cases>, AddResult<{}, StageId, CasesOut<Cases>>>;
|
|
147
|
+
switch<const Cases extends Readonly<Record<string, unknown>>, const StageId extends string = string>(cases: Cases, options: {
|
|
148
|
+
readonly on: (args: StageArgs<any, {}, any>) => CaseKey<Cases>;
|
|
149
|
+
readonly id?: StageId;
|
|
150
|
+
}): StartFlow<Info, Schema, Id, CasesOut<Cases>, AddResult<{}, StageId, CasesOut<Cases>>>;
|
|
151
|
+
parallel<const Branches extends Readonly<Record<string, unknown>>, const StageId extends string = string>(branches: Branches, options?: {
|
|
152
|
+
readonly id?: StageId;
|
|
153
|
+
readonly input?: (args: StageArgs<any, {}, any>) => unknown;
|
|
154
|
+
}): StartFlow<Info, Schema, Id, BranchesOut<Branches>, AddResult<{}, StageId, BranchesOut<Branches>>>;
|
|
155
|
+
map<E, const StageId extends string = string>(each: E, options?: {
|
|
156
|
+
readonly id?: StageId;
|
|
157
|
+
readonly input?: (args: StageArgs<any, {}, any>) => readonly unknown[];
|
|
158
|
+
}): StartFlow<Info, Schema, Id, FlowOut<E>[], AddResult<{}, StageId, FlowOut<E>[]>>;
|
|
159
|
+
loop<B, const StageId extends string = string>(body: B, options: {
|
|
160
|
+
readonly verify: LoopVerifyFn<any, FlowOut<B>> | object;
|
|
161
|
+
readonly max?: number;
|
|
162
|
+
readonly decide?: (args: LoopDecideArgs<any, FlowOut<B>>) => LoopChoice<FlowOut<B>>;
|
|
163
|
+
readonly id?: StageId;
|
|
164
|
+
readonly input?: (args: StageArgs<any, {}, any>) => unknown;
|
|
165
|
+
}): StartFlow<Info, Schema, Id, FlowOut<B>, AddResult<{}, StageId, FlowOut<B>>>;
|
|
166
|
+
/** Give this agent a new step id where there is no options object. */
|
|
167
|
+
withId(id: string): Named<this>;
|
|
168
|
+
/** Optional no-op: returns the assembled agent facade (a workflow for flow agents). */
|
|
169
|
+
build(): BuiltAgent<Info, ReactOutput<Schema>>;
|
|
72
170
|
private ensure;
|
|
171
|
+
/** Record which body a method belongs to; mixing bodies is a build error. */
|
|
172
|
+
private bodyFor;
|
|
173
|
+
private addStage;
|
|
174
|
+
private withAgentItems;
|
|
175
|
+
private addDeclaration;
|
|
176
|
+
private appendCompiled;
|
|
177
|
+
private addAgentHook;
|
|
73
178
|
}
|
|
74
179
|
export type { Implementations };
|
|
180
|
+
export type { WorkflowBinding, WorkflowManifest };
|