Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

feat(eve): support routed agent tool overrides (#3512)

Casey Gowriecbfc425efb21
diff --git a/.changeset/expose-root-workflow-agent.md b/.changeset/expose-root-workflow-agent.md
new file mode 100644
index 000000000..b2b68f11e
--- /dev/null
+++ b/.changeset/expose-root-workflow-agent.md
@@ -0,0 +1,5 @@
+---
+"eve": minor
+---
+
+Root workflow tools now receive the built-in root-copy target at `ctx.agents.agent`, with its authored description or an empty string, and `agent` is reserved from use as a declared subagent name. Tool definitions can set `availableInSubagents: false`; `agentRouter()` sets it automatically, routes only to entries with non-empty descriptions, and can replace the model-facing tool at `agent/tools/agent.ts` without being inherited by the root copy.
diff --git a/docs/concepts/built-in-tools.md b/docs/concepts/built-in-tools.md
index b90fe958a..f6980844d 100644
--- a/docs/concepts/built-in-tools.md
+++ b/docs/concepts/built-in-tools.md
@@ -291,7 +291,7 @@ eve add tool/agent
export { default } from "eve/tools/agent";
```
-The framework behavior cannot be overridden. Re-export the definition above to restore it, or disable it:
+An authored tool at `agent/tools/agent.ts` replaces the framework behavior. Re-export the definition above to restore direct root-copy delegation, export another tool such as `agentRouter()` to change the model-facing behavior, or disable the slot:
```ts title="agent/tools/agent.ts"
import { disableTool } from "eve/tools";
diff --git a/docs/reference/typescript-api.md b/docs/reference/typescript-api.md
index c412c4532..025f8e0cf 100644
--- a/docs/reference/typescript-api.md
+++ b/docs/reference/typescript-api.md
@@ -108,7 +108,7 @@ import template from "../../prompts/template.txt?raw";
| `ctx.getToken(provider)` | Resolve a bearer token for an inline auth provider such as `connect("...")` |
| `ctx.requireAuth(provider)` | Evict and re-authorize an inline provider, commonly after a downstream `401` |
-Authored workflow tools also receive `ctx.agents`, a replay-stable map of effective declared-subagent descriptions, and `ctx.agent(name, input)` for invocation. See [Workflows as tools](../tools/workflows#delegate-work-ctxagent) for the workflow-only context.
+Tool definitions accept `availableInSubagents: false` to restrict the tool to top-level root sessions. Authored workflow tools also receive `ctx.agents`, a replay-stable map of callable-agent metadata, and `ctx.agent(name, input)` for invocation. The root-copy `agent` entry has an empty description when the root omits `description`. See [Workflows as tools](../tools/workflows#delegate-work-ctxagent) for the workflow-only context.
## Imports at a glance
diff --git a/docs/subagents/index.mdx b/docs/subagents/index.mdx
index 906b782c6..3dc153e9d 100644
--- a/docs/subagents/index.mdx
+++ b/docs/subagents/index.mdx
@@ -49,7 +49,7 @@ export default defineAgent({
});
```
-You can also export `disableTool()` from `agent/tools/agent.ts`. An authored root tool at that path takes priority over `tool: false` and the built-in.
+You can also export `disableTool()` from `agent/tools/agent.ts`. Any authored tool at that path replaces the model-facing framework tool and takes priority over `tool: false`; re-export `eve/tools/agent` to keep direct root-copy delegation. Tool composition does not change the callable-agent registry: a workflow in a top-level root session can still invoke the root copy with `ctx.agent("agent", ...)` and read its description from `ctx.agents.agent`.
## Declared subagents
@@ -64,7 +64,7 @@ export default defineAgent({
});
```
-`description` is required. The parent reads it to decide whether to delegate, so the compiler rejects any subagent whose `agent.ts` leaves it out. Set `tool: false` to keep the subagent out of the parent model's tools while allowing an authored [workflow tool](/docs/tools/workflows) to call it by name through `ctx.agent()`:
+`description` is required. The parent reads it to decide whether to delegate, so the compiler rejects any subagent whose `agent.ts` leaves it out. The path-derived invocation name `agent` is reserved for the built-in root-copy target; rename a declared subagent at `agent/subagents/agent/`. Namespaced names such as `crm__agent` do not collide and remain valid. Set `tool: false` to keep the subagent out of the parent model's tools while allowing an authored [workflow tool](/docs/tools/workflows) to call it by name through `ctx.agent()`:
```ts title="agent/subagents/researcher/agent.ts"
import { defineAgent } from "eve";
@@ -216,7 +216,7 @@ eve lowers every tool-enabled subagent visible to the current agent (the root bu
Declared subagents can call nested subagents defined under their own directories. eve does not apply a separate depth limit; nesting ends where the authored directory tree ends. The built-in `agent` follows the stricter root-only rule above, so `limits.maxSubagentDepth` no longer exists.
-Child sessions can still call their own declared or remote subagents, but they do not receive the built-in `agent`. Authored workflow tools use the same subagent availability and authorization checks as direct delegation.
+Child sessions can still call their own declared or remote subagents, but they do not receive the built-in `agent`. Authored workflow tools use the same subagent availability and authorization checks as direct delegation. In a delegated root copy, `ctx.agents` also omits `agent`, so a router cannot select another root copy recursively.
A directly declared subagent's tool name is the bare path-derived name, with no prefix. `agent/subagents/researcher/` registers as the tool `researcher`. A subagent supplied by a mounted extension includes the mount namespace, such as `crm__reviewer`. The model, approvals, logs, and evals reference the resulting name. Its input schema is:
diff --git a/docs/tools/overview.mdx b/docs/tools/overview.mdx
index 6cedae1ff..808428143 100644
--- a/docs/tools/overview.mdx
+++ b/docs/tools/overview.mdx
@@ -32,6 +32,23 @@ A tool definition needs:
When a tool returns structured data, add an optional `outputSchema`. With Zod or Standard Schema it also types the `execute` return.
+### Hide a tool from delegated agents
+
+Set `availableInSubagents: false` when a tool should be callable only in a top-level root session:
+
+```ts title="agent/tools/coordinator.ts"
+export default defineTool({
+ availableInSubagents: false,
+ description: "Coordinate work that only the top-level root agent should start.",
+ inputSchema: z.object({ task: z.string() }),
+ execute({ task }) {
+ return coordinate(task);
+ },
+});
+```
+
+The option defaults to `true` and works with `defineTool` and `defineWorkflowTool`. A root copy does not receive a tool with this option, and a tool authored inside a declared subagent is unavailable because that agent runs in a delegated session. This controls tool availability only; it does not add or remove entries from a workflow's `ctx.agents` registry.
+
Compiled tools preserve Zod schema composition, including input and output schemas imported from helper modules. Durable replay metadata stays separate from the original schema, so adding it does not mutate shared schema objects.
### Label tool activity
diff --git a/docs/tools/workflows.mdx b/docs/tools/workflows.mdx
index 7ae160a92..b0f265bf5 100644
--- a/docs/tools/workflows.mdx
+++ b/docs/tools/workflows.mdx
@@ -15,7 +15,7 @@ suspend in either execution mode; running in the background does not require a s
Workflow tools use the [Workflow SDK](https://workflow-sdk.dev): `"use workflow"`, `"use step"`, `createHook`,
`createWebhook`, `sleep`, retries, and replay. eve provides `ctx.ask` for questions answered through
-the session's channel, `ctx.agents` for effective subagent descriptions, and `ctx.agent` for durable subagent delegation. Use `yield` to report
+the session's channel, `ctx.agents` for effective callable-agent descriptions, and `ctx.agent` for durable agent delegation. Use `yield` to report
progress and `await` on a workflow operation to wait durably. Values needed after a durable wait
stay in local variables in the workflow body.
@@ -317,13 +317,24 @@ const result = await ctx.agent("reviewer", {
});
```
-The first argument is the subagent's path-derived name. It can identify a model-visible subagent or one hidden with `tool: false` or `disableTool()`. eve assigns each call a replay-stable invocation identity, including repeated and parallel calls to the same subagent. Pass `agentId` to
+The first argument is an available agent target. On the root agent, `"agent"` starts or continues a copy of the root agent. A declared subagent uses its path-derived name and remains callable when hidden with `tool: false` or `disableTool()`. Delegated root copies and declared subagent contexts do not expose the built-in root-copy target. The invocation name `agent` is reserved, so a declared subagent cannot shadow it. eve assigns each call a replay-stable invocation identity, including repeated and parallel calls to the same target. Pass `agentId` to
continue an existing child. An inline `outputSchema` requires structured output and determines the
return type, so `result` in the example is typed as `{ findings: string[] }`.
### Route to a hidden subagent with JEV
-Use an authored workflow tool when the parent model should decide to delegate, but JEV should choose the specialist. Set `tool: false` on each specialist so the parent model sees only the routing tool. The specialists remain available through `ctx.agents` and callable through `ctx.agent()`:
+Use an authored workflow tool when the parent model should decide to delegate, but JEV should choose the specialist. Set `tool: false` on each specialist so the parent model sees only the routing tool. The specialists remain available through `ctx.agents` and callable through `ctx.agent()`.
+
+If the router may select the root-copy `agent`, author a root `description` that explains which work should stay with a copy of the root. `ctx.agents.agent` always exists in a top-level root workflow, but its `description` is an empty string when omitted from `agent.ts`. `agentRouter()` considers only entries with a non-empty description, so it does not route to an undescribed root copy.
+
+```ts title="agent/agent.ts"
+import { defineAgent } from "eve";
+
+export default defineAgent({
+ description: "Coordinate cross-specialist tasks that need the root agent's complete toolset.",
+ model: "anthropic/claude-opus-4.8",
+});
+```
```ts title="agent/subagents/researcher/agent.ts"
import { defineAgent } from "eve";
@@ -388,19 +399,19 @@ export default defineWorkflowTool({
The evaluation runs in a step so workflow replay records its result instead of making the routing request again. The parent model receives `agent-router`, but not `researcher` or `operator`. JEV returns the typed `"researcher" | "operator"` choice, and the selected subagent's result becomes the `agent-router` tool result.
-`ctx.agents` is a replay-stable metadata snapshot taken when the workflow starts. It includes agents hidden from the parent model with `tool: false` or `disableTool()`, but exposes no model definitions, credentials, or callbacks. Invocation still checks the subagent's availability through `ctx.agent()`.
+`ctx.agents` is a replay-stable metadata snapshot taken when the workflow starts. In a top-level root workflow, `ctx.agents.agent` always represents the root-copy target and carries the root's authored `description` when provided. The snapshot also includes declared agents hidden from the parent model with `tool: false` or `disableTool()`, but exposes no model definitions, credentials, or callbacks. A delegated root copy omits `agent`, so `agentRouter()` cannot select another root copy recursively. Invocation still checks each target's availability through `ctx.agent()`.
-#### Route across every subagent
+#### Route across every agent target
-Use `agentRouter()` when the router should consider every available declared subagent with the default JEV routing instructions:
+To replace the model-facing `agent` tool with a router across every target in `ctx.agents`, export `agentRouter()` from the `agent` slot:
-```ts title="agent/tools/agent-router.ts"
+```ts title="agent/tools/agent.ts"
import { agentRouter } from "eve/tools/agent-router";
export default agentRouter();
```
-Its input is `{ message: string, outputSchema?: object }`. With two or more available subagents, `agentRouter()` sends the message and every effective description to JEV, then invokes the selected path-derived name through `ctx.agent()`. It invokes a sole available subagent without evaluation and forwards an optional `outputSchema`. The built-in root-copy `agent` target is not included.
+Its input is `{ message: string, outputSchema?: object }`. `agentRouter()` ignores entries without a non-empty description. With two or more described targets, it sends the message and effective descriptions to JEV, then invokes the selected name through `ctx.agent()`. It invokes a sole target without evaluation and forwards an optional `outputSchema`. In a top-level root session, the candidates include the root-copy `agent`; delegated root copies and declared subagent contexts include only their declared targets.
This pattern controls specialist selection, not whether the parent model delegates at all. Route before the parent model runs if every incoming request must go through JEV.
diff --git a/e2e/fixtures/agent-agent-tool-controls/agent/agent.ts b/e2e/fixtures/agent-agent-tool-controls/agent/agent.ts
index 3279ccc2c..fd048d4fd 100644
--- a/e2e/fixtures/agent-agent-tool-controls/agent/agent.ts
+++ b/e2e/fixtures/agent-agent-tool-controls/agent/agent.ts
@@ -4,6 +4,7 @@ import { mockModel } from "eve/evals";
export default defineAgent({
...e2eAgentConfig(),
+ description: "Coordinate specialist work and delegate focused subtasks.",
model: mockModel({
modelId: "root-agent-tool-disabled",
respond(request) {
diff --git a/e2e/fixtures/agent-agent-tool-controls/evals/workflow-agent-metadata.eval.ts b/e2e/fixtures/agent-agent-tool-controls/evals/workflow-agent-metadata.eval.ts
index 622e1271d..1ded95cfd 100644
--- a/e2e/fixtures/agent-agent-tool-controls/evals/workflow-agent-metadata.eval.ts
+++ b/e2e/fixtures/agent-agent-tool-controls/evals/workflow-agent-metadata.eval.ts
@@ -2,18 +2,20 @@ import { defineEval } from "eve/evals";
import { equals } from "eve/evals/expect";
export default defineEval({
- description: "ctx.agents exposes exact descriptions for hidden declared specialists.",
+ description: "ctx.agents exposes the root copy and hidden declared specialists.",
async test(t) {
const turn = await t.send("E2E_INSPECT_WORKFLOW_AGENTS");
turn.expectOk();
+ turn.messageIncludes("Coordinate specialist work and delegate focused subtasks.");
turn.messageIncludes("Investigate, analyze, and explain questions without changing systems.");
turn.messageIncludes("Execute operational changes to systems and deployments.");
await t.require(
Object.keys(JSON.parse(turn.message ?? "{}")).sort(),
- equals(["operator", "researcher"]),
+ equals(["agent", "operator", "researcher"]),
);
turn.calledTool("inspect-agents", { count: 1 });
+ turn.calledSubagent("agent", { count: 0 });
turn.calledSubagent("operator", { count: 0 });
turn.calledSubagent("researcher", { count: 0 });
t.succeeded();
diff --git a/e2e/fixtures/agent-router/agent/agent.ts b/e2e/fixtures/agent-router/agent/agent.ts
index 4660e5bd9..318565de9 100644
--- a/e2e/fixtures/agent-router/agent/agent.ts
+++ b/e2e/fixtures/agent-router/agent/agent.ts
@@ -4,19 +4,30 @@ import { mockModel } from "eve/evals";
export default defineAgent({
...e2eAgentConfig(),
+ description: "Handle general tasks that do not belong to a specialist.",
model: mockModel({
modelId: "agent-router-parent",
respond(request) {
- if (request.tools.some((tool) => tool.name === "worker")) {
- throw new Error("The hidden worker was exposed to the parent model.");
+ if (request.userMessages.some((message) => message.includes("Return the root-copy marker"))) {
+ if (request.tools.some((tool) => tool.name === "agent")) {
+ throw new Error("The delegated root copy exposed the root-only agent router tool.");
+ }
+ const inspection = request.toolResults.find((entry) => entry.name === "inspect-agents");
+ if (inspection === undefined) {
+ return { toolCalls: [{ name: "inspect-agents", input: {} }] };
+ }
+ if (Object.hasOwn(inspection.output as object, "agent")) {
+ throw new Error("The delegated root copy exposed recursive agent metadata.");
+ }
+ return "AGENT-ROUTER-ROOT-COPY-OK";
}
- const result = request.toolResults.find((entry) => entry.name === "agent-router");
+ const result = request.toolResults.find((entry) => entry.name === "agent");
return result === undefined
? {
toolCalls: [
{
- name: "agent-router",
- input: { message: "Return the agent-router marker." },
+ name: "agent",
+ input: { message: "Return the root-copy marker." },
},
],
}
diff --git a/e2e/fixtures/agent-router/agent/subagents/worker/agent.ts b/e2e/fixtures/agent-router/agent/subagents/worker/agent.ts
deleted file mode 100644
index 07f670a6a..000000000
--- a/e2e/fixtures/agent-router/agent/subagents/worker/agent.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-import { defineAgent } from "eve";
-import { mockModel } from "eve/evals";
-
-export default defineAgent({
- description: "Handle every delegated task in this fixture.",
- model: mockModel({ modelId: "agent-router-worker", respond: "AGENT-ROUTER-WORKER-OK" }),
- modelContextWindowTokens: 1_000_000,
- tool: false,
-});
diff --git a/e2e/fixtures/agent-router/agent/subagents/worker/instructions.md b/e2e/fixtures/agent-router/agent/subagents/worker/instructions.md
deleted file mode 100644
index 4c8dac607..000000000
--- a/e2e/fixtures/agent-router/agent/subagents/worker/instructions.md
+++ /dev/null
@@ -1 +0,0 @@
-Reply with the exact string `AGENT-ROUTER-WORKER-OK` and nothing else.
diff --git a/e2e/fixtures/agent-router/agent/tools/agent-router.ts b/e2e/fixtures/agent-router/agent/tools/agent.ts
similarity index 100%
rename from e2e/fixtures/agent-router/agent/tools/agent-router.ts
rename to e2e/fixtures/agent-router/agent/tools/agent.ts
diff --git a/e2e/fixtures/agent-router/agent/tools/inspect-agents.ts b/e2e/fixtures/agent-router/agent/tools/inspect-agents.ts
new file mode 100644
index 000000000..e1c18eda7
--- /dev/null
+++ b/e2e/fixtures/agent-router/agent/tools/inspect-agents.ts
@@ -0,0 +1,26 @@
+import {
+ defineWorkflowTool,
+ type WorkflowAgentMetadata,
+ type WorkflowToolContext,
+ type WorkflowToolDefinition,
+} from "eve/tools";
+
+async function execute(
+ _input: Record<string, unknown>,
+ ctx: WorkflowToolContext,
+): Promise<Record<string, WorkflowAgentMetadata>> {
+ "use workflow";
+
+ return ctx.agents;
+}
+
+const tool: WorkflowToolDefinition<
+ Record<string, unknown>,
+ Record<string, WorkflowAgentMetadata>
+> = defineWorkflowTool({
+ description: "Return the workflow's available agent metadata.",
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
+ execute,
+});
+
+export default tool;
diff --git a/e2e/fixtures/agent-router/evals/agent-router.eval.ts b/e2e/fixtures/agent-router/evals/agent-router.eval.ts
index ce692d824..6483427aa 100644
--- a/e2e/fixtures/agent-router/evals/agent-router.eval.ts
+++ b/e2e/fixtures/agent-router/evals/agent-router.eval.ts
@@ -1,14 +1,14 @@
import { defineEval } from "eve/evals";
export default defineEval({
- description: "agentRouter invokes a sole hidden subagent through the provided workflow tool.",
+ description: "agentRouter invokes the root-copy agent when it is the sole available target.",
async test(t) {
const turn = await t.send("Route this task.");
turn.expectOk();
- turn.messageIncludes("AGENT-ROUTER-WORKER-OK");
- turn.calledTool("agent-router", { count: 1 });
- turn.calledSubagent("worker", { count: 1, status: "pending" });
+ turn.messageIncludes("AGENT-ROUTER-ROOT-COPY-OK");
+ turn.calledTool("agent", { count: 1 });
+ turn.calledSubagent("agent", { count: 1, status: "pending" });
t.succeeded();
t.noFailedActions();
},
diff --git a/packages/eve/extension-contracts/compatibility/dynamicTool/v49.ts b/packages/eve/extension-contracts/compatibility/dynamicTool/v49.ts
new file mode 100644
index 000000000..bdc51a74d
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/dynamicTool/v49.ts
@@ -0,0 +1,16 @@
+import { defineDurableCallback, defineDynamic, defineTool } from "#public/tools/index.js";
+
+export default defineDynamic({
+ events: {
+ "session.started": (_event, context) => ({
+ session_id: defineTool({
+ description: "Return the captured session id.",
+ inputSchema: { type: "object", properties: {} },
+ execute: defineDurableCallback({
+ closure: { sessionId: context.session.id },
+ callback: ({ sessionId }) => sessionId,
+ }),
+ }),
+ }),
+ },
+});
diff --git a/packages/eve/extension-contracts/compatibility/tool/v50.ts b/packages/eve/extension-contracts/compatibility/tool/v50.ts
new file mode 100644
index 000000000..5ad0f8c1f
--- /dev/null
+++ b/packages/eve/extension-contracts/compatibility/tool/v50.ts
@@ -0,0 +1,3 @@
+import { agentRouter } from "#public/tools/agent-router.js";
+
+export default agentRouter();
diff --git a/packages/eve/extension-contracts/reports/dynamicTool/v50.json b/packages/eve/extension-contracts/reports/dynamicTool/v50.json
new file mode 100644
index 000000000..26463a357
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/dynamicTool/v50.json
@@ -0,0 +1,16 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "dynamicTool",
+ "epoch": 50,
+ "sha256": "f435eed285355eb6c6c1dd8ed0a6f17bdb0652ad960cf688d85d95431b2909f3",
+ "exports": [
+ "DynamicToolEntry",
+ "DynamicToolEvents",
+ "DynamicToolResult",
+ "DynamicToolSet",
+ "auto",
+ "defineDurableCallback",
+ "defineDurableSchema",
+ "defineDynamic"
+ ]
+}
diff --git a/packages/eve/extension-contracts/reports/tool/v51.json b/packages/eve/extension-contracts/reports/tool/v51.json
new file mode 100644
index 000000000..e5537c484
--- /dev/null
+++ b/packages/eve/extension-contracts/reports/tool/v51.json
@@ -0,0 +1,26 @@
+{
+ "kind": "eve-extension-capability-contract",
+ "capability": "tool",
+ "epoch": 51,
+ "sha256": "03bb628d2b165fb5807b6068ddc64666d8281ae94f56b712bb72140d76b7ec87",
+ "exports": [
+ "AgentRouterInput",
+ "AgentRouterTool",
+ "WorkflowTool",
+ "WorkflowToolInput",
+ "WorkflowToolOptions",
+ "agentRouter",
+ "defaultWebSearch",
+ "defineTool",
+ "defineWorkflowTool",
+ "disableTool",
+ "evaluate",
+ "isDisabledToolSentinel",
+ "isWebSearchToolDefinition",
+ "toolOutput",
+ "toolOutputPart",
+ "toolResultFrom",
+ "webSearch",
+ "workflow"
+ ]
+}
diff --git a/packages/eve/src/compiler/default-tool-policy.ts b/packages/eve/src/compiler/default-tool-policy.ts
index 9d46bfe5e..8ef803c62 100644
--- a/packages/eve/src/compiler/default-tool-policy.ts
+++ b/packages/eve/src/compiler/default-tool-policy.ts
@@ -23,7 +23,6 @@ export function assertFrameworkToolPolicy(
);
}
const closedDispatchSlots = {
- "tools/agent": "self-agent",
"tools/task_cancel": "task-cancel",
} as const;
const expectedAction = closedDispatchSlots[slot as keyof typeof closedDispatchSlots];
diff --git a/packages/eve/src/compiler/extension-compatibility.ts b/packages/eve/src/compiler/extension-compatibility.ts
index 4b8bcf50c..97f1a5617 100644
--- a/packages/eve/src/compiler/extension-compatibility.ts
+++ b/packages/eve/src/compiler/extension-compatibility.ts
@@ -22,9 +22,9 @@ interface ExtensionCapabilityContract {
const EXTENSION_CAPABILITY_CONTRACTS = {
extension: { current: 1, supported: [1], dropped: {} },
tool: {
- current: 50,
+ current: 51,
supported: [
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 28, 29, 30, 31, 32, 34, 35, 44, 45, 46, 49, 50,
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 28, 29, 30, 31, 32, 34, 35, 44, 45, 46, 49, 50, 51,
],
dropped: {
14: "TaskExec.delegated was removed; migrate to workflow-backed background tools",
@@ -55,10 +55,10 @@ const EXTENSION_CAPABILITY_CONTRACTS = {
},
},
dynamicTool: {
- current: 49,
+ current: 50,
supported: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 28, 29, 30, 31, 32,
- 33, 41, 48, 49,
+ 33, 41, 48, 49, 50,
],
dropped: {
21: "Message and reasoning append events now expose deltas instead of cumulative snapshots.",
diff --git a/packages/eve/src/compiler/manifest.test.ts b/packages/eve/src/compiler/manifest.test.ts
index e17a7bb9a..888c0482c 100644
--- a/packages/eve/src/compiler/manifest.test.ts
+++ b/packages/eve/src/compiler/manifest.test.ts
@@ -11,7 +11,7 @@ import {
validateCompiledModuleMap,
} from "#compiler/validate-artifact.js";
-describe("compiled agent manifest v49", () => {
+describe("compiled agent manifest v50", () => {
it("round-trips a real compiled graph through the serialized schema", async () => {
const { manifest } = await compileFromMemory({
agent: {
@@ -122,6 +122,29 @@ describe("compiled agent manifest v49", () => {
).toThrow("do not match its bindings");
});
+ it("rejects a compiled subagent named agent", async () => {
+ const { manifest } = await compileFromMemory({ model: "openai/gpt-5.4" });
+ const subagent = {
+ agent: createCompiledAgentNodeManifest(manifest),
+ backing: { kind: "resource" as const, sourcePath: "/virtual/subagents/agent" },
+ description: "Ambiguous agent.",
+ entryPath: "/virtual/subagents/agent",
+ logicalPath: "subagents/agent",
+ name: "agent",
+ nodeId: "agent-node",
+ owner: { kind: "application" as const },
+ parentNodeId: "__root__",
+ rootPath: "/virtual/subagents/agent",
+ sourceId: "agent-source",
+ sourceKind: "module" as const,
+ };
+ const corrupted = compiledAgentManifestSchema.parse({ ...manifest, subagents: [subagent] });
+
+ expect(() => validateCompiledAgentManifest(corrupted)).toThrow(
+ 'subagent name "agent" is reserved for the built-in root-copy target',
+ );
+ });
+
it("rejects a disconnected subagent parent cycle", async () => {
const { manifest } = await compileFromMemory({ model: "openai/gpt-5.4" });
const agent = createCompiledAgentNodeManifest(manifest);
diff --git a/packages/eve/src/compiler/manifest.ts b/packages/eve/src/compiler/manifest.ts
index 47445c896..28ced0ae6 100644
--- a/packages/eve/src/compiler/manifest.ts
+++ b/packages/eve/src/compiler/manifest.ts
@@ -55,7 +55,7 @@ export const ROOT_COMPILED_AGENT_NODE_ID = "__root__";
/**
* Current compiled manifest schema version.
*/
-export const COMPILED_AGENT_MANIFEST_VERSION = 49;
+export const COMPILED_AGENT_MANIFEST_VERSION = 50;
/**
* Compiled channel entry preserved in the compiled manifest.
@@ -857,6 +857,7 @@ const compiledToolBehaviorSchema: z.ZodType<CompiledToolBehavior> = z
const compiledToolDefinitionSchema = z
.object({
+ availableInSubagents: z.boolean().optional(),
behavior: compiledToolBehaviorSchema.optional(),
description: z.string(),
execution: z.literal("background").optional(),
diff --git a/packages/eve/src/compiler/normalize-manifest.test.ts b/packages/eve/src/compiler/normalize-manifest.test.ts
index b2bb60283..7a2cbec45 100644
--- a/packages/eve/src/compiler/normalize-manifest.test.ts
+++ b/packages/eve/src/compiler/normalize-manifest.test.ts
@@ -275,29 +275,53 @@ describe("compileAgentManifest source graph", () => {
);
});
- it.each(["agent", "task_cancel"])(
- "rejects overriding closed framework tool %s",
- async (toolName) => {
- const sourceRegistry = registry([
- {
- logicalPath: `tools/${toolName}.ts`,
- loadNamespace: async () => ({
- default: defineTool({
- description: "Replacement tool.",
- execute: async () => null,
- inputSchema: {},
- }),
+ it("allows an authored tool in the agent slot", async () => {
+ const sourceRegistry = registry([
+ {
+ logicalPath: "tools/agent.ts",
+ loadNamespace: async () => ({
+ default: defineTool({
+ availableInSubagents: false,
+ description: "Route delegated work.",
+ execute: async () => null,
+ inputSchema: {},
}),
- },
- ]);
+ }),
+ },
+ ]);
- await expect(
- compileAgentManifest(manifest(), { sourceRegistries: [sourceRegistry] }),
- ).rejects.toThrow(
- `The framework "${toolName}" tool cannot be overridden. Re-export it from "eve/tools/${toolName}" or disable it with disableTool().`,
- );
- },
- );
+ const compiled = await compileAgentManifest(manifest(), {
+ sourceRegistries: [sourceRegistry],
+ });
+
+ expect(compiled.tools.find((tool) => tool.name === "agent")).toMatchObject({
+ availableInSubagents: false,
+ behavior: { availability: [] },
+ description: "Route delegated work.",
+ execution: undefined,
+ });
+ });
+
+ it.each(["task_cancel"])("rejects overriding closed framework tool %s", async (toolName) => {
+ const sourceRegistry = registry([
+ {
+ logicalPath: `tools/${toolName}.ts`,
+ loadNamespace: async () => ({
+ default: defineTool({
+ description: "Replacement tool.",
+ execute: async () => null,
+ inputSchema: {},
+ }),
+ }),
+ },
+ ]);
+
+ await expect(
+ compileAgentManifest(manifest(), { sourceRegistries: [sourceRegistry] }),
+ ).rejects.toThrow(
+ `The framework "${toolName}" tool cannot be overridden. Re-export it from "eve/tools/${toolName}" or disable it with disableTool().`,
+ );
+ });
it("compiles a workflow tool with programmatic executor metadata", async () => {
const execute = async () => ({ ok: true });
@@ -690,6 +714,30 @@ describe("compileAgentManifest source graph", () => {
});
});
+ it("reserves the agent subagent name for root self-delegation", async () => {
+ const child = createAgentSourceManifest({
+ agentId: "agent",
+ agentRoot: "/virtual/source-test/agent/subagents/agent",
+ appRoot: "/virtual/source-test",
+ });
+ const discovered = manifest();
+ discovered.subagents.push(
+ createLocalSubagentSourceRef({
+ entryPath: child.agentRoot,
+ logicalPath: "subagents/agent",
+ manifest: child,
+ rootPath: child.agentRoot,
+ subagentId: "agent",
+ }),
+ );
+
+ await expect(
+ compileAgentManifest(discovered, { sourceRegistries: [registry([])] }),
+ ).rejects.toThrow(
+ 'Subagent "subagents/agent" uses the reserved name "agent". Rename its path; eve reserves "agent" for the built-in root-copy target.',
+ );
+ });
+
it("projects a local subagent node once", async () => {
let toolSourceIterations = 0;
const child = createAgentSourceManifest({
diff --git a/packages/eve/src/compiler/normalize-tool.ts b/packages/eve/src/compiler/normalize-tool.ts
index 67c7db1d6..f16cff632 100644
--- a/packages/eve/src/compiler/normalize-tool.ts
+++ b/packages/eve/src/compiler/normalize-tool.ts
@@ -109,6 +109,7 @@ export async function compileToolEntry(
return {
kind: "tool",
definition: {
+ availableInSubagents: entry.definition.availableInSubagents,
behavior:
workflowId === undefined
? entry.definition.behavior === undefined
diff --git a/packages/eve/src/compiler/project-sources.ts b/packages/eve/src/compiler/project-sources.ts
index 696253e3a..a9f4fd0ce 100644
--- a/packages/eve/src/compiler/project-sources.ts
+++ b/packages/eve/src/compiler/project-sources.ts
@@ -345,6 +345,11 @@ function projectManifest(input: {
for (const source of input.manifest.subagents) {
const name = projection.name(source.subagentId);
const logicalPath = projection.logicalPath(source.logicalPath);
+ if (name === "agent") {
+ throw new Error(
+ `Subagent "${logicalPath}" uses the reserved name "agent". Rename its path; eve reserves "agent" for the built-in root-copy target.`,
+ );
+ }
const projectedSource = {
...source,
logicalPath,
diff --git a/packages/eve/src/compiler/validate-artifact.ts b/packages/eve/src/compiler/validate-artifact.ts
index 1637d4e62..8a116ecb5 100644
--- a/packages/eve/src/compiler/validate-artifact.ts
+++ b/packages/eve/src/compiler/validate-artifact.ts
@@ -241,6 +241,9 @@ export function validateCompiledAgentResources(
}
function validateSubagentRecord(subagent: CompiledSubagentNode): void {
+ if (subagent.name === "agent") {
+ fail('subagent name "agent" is reserved for the built-in root-copy target');
+ }
if (subagent.backing.kind !== "resource" || subagent.backing.sourcePath.length === 0) {
fail(`subagent "${subagent.nodeId}" has no physical resource backing`);
}
diff --git a/packages/eve/src/context/build-dynamic-tools.ts b/packages/eve/src/context/build-dynamic-tools.ts
index 2ed26e2b5..1120d69b8 100644
--- a/packages/eve/src/context/build-dynamic-tools.ts
+++ b/packages/eve/src/context/build-dynamic-tools.ts
@@ -140,6 +140,7 @@ export function replayDynamicTools(
const replayed: {
-readonly [K in keyof HarnessToolDefinition]: HarnessToolDefinition[K];
} = {
+ availableInSubagents: entry.availableInSubagents,
description: entry.description,
execute:
entry.execution === "background"
diff --git a/packages/eve/src/context/dynamic-tool-lifecycle.test.ts b/packages/eve/src/context/dynamic-tool-lifecycle.test.ts
index fe4831b1d..39f097d7b 100644
--- a/packages/eve/src/context/dynamic-tool-lifecycle.test.ts
+++ b/packages/eve/src/context/dynamic-tool-lifecycle.test.ts
@@ -1121,6 +1121,34 @@ describe("dispatchDynamicToolEvent", () => {
expect(buildDynamicTools(ctx)).toHaveLength(2);
});
+ it("persists subagent visibility when replaying", async () => {
+ const ctx = createCtx();
+ const resolver = createResolver("root-only", ["session.started"], () => {
+ const entry = defineTool({
+ availableInSubagents: false,
+ description: "run only in the root session",
+ inputSchema: z.strictObject({}),
+ execute: () => null,
+ });
+ stampDurableDynamicToolCallbacks(entry, {
+ inputSchema: { callback: () => entry.inputSchema, closure: {} },
+ execute: { callback: () => null, closure: {} },
+ });
+ return { root_only: entry };
+ });
+
+ await dispatchDynamicToolEvent({
+ ctx,
+ resolvers: [resolver],
+ messages: [],
+ event: makeEvent("session.started"),
+ });
+ const restored = await deserializeContext(serializeContext(ctx));
+ const [metadata] = restored.get(SessionDynamicToolMetadataKey) ?? [];
+ expect(metadata?.availableInSubagents).toBe(false);
+ expect(buildDynamicTools(restored)[0]?.availableInSubagents).toBe(false);
+ });
+
it("persists background execution and forwards TaskExec when replaying", async () => {
const ctx = createCtx();
const stepFn = vi.fn(async function* (
diff --git a/packages/eve/src/context/dynamic-tool-lifecycle.ts b/packages/eve/src/context/dynamic-tool-lifecycle.ts
index c6b9521a6..2604f7ba5 100644
--- a/packages/eve/src/context/dynamic-tool-lifecycle.ts
+++ b/packages/eve/src/context/dynamic-tool-lifecycle.ts
@@ -325,6 +325,7 @@ function createMetadata(input: {
readonly resolver: ResolvedDynamicToolResolver;
}): CurrentDynamicToolMetadata {
return {
+ availableInSubagents: input.entry.availableInSubagents,
callbacks: validateDurableDynamicToolCallbacks(input.name, input.entry, {
sessionId: input.sessionId,
scope: input.scope,
diff --git a/packages/eve/src/context/dynamic-tool-metadata.ts b/packages/eve/src/context/dynamic-tool-metadata.ts
index 46e6c1793..d2bd3dc20 100644
--- a/packages/eve/src/context/dynamic-tool-metadata.ts
+++ b/packages/eve/src/context/dynamic-tool-metadata.ts
@@ -2,6 +2,7 @@ import type { JsonObject } from "#shared/json.js";
import type { DurableDynamicToolCallbacks } from "#tools/durable-callbacks.js";
interface DynamicToolMetadataBase {
+ readonly availableInSubagents?: boolean;
readonly name: string;
readonly description: string;
readonly execution?: "background";
diff --git a/packages/eve/src/execution/node-step.test.ts b/packages/eve/src/execution/node-step.test.ts
index f1b492940..e82a06e2a 100644
--- a/packages/eve/src/execution/node-step.test.ts
+++ b/packages/eve/src/execution/node-step.test.ts
@@ -179,19 +179,31 @@ async function createNodeWithSourceOwnedTools(input: {
| { readonly feature: string; readonly kind: "framework" };
readonly turnTools?: StaticRuntimeTurnAgent["tools"];
}): Promise<ResolvedRuntimeAgentNode> {
- const toolRegistry = await createRuntimeToolRegistry({
- tools: input.names.map((name) => ({
- description: name === AGENT_TOOL_NAME ? AGENT_TOOL_DESCRIPTION : `${name} programmatic tool.`,
- execute: async () => `${name}-sentinel`,
- execution: name === AGENT_TOOL_NAME ? "background" : undefined,
- inputSchema: name === AGENT_TOOL_NAME ? SUBAGENT_TOOL_INPUT_SCHEMA : null,
- logicalPath: `tools/${name}.ts`,
- name,
- owner: input.owner ?? { feature: "test", kind: "framework" },
- sourceId: `framework:tools/${name}.ts`,
- sourceKind: "module",
- })),
- });
+ const toolRegistry = await createRuntimeToolRegistry(
+ {
+ tools: input.names.map((name) => {
+ const frameworkAgent = name === AGENT_TOOL_NAME && input.owner?.kind !== "application";
+ return {
+ behavior: frameworkAgent
+ ? {
+ availability: ["root-session"] as const,
+ handling: { action: "self-agent" as const, kind: "dispatch" as const },
+ }
+ : undefined,
+ description: frameworkAgent ? AGENT_TOOL_DESCRIPTION : `${name} programmatic tool.`,
+ execute: async () => `${name}-sentinel`,
+ execution: frameworkAgent ? "background" : undefined,
+ inputSchema: frameworkAgent ? SUBAGENT_TOOL_INPUT_SCHEMA : null,
+ logicalPath: `tools/${name}.ts`,
+ name,
+ owner: input.owner ?? { feature: "test", kind: "framework" },
+ sourceId: `framework:tools/${name}.ts`,
+ sourceKind: "module",
+ };
+ }),
+ },
+ { nodeId: ROOT_RUNTIME_AGENT_NODE_ID },
+ );
const node = createTestNode(
createTestTurnAgent({
tools: [...toolRegistry.preparedTools, ...(input.turnTools ?? [])],
@@ -265,6 +277,20 @@ describe("createNodeHarnessTools", () => {
expect(agentTool?.execute).toBeDefined();
});
+ it("keeps an authored agent tool separate from self-delegation", async () => {
+ const node = await createNodeWithSourceOwnedTools({
+ names: ["agent"],
+ owner: { kind: "application" },
+ });
+ const agentTool = createNodeHarnessTools({ node }).get("agent");
+
+ expect(agentTool?.availableInSubagents).toBeUndefined();
+ expect(agentTool?.execution).toBeUndefined();
+ expect(agentTool?.resultKind).toBeUndefined();
+ expect(agentTool?.rootOnly).toBeUndefined();
+ expect(agentTool?.workflowId).toBeUndefined();
+ });
+
it("lowers task_cancel from its framework definition", async () => {
const node = await createNodeWithSourceOwnedTools({ names: ["task_cancel"] });
const tools = createNodeHarnessTools({ node });
diff --git a/packages/eve/src/execution/node-step.ts b/packages/eve/src/execution/node-step.ts
index 6bdaeed97..6b9550ed7 100644
--- a/packages/eve/src/execution/node-step.ts
+++ b/packages/eve/src/execution/node-step.ts
@@ -277,6 +277,7 @@ function createRegisteredHarnessToolDefinition(input: {
def.owner.kind === "framework" && def.name === ASK_QUESTION_TOOL_NAME;
const definition: HarnessToolDefinition = {
+ availableInSubagents: def.availableInSubagents,
label:
def.label ??
(def.owner.kind === "framework" && def.name === WEB_SEARCH_TOOL_NAME
diff --git a/packages/eve/src/execution/tools/agent-router-workflow.ts b/packages/eve/src/execution/tools/agent-router-workflow.ts
index 196623975..7032b83ce 100644
--- a/packages/eve/src/execution/tools/agent-router-workflow.ts
+++ b/packages/eve/src/execution/tools/agent-router-workflow.ts
@@ -28,7 +28,7 @@ async function chooseTarget(
const names = Object.keys(criteria);
if (names.length === 0) {
- throw new Error("agentRouter requires at least one available declared subagent.");
+ throw new Error("agentRouter requires at least one available agent with a description.");
}
if (names.length === 1) return names[0]!;
@@ -48,6 +48,9 @@ async function chooseTarget(
function descriptions(ctx: WorkflowToolContext): Record<string, string> {
return Object.fromEntries(
- Object.entries(ctx.agents).map(([name, metadata]) => [name, metadata.description]),
+ Object.entries(ctx.agents).flatMap(([name, metadata]) => {
+ const description = metadata.description.trim();
+ return description.length === 0 ? [] : [[name, description]];
+ }),
);
}
diff --git a/packages/eve/src/execution/tools/subagent/metadata.test.ts b/packages/eve/src/execution/tools/subagent/metadata.test.ts
index 3933f5f4d..16d045594 100644
--- a/packages/eve/src/execution/tools/subagent/metadata.test.ts
+++ b/packages/eve/src/execution/tools/subagent/metadata.test.ts
@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";
import { ContextContainer } from "#context/container.js";
import {
+ ParentSessionKey,
SessionDynamicSubagentSelectionsKey,
TurnDynamicSubagentSelectionsKey,
} from "#context/keys.js";
@@ -9,8 +10,9 @@ import { resolveWorkflowAgentMetadata } from "#execution/tools/subagent/metadata
import { BundleKey } from "#runtime/sessions/runtime-context-keys.js";
describe("resolveWorkflowAgentMetadata", () => {
- it("includes hidden static subagents without adding self-delegation", () => {
+ it("includes root self-delegation and hidden static subagents", () => {
const ctx = context({
+ description: "Coordinate specialist work.",
nodeId: undefined,
subagentsByName: new Map([
[
@@ -27,11 +29,31 @@ describe("resolveWorkflowAgentMetadata", () => {
});
expect(resolveWorkflowAgentMetadata(ctx)).toEqual({
+ agent: { description: "Coordinate specialist work." },
researcher: { description: "Investigate difficult questions." },
});
});
- it("uses effective dynamic descriptions with turn precedence", () => {
+ it("includes root self-delegation with an empty description when the root has none", () => {
+ const ctx = context({ nodeId: undefined, subagentsByName: new Map() });
+
+ expect(resolveWorkflowAgentMetadata(ctx)).toEqual({
+ agent: { description: "" },
+ });
+ });
+
+ it("omits self-delegation from a delegated root copy", () => {
+ const ctx = context({
+ description: "Coordinate specialist work.",
+ nodeId: undefined,
+ parentSession: { rootSessionId: "root", sessionId: "parent", turnId: "turn" },
+ subagentsByName: new Map(),
+ });
+
+ expect(resolveWorkflowAgentMetadata(ctx)).toEqual({});
+ });
+
+ it("uses effective dynamic descriptions with turn precedence without adding self-delegation", () => {
const ctx = context({ nodeId: "subagents/coordinator", subagentsByName: new Map() });
const prepared = { name: "reviewer" };
ctx.set(SessionDynamicSubagentSelectionsKey, {
@@ -56,13 +78,17 @@ describe("resolveWorkflowAgentMetadata", () => {
});
function context(input: {
+ readonly description?: string;
readonly nodeId: string | undefined;
+ readonly parentSession?: unknown;
readonly subagentsByName: ReadonlyMap<string, unknown>;
}): ContextContainer {
const ctx = new ContextContainer();
ctx.set(BundleKey, {
nodeId: input.nodeId,
+ resolvedAgent: { config: { description: input.description } },
subagentRegistry: { subagentsByName: input.subagentsByName },
} as never);
+ if (input.parentSession !== undefined) ctx.set(ParentSessionKey, input.parentSession as never);
return ctx;
}
diff --git a/packages/eve/src/execution/tools/subagent/metadata.ts b/packages/eve/src/execution/tools/subagent/metadata.ts
index 9d8c55485..f76e334cc 100644
--- a/packages/eve/src/execution/tools/subagent/metadata.ts
+++ b/packages/eve/src/execution/tools/subagent/metadata.ts
@@ -1,10 +1,12 @@
import {
+ ParentSessionKey,
SessionDynamicSubagentSelectionsKey,
TurnDynamicSubagentSelectionsKey,
type DurableDynamicSubagentSelection,
} from "#context/keys.js";
import type { ContextReader } from "#context/key.js";
import { BundleKey } from "#runtime/sessions/runtime-context-keys.js";
+import { AGENT_TOOL_NAME } from "#tools/framework/agent-contract.js";
import type { WorkflowAgentMetadata } from "#tools/workflow-definition.js";
/** Snapshots callable agent metadata for one workflow tool run. */
@@ -15,6 +17,12 @@ export function resolveWorkflowAgentMetadata(
if (bundle === undefined) return {};
const agents = new Map<string, WorkflowAgentMetadata>();
+ if (bundle.nodeId === undefined && ctx.get(ParentSessionKey) === undefined) {
+ agents.set(AGENT_TOOL_NAME, {
+ description: bundle.resolvedAgent.config?.description ?? "",
+ });
+ }
+
for (const [name, registered] of bundle.subagentRegistry.subagentsByName ?? []) {
const description = registered.definition.description;
if (description !== undefined) agents.set(name, { description });
diff --git a/packages/eve/src/harness/advertised-tools.test.ts b/packages/eve/src/harness/advertised-tools.test.ts
index 17e32db47..ab136248f 100644
--- a/packages/eve/src/harness/advertised-tools.test.ts
+++ b/packages/eve/src/harness/advertised-tools.test.ts
@@ -70,6 +70,17 @@ describe("getAdvertisedTools for definition arrays", () => {
expect(advertisedTools.map((tool) => tool.name)).toEqual(["add", "delegate"]);
});
+ it("hides tools marked unavailable in subagents from delegated sessions", () => {
+ const tools = new Map([
+ ["root_only", { ...createTool("root_only"), availableInSubagents: false }],
+ ]) satisfies HarnessToolMap;
+
+ expect([...getAdvertisedTools({ session: {}, tools }).keys()]).toEqual(["root_only"]);
+ expect([
+ ...getAdvertisedTools({ session: { rootSessionId: "root-session" }, tools }).keys(),
+ ]).toEqual([]);
+ });
+
it("keeps root-session tools in the root session", () => {
const tools = new Map([
["add", createTool("add")],
diff --git a/packages/eve/src/harness/advertised-tools.ts b/packages/eve/src/harness/advertised-tools.ts
index 5f8a1d23e..3385069d6 100644
--- a/packages/eve/src/harness/advertised-tools.ts
+++ b/packages/eve/src/harness/advertised-tools.ts
@@ -99,6 +99,7 @@ function shouldHideTool(
const delegated = session.rootSessionId !== undefined;
if (
definition.rootOnly === true ||
+ definition.availableInSubagents === false ||
definition.behavior?.availability.includes("root-session") === true
) {
return delegated;
diff --git a/packages/eve/src/harness/execute-tool.ts b/packages/eve/src/harness/execute-tool.ts
index 2f5d3dc01..b5412dcd4 100644
--- a/packages/eve/src/harness/execute-tool.ts
+++ b/packages/eve/src/harness/execute-tool.ts
@@ -18,6 +18,7 @@ export type HarnessRuntimeActionDefinition = { readonly kind: "task-control" };
* Unified harness-owned tool definition.
*/
export interface HarnessToolDefinition {
+ readonly availableInSubagents?: boolean;
readonly label?: InternalToolLabelDefinition;
readonly approvalKey?: (toolInput: Readonly<Record<string, unknown>>) => string;
readonly behavior?: PreparedToolBehavior;
diff --git a/packages/eve/src/internal/authored-definition/schema-backed.test.ts b/packages/eve/src/internal/authored-definition/schema-backed.test.ts
index 2499c4913..ef25a1a3b 100644
--- a/packages/eve/src/internal/authored-definition/schema-backed.test.ts
+++ b/packages/eve/src/internal/authored-definition/schema-backed.test.ts
@@ -30,6 +30,21 @@ describe("normalizeToolDefinition", () => {
expect(typeof entry.definition.execute).toBe("function");
});
+ it("preserves subagent visibility", () => {
+ const tool = defineTool({
+ availableInSubagents: false,
+ description: "Runs only in a root session.",
+ inputSchema: z.object({}),
+ execute: () => null,
+ });
+
+ const entry = normalizeToolDefinition(tool, FAILURE_MESSAGE);
+
+ expect(entry.kind).toBe("tool");
+ if (entry.kind !== "tool") throw new Error("expected tool kind");
+ expect(entry.definition.availableInSubagents).toBe(false);
+ });
+
it("preserves the background execution discriminator", () => {
const tool = defineTool({
description: "Starts an export.",
diff --git a/packages/eve/src/internal/authored-definition/schema-backed.ts b/packages/eve/src/internal/authored-definition/schema-backed.ts
index ecacc6814..b7b47b904 100644
--- a/packages/eve/src/internal/authored-definition/schema-backed.ts
+++ b/packages/eve/src/internal/authored-definition/schema-backed.ts
@@ -3,6 +3,7 @@ import { readWorkflowFunctionId } from "#internal/workflow/reference.js";
import { isDisabledToolSentinel } from "#tools/definition.js";
import { isWebSearchToolDefinition } from "#tools/provided/web-search.js";
import {
+ expectBoolean,
expectFunction,
expectObjectRecord,
expectOnlyKnownKeys,
@@ -109,6 +110,7 @@ export function normalizeToolDefinition(value: unknown, message: string): Normal
expectOnlyKnownKeys(
record,
[
+ "availableInSubagents",
"label",
"auth",
"description",
@@ -138,6 +140,10 @@ export function normalizeToolDefinition(value: unknown, message: string): Normal
expectFunction(record.execute, message);
}
const definition: MutableNormalizedAuthoredTool = {
+ availableInSubagents:
+ record.availableInSubagents === undefined
+ ? undefined
+ : expectBoolean(record.availableInSubagents, message),
description: expectString(record.description, message),
hasApproval: record.approval !== undefined,
hasExecute,
diff --git a/packages/eve/src/runtime/resolve-agent.ts b/packages/eve/src/runtime/resolve-agent.ts
index 7ae77e79e..ca97420a8 100644
--- a/packages/eve/src/runtime/resolve-agent.ts
+++ b/packages/eve/src/runtime/resolve-agent.ts
@@ -185,6 +185,7 @@ function createResolvedAgentConfig(
const config: {
compaction?: NonNullable<ResolvedAgent["config"]>["compaction"];
defaultTools?: boolean;
+ description?: string;
experimental?: NonNullable<ResolvedAgent["config"]>["experimental"];
name: string;
outputSchema?: NonNullable<ResolvedAgent["config"]>["outputSchema"];
@@ -199,6 +200,9 @@ function createResolvedAgentConfig(
if (manifest.config.defaultTools !== undefined) {
config.defaultTools = manifest.config.defaultTools;
}
+ if (manifest.config.description !== undefined) {
+ config.description = manifest.config.description;
+ }
if (manifest.config.compaction !== undefined) {
const compaction: {
diff --git a/packages/eve/src/runtime/resolve-tool.ts b/packages/eve/src/runtime/resolve-tool.ts
index 12c502059..b2739cf24 100644
--- a/packages/eve/src/runtime/resolve-tool.ts
+++ b/packages/eve/src/runtime/resolve-tool.ts
@@ -30,6 +30,7 @@ export async function resolveToolDefinition(
): Promise<ResolvedToolDefinition> {
if (!definition.hasExecute) {
return {
+ availableInSubagents: definition.availableInSubagents,
behavior: definition.behavior,
description: definition.description,
inputSchema: toInputSchema(definition.inputSchema),
@@ -82,6 +83,7 @@ export async function resolveToolDefinition(
: (input: unknown) => createWorkflowProgramExecuteInput(workflowProgram, input);
return {
+ availableInSubagents: definition.availableInSubagents,
behavior: definition.behavior,
description: definition.description,
execute,
diff --git a/packages/eve/src/runtime/tools/registry.ts b/packages/eve/src/runtime/tools/registry.ts
index 608b77e55..98eeba8b5 100644
--- a/packages/eve/src/runtime/tools/registry.ts
+++ b/packages/eve/src/runtime/tools/registry.ts
@@ -83,17 +83,20 @@ async function createPreparedRuntimeTool(
definition: ResolvedToolDefinition,
nodeId: string | undefined,
): Promise<PreparedRuntimeAuthoredTool> {
- const isFrameworkAgent = definition.name === AGENT_TOOL_NAME;
- const workflowId = isFrameworkAgent
+ const isSelfAgent =
+ definition.behavior?.handling?.kind === "dispatch" &&
+ definition.behavior.handling.action === "self-agent";
+ const workflowId = isSelfAgent
? subagentToolExecuteWorkflowReference.workflowId
: definition.behavior?.handling?.kind === "workflow-tool"
? definition.behavior.handling.workflowId
: undefined;
return {
+ availableInSubagents: definition.availableInSubagents,
behavior: prepareToolBehavior(
definition.behavior,
nodeId,
- isFrameworkAgent ? subagentToolExecuteWorkflowReference.workflowId : undefined,
+ isSelfAgent ? subagentToolExecuteWorkflowReference.workflowId : undefined,
),
description: definition.description,
execution: definition.execution,
@@ -103,12 +106,12 @@ async function createPreparedRuntimeTool(
name: definition.name,
owner: definition.owner,
outputSchema: serializeOutputSchema(definition.outputSchema),
- rootOnly: isFrameworkAgent || undefined,
+ rootOnly: isSelfAgent || undefined,
sourceId: definition.sourceId,
task:
workflowId === undefined
? undefined
- : isFrameworkAgent
+ : isSelfAgent
? {
nodeId: ROOT_RUNTIME_AGENT_NODE_ID,
resultKind: "subagent",
diff --git a/packages/eve/src/tools/definition.ts b/packages/eve/src/tools/definition.ts
index 9f2c7e318..9e61ba368 100644
--- a/packages/eve/src/tools/definition.ts
+++ b/packages/eve/src/tools/definition.ts
@@ -36,6 +36,8 @@ export type ToolExecuteFn<TInput = unknown, TOutput = unknown> = (
export type ToolExecution = "background";
interface ToolDefinitionBase {
+ /** Whether delegated agent sessions receive this tool. Defaults to `true`. */
+ readonly availableInSubagents?: boolean;
readonly description: string;
readonly execution?: ToolExecution;
}
diff --git a/packages/eve/src/tools/dynamic.ts b/packages/eve/src/tools/dynamic.ts
index 6e5ba6195..7eb72a148 100644
--- a/packages/eve/src/tools/dynamic.ts
+++ b/packages/eve/src/tools/dynamic.ts
@@ -23,6 +23,7 @@ import type { ToolModelOutput } from "#tools/model-output.js";
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export interface DynamicToolEntry<TInput = Record<string, unknown>, TOutput = any> {
+ readonly availableInSubagents?: boolean;
readonly label?: ToolLabelDefinition<TInput, TOutput>;
readonly description: string;
readonly inputSchema: PublicToolInputSchema<TInput>;
diff --git a/packages/eve/src/tools/provided/agent-router.test.ts b/packages/eve/src/tools/provided/agent-router.test.ts
index b9cb4cef2..ce1e12110 100644
--- a/packages/eve/src/tools/provided/agent-router.test.ts
+++ b/packages/eve/src/tools/provided/agent-router.test.ts
@@ -13,6 +13,7 @@ describe("agentRouter", () => {
it("defines a workflow tool", () => {
const definition = agentRouter();
+ expect(definition.availableInSubagents).toBe(false);
expect(definition.description).toContain("best available subagent");
expect(definition.execute).toBe(executeAgentRouterTool);
});
@@ -52,7 +53,24 @@ describe("agentRouter", () => {
expect(agent).toHaveBeenCalledWith("operator", { message: "Deploy the service" });
});
- it("invokes the only available agent without evaluation", async () => {
+ it("ignores agents without descriptions", async () => {
+ const agent = vi.fn().mockResolvedValue("researched");
+ const ctx = workflowContext({
+ agent,
+ agents: {
+ agent: { description: "" },
+ researcher: { description: "Investigate and explain." },
+ },
+ });
+
+ await expect(executeAgentRouterTool({ message: "Investigate" }, ctx)).resolves.toBe(
+ "researched",
+ );
+ expect(evaluate).not.toHaveBeenCalled();
+ expect(agent).toHaveBeenCalledWith("researcher", { message: "Investigate" });
+ });
+
+ it("invokes the only available described agent without evaluation", async () => {
const agent = vi.fn().mockResolvedValue("researched");
const ctx = workflowContext({
agent,
@@ -90,11 +108,14 @@ describe("agentRouter", () => {
});
});
- it("rejects an empty agent map before evaluation", async () => {
- const ctx = { agents: {} } as WorkflowToolContext;
+ it("rejects an agent map without descriptions before evaluation", async () => {
+ const ctx = workflowContext({
+ agent: vi.fn(),
+ agents: { agent: { description: " " } },
+ });
await expect(executeAgentRouterTool({ message: "Route me" }, ctx)).rejects.toThrow(
- "agentRouter requires at least one available declared subagent.",
+ "agentRouter requires at least one available agent with a description.",
);
expect(evaluate).not.toHaveBeenCalled();
});
diff --git a/packages/eve/src/tools/provided/agent-router.ts b/packages/eve/src/tools/provided/agent-router.ts
index 5c7acdf55..c6a8e9e49 100644
--- a/packages/eve/src/tools/provided/agent-router.ts
+++ b/packages/eve/src/tools/provided/agent-router.ts
@@ -14,9 +14,10 @@ export type { AgentRouterInput };
export type AgentRouterTool = BlockingWorkflowToolDefinition<AgentRouterInput, JsonValue>;
-/** Defines a workflow tool that uses JEV to route a task across all available declared subagents. */
+/** Defines a workflow tool that uses JEV to route a task across all available agent targets. */
export function agentRouter(): AgentRouterTool {
return defineWorkflowTool({
+ availableInSubagents: false,
description: AGENT_ROUTER_TOOL_DESCRIPTION,
execute: executeAgentRouterTool,
inputSchema: AGENT_ROUTER_INPUT_SCHEMA,
diff --git a/packages/eve/src/tools/workflow-definition.ts b/packages/eve/src/tools/workflow-definition.ts
index 96a7da4d8..a8d588f72 100644
--- a/packages/eve/src/tools/workflow-definition.ts
+++ b/packages/eve/src/tools/workflow-definition.ts
@@ -84,7 +84,7 @@ export type WorkflowToolContext = Pick<
ToolContext,
"abortSignal" | "callId" | "session" | "toolName" | "getToken" | "requireAuth"
> & {
- /** Invoke an agent by its path-derived name. */
+ /** Invoke an agent by its invocation name. */
agent: WorkflowAgent;
/** Metadata for agents callable by this workflow, including hidden agents. */
agents: Readonly<Record<string, WorkflowAgentMetadata>>;
diff --git a/packages/eve/test/runtime-tool-registry.test.ts b/packages/eve/test/runtime-tool-registry.test.ts
index efbd81e4e..6279b5ab3 100644
--- a/packages/eve/test/runtime-tool-registry.test.ts
+++ b/packages/eve/test/runtime-tool-registry.test.ts
@@ -94,40 +94,27 @@ describe("createRuntimeToolRegistry", () => {
expect(registry.preparedTools[0]).not.toHaveProperty("resultKind");
});
- it("uses the shared stable workflow for the framework agent tool", async () => {
+ it("keeps an authored workflow named agent separate from self-delegation", async () => {
+ const workflowId = "workflow//./agent/tools/agent//execute";
const registry = await createRuntimeToolRegistry({
tools: [
createResolvedToolDefinition({
behavior: {
availability: [],
- handling: {
- kind: "workflow-tool",
- workflowId: "workflow//./agent/tools/agent//execute",
- },
+ handling: { kind: "workflow-tool", workflowId },
},
logicalPath: "tools/agent.ts",
name: "agent",
- owner: { feature: "root-defaults", kind: "framework" },
- sourceId: "eve:root-defaults:tools/agent.ts",
+ sourceId: "tools/agent.ts",
}),
],
});
const prepared = registry.preparedTools[0];
- expect(subagentToolExecuteWorkflowReference.workflowId).toMatch(
- /^workflow\/\/[^/]+\/\/subagentToolExecuteWorkflow$/,
- );
- expect(prepared?.task).toEqual({
- nodeId: "__root__",
- resultKind: "subagent",
- workflowId: subagentToolExecuteWorkflowReference.workflowId,
- });
+ expect(prepared?.task).toEqual({ workflowId });
expect(prepared?.behavior?.handling).toEqual({
kind: "dispatch",
- target: {
- kind: "workflow-tool-call",
- workflowId: subagentToolExecuteWorkflowReference.workflowId,
- },
+ target: { kind: "workflow-tool-call", workflowId },
});
});
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 847d4b7ce..437bdc92b 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1089,7 +1089,7 @@ importers:
version: link:../e2e-config
'@workflow/world-postgres':
specifier: 'catalog:'
eve:
specifier: workspace:*
version: link:../../../packages/eve
diff --git a/research/subagent-tool-projection.md b/research/subagent-tool-projection.md
index d148b205e..92e6eb1d6 100644
--- a/research/subagent-tool-projection.md
+++ b/research/subagent-tool-projection.md
@@ -1,7 +1,7 @@
---
issue: TBD
status: in-progress
-last_updated: "2026-09-17"
+last_updated: "2026-09-18"
---
# Subagent tool projection
@@ -37,10 +37,11 @@ The second form removes the derived `researcher` tool but not the `researcher` c
## Semantics
- `tool` defaults to `true` for root, local, remote, workspace, and dynamically selected agents.
-- Root `tool: false` removes the built-in `agent` tool unless an authored `agent/tools/agent.ts` overrides that slot.
+- Root `tool: false` removes the built-in `agent` tool unless an authored `agent/tools/agent.ts` overrides that slot. The authored slot may contain any tool definition; tool identity does not grant root-copy invocation authority.
- Subagent `tool: false` suppresses only its model-tool projection. Workflow `ctx.agent()` continues to resolve the child from the complete registry.
- A same-named `disableTool()` suppresses a declared subagent's projection or the root built-in `agent` tool.
-- A same-named authored tool and subagent may coexist only when the subagent's tool projection is disabled. The authored tool owns the model name; `ctx.agent(name, input)` owns the child-agent name.
+- A same-named authored tool and subagent may coexist only when the subagent's tool projection is disabled. The authored tool owns the model name; `ctx.agent(name, input)` owns the child-agent name. The name `agent` is reserved for the built-in root-copy target and cannot identify a declared subagent.
+- `availableInSubagents: false` compiles a tool as top-level-root-only. `agentRouter()` sets it automatically, so it can own the model-facing `agent` slot without being inherited by a delegated root copy.
- Hidden subagents retain their description, execution, authorization, task lifecycle, tracing, limits, output schema, and continuation behavior.
- A nullish dynamic subagent selection remains unavailable to every caller. `tool: false` is visibility, not availability.
@@ -50,7 +51,7 @@ Each compiled agent node records its selected tools and source-composition decis
## Workflow metadata
-A workflow tool receives `ctx.agents`, a replay-stable snapshot of effective declared-subagent descriptions keyed by path-derived name. The snapshot includes model-visible and hidden local, remote, and active dynamic subagents, but not the built-in root-copy `agent` target, model definitions, credentials, or callbacks. Workflow invocation remains separate:
+A workflow tool receives `ctx.agents`, a replay-stable snapshot of effective callable-agent descriptions keyed by invocation name. In a top-level root session, the snapshot includes the built-in root-copy `agent` target plus model-visible and hidden local, remote, and active dynamic subagents. The root-copy entry carries an empty description when the root omits its optional description. Delegated root-copy and declared subagent contexts include only their declared targets because recursive root copying is unavailable. The snapshot contains no model definitions, credentials, or callbacks. Workflow invocation remains separate:
```ts
const target = await chooseTarget(task, {
@@ -63,4 +64,4 @@ return ctx.agent(target, { message: task });
The owner snapshots metadata when it starts the workflow run. Older in-flight workflow payloads default to an empty metadata registry. `ctx.agent()` still validates availability at invocation time, so a dynamic agent that becomes unavailable after the snapshot cannot be invoked through stale metadata.
-The provided `agentRouter()` workflow tool sends its input message and the complete `ctx.agents` description map to the default evaluation model (`typesafe-ai/jev`), then invokes the selected path-derived name. It forwards an optional output schema and rejects an empty declared-subagent map before evaluation. Authors use `defineWorkflowTool` directly when routing requires a subset, custom instructions, or a non-default evaluator.
+The provided `agentRouter()` workflow tool filters `ctx.agents` to entries with non-empty descriptions, sends its input message and that description map to the default evaluation model (`typesafe-ai/jev`), then invokes the selected name. It forwards an optional output schema and rejects an empty target map before evaluation. Authors use `defineWorkflowTool` directly when routing requires a subset, custom instructions, or a non-default evaluator.