diff --git a/extensions/gentle-agents.ts b/extensions/gentle-agents.ts index 120eafb41..accd62c0b 100644 --- a/extensions/gentle-agents.ts +++ b/extensions/gentle-agents.ts @@ -563,6 +563,15 @@ const ACTION_HEADING: Record = { list_tasks: "Agent tasks", list_agents: "Agent roster", }; +// Models trained on orchestration tools often attach `reason` to every call; listing tools ignore it. +const LIST_TOOL_PARAMS = { + properties: { + reason: { + type: "string", + description: "Optional caller note. Ignored for this read-only listing tool.", + }, + }, +} as const; // The state word as a scanable pill: uppercase, colored by the state's role. function statusPill(status: string, theme: CardTheme): string { @@ -3404,7 +3413,7 @@ export default function gentleAgents(pi: ExtensionAPI, env: NodeJS.ProcessEnv = }, }); - tool("list_agents", "List the subagents defined for this project and user, with their descriptions and declared tool inventory.", { properties: {} }, async (_params, ctx) => { + tool("list_agents", "List the subagents defined for this project and user, with their descriptions and declared tool inventory. No required arguments; an optional reason is ignored.", LIST_TOOL_PARAMS, async (_params, ctx) => { const { agents, errors, notices } = discoverAgents(roots(ctx)); const lines = agents.map((agent) => `- ${agent.name} (${agent.scope}): ${agent.description || "no description"} ${declaredToolInventory(agent)}`); const problems = [...errors, ...notices].map((problem) => `! ${problem}`); @@ -3486,7 +3495,7 @@ export default function gentleAgents(pi: ExtensionAPI, env: NodeJS.ProcessEnv = return text(isFinished(task.status) ? finishedText(task) : `Task ${task.id} is still ${task.status} (last: ${task.lastStep}).`, taskDetails(task)); }); - tool("list_tasks", "List the subagent tasks of this session, newest first.", { properties: {} }, async (_params, ctx) => { + tool("list_tasks", "List the subagent tasks of this session, newest first. No required arguments; an optional reason is ignored.", LIST_TOOL_PARAMS, async (_params, ctx) => { await sessionRestoration; const sessionId = ctx.sessionManager.getSessionId() ?? ""; const tasks = store.list(sessionId); diff --git a/tests/gentle-agents.test.ts b/tests/gentle-agents.test.ts index 6de9a568b..ebd6a22fa 100644 --- a/tests/gentle-agents.test.ts +++ b/tests/gentle-agents.test.ts @@ -12,7 +12,7 @@ import { SessionChanges, type SessionChangeEvidence } from "../lib/session-chang import test, { after, afterEach, before, mock } from "node:test"; import type { TestContext } from "node:test"; import { generateUnifiedPatch, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent"; -import { createAssistantMessageEventStream, type AssistantMessage } from "@earendil-works/pi-ai"; +import { createAssistantMessageEventStream, validateToolArguments, type AssistantMessage } from "@earendil-works/pi-ai"; import { visibleWidth, type Component, type TUI, type TuiMouseEvent } from "@earendil-works/pi-tui"; import { sidebarState } from "../lib/shell-sidebar.ts"; import { CHILD_PACKAGE_INJECTION_ENV, encodeChildPackageInjection } from "../lib/child-package-injection.ts"; @@ -55,7 +55,7 @@ interface Registered { parameters: { properties: Record }; renderShell?: string; name: string; - execute(id: string, params: unknown, signal: AbortSignal | undefined, onUpdate: undefined, ctx: ExtensionContext): Promise<{ content: Array<{ text: string }>; details: Record }>; + execute(id: string, params: unknown, signal: AbortSignal | undefined, onUpdate: undefined, ctx: ExtensionContext): Promise<{ content: Array<{ text: string }>; details: Record; isError?: boolean }>; renderCall(args: unknown, theme: unknown, context?: unknown): { render(width: number): string[] }; renderResult(result: { content: Array<{ type: string; text: string }>; details: Record | undefined }, options: { expanded: boolean; isPartial?: boolean }, theme: unknown, context?: unknown): { render(width: number): string[] }; } @@ -4308,6 +4308,21 @@ test("subagent_list_agents publishes each agent's declared tool inventory so rou } finally { rmSync(fixture, TEST_DIR_REMOVAL); } }); +test("subagent_list_agents accepts an optional reason field models often attach spuriously", async () => { + const h = fakePi(); + gentleAgents(h.pi, {}, deps().deps); + const { ctx } = fakeContext(); + await h.fire("session_start", ctx); + const listAgents = h.tools.get("subagent_list_agents")!; + const listTasks = h.tools.get("subagent_list_tasks")!; + const reason = "need explorer agent name for codebase mapping"; + for (const tool of [listAgents, listTasks]) { + validateToolArguments(tool as never, { type: "toolCall", id: "c-reason", name: tool.name, arguments: { reason } }); + const result = await tool.execute("c-reason", { reason }, undefined, undefined, ctx); + assert.notEqual(result.isError, true); + } +}); + test("subagent_list_agents and subagent_run in task mode launch a child with the resolved profile and return its answer", async () => { const { pi, tools, fire } = fakePi(); const harness = deps();