The Open Framework for Building Agents
fix(eve): separate subagent child prompt descriptions (#397)
Ruic7827fb9b043
diff --git a/.changeset/fix-subagent-child-prompt.md b/.changeset/fix-subagent-child-prompt.mdnew file mode 100644index 000000000..20c494d43--- /dev/null+++ b/.changeset/fix-subagent-child-prompt.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Stop injecting subagent tool descriptions into delegated child prompts. Child runs now receive only the caller's delegated message plus the stable subagent invocation wrapper.diff --git a/packages/eve/src/execution/dispatch-runtime-actions-step.ts b/packages/eve/src/execution/dispatch-runtime-actions-step.tsindex 117037be6..5f831d4f6 100644--- a/packages/eve/src/execution/dispatch-runtime-actions-step.ts+++ b/packages/eve/src/execution/dispatch-runtime-actions-step.ts@@ -40,7 +40,7 @@ import {startRemoteAgentSession,} from "#execution/remote-agent-dispatch.js";import { hydrateDurableSession } from "#execution/session.js";-import { buildSubagentRunInput } from "#execution/subagent-tool.js";+import { buildSubagentRunInput, type SubagentInputSource } from "#execution/subagent-tool.js";import { createWorkflowRuntime, workflowEntryReference } from "#execution/workflow-runtime.js";import { createLogger, logError } from "#internal/logging.js";import { toErrorMessage } from "#shared/errors.js";@@ -97,6 +97,11 @@ export async function dispatchRuntimeActionsStep(input: {switch (action.kind) {case "subagent-call": {+ const registered = bundle.subagentRegistry.subagentsByNodeId.get(action.nodeId);+ const source: SubagentInputSource =+ registered?.definition.kind === "subagent"+ ? { description: registered.definition.description, type: "local" }+ : { type: "runtime" };const childRuntime = createWorkflowRuntime({compiledArtifactsSource: bundle.compiledArtifactsSource,nodeId: action.nodeId,@@ -110,6 +115,7 @@ export async function dispatchRuntimeActionsStep(input: {initiatorAuth,parentContinuationToken: input.parentContinuationToken,session,+ source,});const handle = await childRuntime.run(runInput);diff --git a/packages/eve/src/execution/remote-agent-dispatch.test.ts b/packages/eve/src/execution/remote-agent-dispatch.test.tsindex 9cf507cd3..8bee9f871 100644--- a/packages/eve/src/execution/remote-agent-dispatch.test.ts+++ b/packages/eve/src/execution/remote-agent-dispatch.test.ts@@ -177,7 +177,7 @@ describe("startRemoteAgentSession", () => {function createAction(): RuntimeRemoteAgentCallActionRequest {return {callId: "call-remote",- description: "Performs research.",+ description: "Runtime action event description.",input: { message: "find the marker" },kind: "remote-agent-call",name: "research",diff --git a/packages/eve/src/execution/remote-agent-dispatch.ts b/packages/eve/src/execution/remote-agent-dispatch.tsindex 0e8401ea6..a74182013 100644--- a/packages/eve/src/execution/remote-agent-dispatch.ts+++ b/packages/eve/src/execution/remote-agent-dispatch.ts@@ -1,7 +1,7 @@import { EVE_SESSION_ID_HEADER } from "#protocol/message.js";import { createEveCallbackRoutePath } from "#protocol/routes.js";import { createWorkflowCallbackUrl } from "#execution/workflow-callback-url.js";-import { formatSubagentInvocation } from "#execution/subagent-invocation.js";+import { formatSubagentInput } from "#execution/subagent-invocation.js";import type { HarnessSession } from "#harness/types.js";import type { RuntimeRemoteAgentCallActionRequest } from "#runtime/actions/types.js";import type { RuntimeSubagentRegistry } from "#runtime/subagents/registry.js";@@ -34,7 +34,7 @@ export async function startRemoteAgentSession(input: {createEveCallbackRoutePath(callbackToken),),},- message: formatRemoteAgentCallInputMessage(input.action),+ message: formatRemoteAgentCallInputMessage({ action: input.action, remote: input.remote }),mode: "task",outputSchema:(input.action.input.outputSchema as object | undefined) ?? input.remote.outputSchema,@@ -104,12 +104,16 @@ async function resolveRemoteAgentRequestHeaders(return headers;}-function formatRemoteAgentCallInputMessage(input: RuntimeRemoteAgentCallActionRequest): string {- const message = typeof input.input.message === "string" ? input.input.message : "";- return formatSubagentInvocation({- description: input.description,+function formatRemoteAgentCallInputMessage(input: {+ readonly action: RuntimeRemoteAgentCallActionRequest;+ readonly remote: ResolvedRuntimeRemoteAgentNode;+}): string {+ const message = typeof input.action.input.message === "string" ? input.action.input.message : "";+ return formatSubagentInput({+ description: input.remote.description,message,- name: input.remoteAgentName,+ name: input.action.remoteAgentName,+ type: "remote",}).message;}diff --git a/packages/eve/src/execution/subagent-invocation.ts b/packages/eve/src/execution/subagent-invocation.tsindex 05e661f74..0fe3c8247 100644--- a/packages/eve/src/execution/subagent-invocation.ts+++ b/packages/eve/src/execution/subagent-invocation.ts@@ -8,18 +8,90 @@ export interface FormattedSubagentInvocation extends StepInput {readonly message: string;}+type RuntimeSubagentInputFormatRequest = {+ readonly message: string;+ readonly name: string;+ readonly type: "runtime";+};++type LocalSubagentInputFormatRequest = {+ readonly description: string;+ readonly message: string;+ readonly name: string;+ readonly type: "local";+};++type RemoteSubagentInputFormatRequest = {+ readonly description: string;+ readonly message: string;+ readonly name: string;+ readonly type: "remote";+};++type SubagentInputFormatRequest =+ | RuntimeSubagentInputFormatRequest+ | LocalSubagentInputFormatRequest+ | RemoteSubagentInputFormatRequest;++type SubagentInputFormatters = {+ readonly runtime: (input: RuntimeSubagentInputFormatRequest) => FormattedSubagentInvocation;+ readonly local: (input: LocalSubagentInputFormatRequest) => FormattedSubagentInvocation;+ readonly remote: (input: RemoteSubagentInputFormatRequest) => FormattedSubagentInvocation;+};++const formatSubagentInputByType = {+ runtime(input) {+ return formatSubagentPrompt({+ descriptionLines: [],+ message: input.message,+ name: input.name,+ });+ },+ local(input) {+ return formatSubagentPrompt({+ descriptionLines: formatDescriptionLines(input.description),+ message: input.message,+ name: input.name,+ });+ },+ remote(input) {+ return formatSubagentPrompt({+ descriptionLines: formatDescriptionLines(input.description),+ message: input.message,+ name: input.name,+ });+ },+} satisfies SubagentInputFormatters;+/*** Formats the stable delegated input handed to one child agent invocation.*/-export function formatSubagentInvocation(input: {- readonly description: string;+export function formatSubagentInput(+ input: SubagentInputFormatRequest,+): FormattedSubagentInvocation {+ switch (input.type) {+ case "runtime":+ return formatSubagentInputByType.runtime(input);+ case "local":+ return formatSubagentInputByType.local(input);+ case "remote":+ return formatSubagentInputByType.remote(input);+ default: {+ const _exhaustive: never = input;+ return _exhaustive;+ }+ }+}++function formatSubagentPrompt(input: {+ readonly descriptionLines: readonly string[];readonly message: string;readonly name: string;}): FormattedSubagentInvocation {return {message: [`You are the subagent "${input.name}".`,- `Description: ${input.description}`,+ ...input.descriptionLines,"","The caller delegated the following task to you. Complete it and return the final result directly.","",@@ -28,3 +100,7 @@ export function formatSubagentInvocation(input: {].join("\n"),};}++function formatDescriptionLines(description: string): readonly string[] {+ return description.trim().length > 0 ? [`Description: ${description}`] : [];+}diff --git a/packages/eve/src/execution/subagent-tool.test.ts b/packages/eve/src/execution/subagent-tool.test.tsindex 6c35c206f..f32ce0560 100644--- a/packages/eve/src/execution/subagent-tool.test.ts+++ b/packages/eve/src/execution/subagent-tool.test.ts@@ -5,6 +5,8 @@ import type { HarnessSession } from "#harness/types.js";import type { RuntimeSubagentCallActionRequest } from "#runtime/actions/types.js";import { buildSubagentRunInput } from "#execution/subagent-tool.js";+type BuildSubagentRunInput = Parameters<typeof buildSubagentRunInput>[0];+function makeSession(): HarnessSession {return {agent: {@@ -31,9 +33,15 @@ function makeAction(): RuntimeSubagentCallActionRequest {};}+function buildRuntimeSubagentRunInput(+ input: Omit<BuildSubagentRunInput, "source">,+): ReturnType<typeof buildSubagentRunInput> {+ return buildSubagentRunInput({ ...input, source: { type: "runtime" } });+}+describe("buildSubagentRunInput", () => {it("forwards parent capabilities to the child run input", () => {- const { runInput } = buildSubagentRunInput({+ const { runInput } = buildRuntimeSubagentRunInput({action: makeAction(),auth: null,batchEvent: { sequence: 0, turnId: "turn-0" },@@ -46,7 +54,7 @@ describe("buildSubagentRunInput", () => {});it("leaves capabilities undefined when the parent has none", () => {- const { runInput } = buildSubagentRunInput({+ const { runInput } = buildRuntimeSubagentRunInput({action: makeAction(),auth: null,batchEvent: { sequence: 0, turnId: "turn-0" },@@ -58,7 +66,7 @@ describe("buildSubagentRunInput", () => {});it("sets the subagent adapter state with parent lineage metadata", () => {- const { childContinuationToken, runInput } = buildSubagentRunInput({+ const { childContinuationToken, runInput } = buildRuntimeSubagentRunInput({action: makeAction(),auth: null,batchEvent: { sequence: 5, turnId: "turn-17" },@@ -84,7 +92,7 @@ describe("buildSubagentRunInput", () => {});it("routes parent notifications to an active turn inbox when supplied", () => {- const { runInput } = buildSubagentRunInput({+ const { runInput } = buildRuntimeSubagentRunInput({action: makeAction(),auth: null,batchEvent: { sequence: 0, turnId: "turn-0" },@@ -103,7 +111,7 @@ describe("buildSubagentRunInput", () => {kind: "channel:slack",metadata: { threadTs: "1234.5678", userId: "U123" },};- const { runInput } = buildSubagentRunInput({+ const { runInput } = buildRuntimeSubagentRunInput({action: makeAction(),auth: null,batchEvent: { sequence: 0, turnId: "turn-0" },@@ -116,7 +124,7 @@ describe("buildSubagentRunInput", () => {});it("leaves channelMetadata undefined when the parent has none", () => {- const { runInput } = buildSubagentRunInput({+ const { runInput } = buildRuntimeSubagentRunInput({action: makeAction(),auth: null,batchEvent: { sequence: 0, turnId: "turn-0" },@@ -133,7 +141,7 @@ describe("buildSubagentRunInput", () => {rootSessionId: "root-session-from-top",sessionId: "intermediate-session",};- const { runInput } = buildSubagentRunInput({+ const { runInput } = buildRuntimeSubagentRunInput({action: makeAction(),auth: null,batchEvent: { sequence: 1, turnId: "turn-99" },@@ -155,7 +163,7 @@ describe("buildSubagentRunInput", () => {...makeAction(),input: { message: "do something", outputSchema: schema },};- const { runInput } = buildSubagentRunInput({+ const { runInput } = buildRuntimeSubagentRunInput({action,auth: null,batchEvent: { sequence: 0, turnId: "turn-0" },@@ -166,8 +174,64 @@ describe("buildSubagentRunInput", () => {expect(runInput.input.outputSchema).toEqual(schema);});- it("leaves outputSchema undefined when not provided", () => {+ it("passes a resolved local subagent description into the child message", () => {const { runInput } = buildSubagentRunInput({+ action: {+ ...makeAction(),+ description: "Runtime action event description.",+ },+ auth: null,+ batchEvent: { sequence: 0, turnId: "turn-0" },+ initiatorAuth: null,+ session: makeSession(),+ source: { description: "Local delegate subagent description.", type: "local" },+ });++ expect(runInput.input.message).toBe(+ [+ 'You are the subagent "linear".',+ "Description: Local delegate subagent description.",+ "",+ "The caller delegated the following task to you. Complete it and return the final result directly.",+ "",+ "Caller message:",+ "Make an issue titled 'Resolve flaky test'.",+ ].join("\n"),+ );+ expect(runInput.input.message).not.toContain("Runtime action event description.");+ });++ it("does not pass the built-in agent tool description into the child message", () => {+ const action: RuntimeSubagentCallActionRequest = {+ ...makeAction(),+ description: "Delegate a focused subtask to a fresh copy of yourself.",+ name: "agent",+ nodeId: "root",+ subagentName: "agent",+ };+ const { runInput } = buildRuntimeSubagentRunInput({+ action,+ auth: null,+ batchEvent: { sequence: 0, turnId: "turn-0" },+ initiatorAuth: null,+ session: makeSession(),+ });++ expect(runInput.input.message).toBe(+ [+ `You are the subagent "${action.subagentName}".`,+ "",+ "The caller delegated the following task to you. Complete it and return the final result directly.",+ "",+ "Caller message:",+ "Make an issue titled 'Resolve flaky test'.",+ ].join("\n"),+ );+ expect(runInput.input.message).not.toContain(action.description);+ });++ it("leaves outputSchema undefined when not provided", () => {+ const { runInput } = buildRuntimeSubagentRunInput({action: makeAction(),auth: null,batchEvent: { sequence: 0, turnId: "turn-0" },@@ -185,7 +249,7 @@ describe("buildSubagentRunInput", () => {...makeAction(),subagentName: "agent",};- const { runInput } = buildSubagentRunInput({+ const { runInput } = buildRuntimeSubagentRunInput({action,auth: null,batchEvent: { sequence: 0, turnId: "turn-0" },@@ -202,7 +266,7 @@ describe("buildSubagentRunInput", () => {it("does not include sandbox sharing fields for normal subagents", () => {const sandboxState = { initialized: true, session: null };const session = { ...makeSession(), sandboxState };- const { runInput } = buildSubagentRunInput({+ const { runInput } = buildRuntimeSubagentRunInput({action: makeAction(),auth: null,batchEvent: { sequence: 0, turnId: "turn-0" },diff --git a/packages/eve/src/execution/subagent-tool.ts b/packages/eve/src/execution/subagent-tool.tsindex a5ef0f50c..bf9e4731a 100644--- a/packages/eve/src/execution/subagent-tool.ts+++ b/packages/eve/src/execution/subagent-tool.ts@@ -1,5 +1,5 @@import { SUBAGENT_ADAPTER_KIND } from "#execution/subagent-adapter.js";-import { formatSubagentInvocation } from "#execution/subagent-invocation.js";+import { formatSubagentInput } from "#execution/subagent-invocation.js";import type {ChannelInstrumentationProjection,RunInput,@@ -19,6 +19,15 @@ interface BatchEventMetadata {readonly turnId: string;}+export type SubagentInputSource =+ | {+ readonly description: string;+ readonly type: "local";+ }+ | {+ readonly type: "runtime";+ };+/*** Result of {@link buildSubagentRunInput}.*@@ -49,8 +58,18 @@ export function buildSubagentRunInput(input: {/** Hook token owned by the workflow currently waiting for this child. */readonly parentContinuationToken?: string;readonly session: HarnessSession;+ readonly source: SubagentInputSource;}): SubagentRunInputBuild {- const { action, auth, batchEvent, capabilities, channelMetadata, initiatorAuth, session } = input;+ const {+ action,+ auth,+ batchEvent,+ capabilities,+ channelMetadata,+ initiatorAuth,+ session,+ source,+ } = input;const childContinuationToken = mintSubagentContinuationToken(`${session.sessionId}:${action.callId}`,@@ -84,7 +103,7 @@ export function buildSubagentRunInput(input: {continuationToken: childContinuationToken,initiatorAuth,input: {- message: formatSubagentCallInputMessage(action),+ message: formatSubagentCallInputMessage({ action, source }),outputSchema: action.input.outputSchema as JsonObject | undefined,},mode: "task",@@ -105,14 +124,29 @@ export function buildSubagentRunInput(input: {/*** Formats the synthesized child input message for one delegated subagent call.*/-function formatSubagentCallInputMessage(- action: Pick<RuntimeSubagentCallActionRequest, "description" | "input" | "subagentName">,-): string {- const { message } = action.input as { message: string };+function formatSubagentCallInputMessage(input: {+ readonly action: Pick<RuntimeSubagentCallActionRequest, "input" | "subagentName">;+ readonly source: SubagentInputSource;+}): string {+ const { message } = input.action.input as { message: string };- return formatSubagentInvocation({- description: action.description,- message,- name: action.subagentName,- }).message;+ switch (input.source.type) {+ case "local":+ return formatSubagentInput({+ description: input.source.description,+ message,+ name: input.action.subagentName,+ type: "local",+ }).message;+ case "runtime":+ return formatSubagentInput({+ message,+ name: input.action.subagentName,+ type: "runtime",+ }).message;+ default: {+ const _exhaustive: never = input.source;+ return _exhaustive;+ }+ }}diff --git a/packages/eve/src/execution/workflow-steps.test.ts b/packages/eve/src/execution/workflow-steps.test.tsindex 1c41dc503..2b01d0faa 100644--- a/packages/eve/src/execution/workflow-steps.test.ts+++ b/packages/eve/src/execution/workflow-steps.test.ts@@ -299,7 +299,19 @@ describe("dispatchRuntimeActionsStep", () => {},hookRegistry: createEmptyHookRegistry(),resolvedAgent: { config: {} },- subagentRegistry: {},+ subagentRegistry: {+ subagentsByNodeId: new Map([+ [+ "subagents/delegate",+ {+ definition: {+ description: "Local delegate child description.",+ kind: "subagent",+ },+ },+ ],+ ]),+ },toolRegistry: {},turnAgent: TestTurnAgent,} as never;@@ -318,7 +330,7 @@ describe("dispatchRuntimeActionsStep", () => {actions: [{callId: "call-1",- description: "Delegate the work.",+ description: "Runtime action event description.",input: { message: "investigate latest routing" },kind: "subagent-call",name: "delegate",@@ -353,7 +365,7 @@ describe("dispatchRuntimeActionsStep", () => {[expect.objectContaining({input: {- message: expect.stringContaining("investigate latest routing"),+ message: expect.stringContaining("Description: Local delegate child description."),},serializedContext: expect.objectContaining({"eve.channel": expect.objectContaining({@@ -373,6 +385,28 @@ describe("dispatchRuntimeActionsStep", () => {deploymentId: "latest",},);+ expect(startMock).toHaveBeenCalledWith(+ workflowEntryReference,+ [+ expect.objectContaining({+ input: {+ message: expect.stringContaining("investigate latest routing"),+ },+ }),+ ],+ expect.any(Object),+ );+ expect(startMock).toHaveBeenCalledWith(+ workflowEntryReference,+ [+ expect.objectContaining({+ input: {+ message: expect.not.stringContaining("Runtime action event description."),+ },+ }),+ ],+ expect.any(Object),+ );});it("returns a failed subagent result when remote session creation fails", async () => {