agy-cli: run_command's toolSummary no longer collides with agy's own (#1174)

agy-cli forwards a run_command tool that declares toolSummary when agy adds its own.

agy adds a required toolSummary to the MCP tools it loads. When the client's own run_command already lists toolSummary as required, the duplicate makes the schema invalid and the toolbox fails to start. The bridge now drops toolSummary from run_command's required list when it lists the tool. On the way back it fills in "Run command" when agy kept the summary to itself and the client's schema declares the property. A summary the model sent is kept, and a schema without the property is left alone.

Run at 52b77b78 on mote: packages/agy-cli `bun test` 25/25. Broken by hand: with main's index.mjs, the new tool-summary test goes red. The author checked a live agy client: run_command is the only tool that requires toolSummary, and an agy-to-magpie-to-agy session ran `pwd`. Not tried here: a live agy session, since the local agy account is disabled.

Co-authored-by: andrew-zyf <andrew-zyf@users.noreply.github.com>
This commit is contained in:
𝘼𝙣𝙙𝙧𝙚𝙬 𝙕𝙮𝙛
2026-11-15 15:42:32 +08:00
committed by GitHub
co-authored by andrew-zyf
parent b840915abc
commit 491cea357d
3 changed files with 59 additions and 2 deletions
+1
View File
@@ -23,6 +23,7 @@ for (const [name, mocks] of [
["catalog.mjs", false], ["catalog.mjs", false],
["step-usage.mjs", false], ["step-usage.mjs", false],
["tool-schema.mjs", false], ["tool-schema.mjs", false],
["tool-summary.mjs", false],
["usage-settlement.mjs", false], ["usage-settlement.mjs", false],
["steer-in-session.mjs", false], ["steer-in-session.mjs", false],
["repeat-batch.mjs", false], ["repeat-batch.mjs", false],
+12 -2
View File
@@ -2325,9 +2325,14 @@ class Proc {
throw new Error("agy bridge: no prompt in flight for MCP call") throw new Error("agy bridge: no prompt in flight for MCP call")
} }
const name = message.name const name = message.name
const args = message.arguments ?? {} let args = message.arguments ?? {}
if (!args || typeof args !== "object" || Array.isArray(args)) throw new Error("agy bridge: invalid tool arguments") if (!args || typeof args !== "object" || Array.isArray(args)) throw new Error("agy bridge: invalid tool arguments")
if (!this.tools.some((tool) => tool.name === name)) throw new Error(`agy bridge: undeclared tool ${name}`) const tool = this.tools.find((item) => item.name === name)
if (!tool) throw new Error(`agy bridge: undeclared tool ${name}`)
// agy consumes its internal toolSummary instead of forwarding it to MCP.
if (name === "run_command" && tool.inputSchema?.properties?.toolSummary && !Object.hasOwn(args, "toolSummary")) {
args = { ...args, toolSummary: "Run command" }
}
const signature = stableJSON(args) const signature = stableJSON(args)
const running = turn.calls.find((call) => call.deferred && !call.lateDelivered && const running = turn.calls.find((call) => call.deferred && !call.lateDelivered &&
call.name === name && stableJSON(call.arguments) === signature) call.name === name && stableJSON(call.arguments) === signature)
@@ -4138,6 +4143,11 @@ function normalizeTools(body) {
throw new UnsupportedContent(`an invalid schema for tool ${tool.name}`) throw new UnsupportedContent(`an invalid schema for tool ${tool.name}`)
} }
const inputSchema = ensureGeminiArrayItems(sanitizeInputSchema(expandToolSchema(rawSchema))) const inputSchema = ensureGeminiArrayItems(sanitizeInputSchema(expandToolSchema(rawSchema)))
// agy adds its own required toolSummary to MCP tools. A duplicate makes
// the resulting JSON Schema invalid before the agent can start.
if (tool.name === "run_command" && Array.isArray(inputSchema.required)) {
inputSchema.required = inputSchema.required.filter((key) => key !== "toolSummary")
}
tools.push({ tools.push({
name: tool.name, name: tool.name,
description: typeof tool.description === "string" ? tool.description : "", description: typeof tool.description === "string" ? tool.description : "",
+46
View File
@@ -0,0 +1,46 @@
import { test } from "node:test"
import assert from "node:assert/strict"
import { baseBody, createBridgeKit, readSse } from "./testkit.mjs"
async function callRunCommand(inputSchema, args) {
const kit = await createBridgeKit()
try {
let listed
kit.prompts.push(async (agent) => {
listed = await agent.listTools()
await agent.tool("run_command", args)
})
const body = baseBody({ tools: [{ name: "run_command", input_schema: inputSchema }] })
const result = await readSse(await kit.request(body))
return { schema: listed.result.tools[0].inputSchema, call: result.content.find((item) => item.type === "tool_use") }
} finally {
await kit.dispose()
}
}
test("run_command avoids agy's toolSummary collision and restores the argument for the client", async () => {
const schema = {
type: "object",
properties: { CommandLine: { type: "string" }, toolSummary: { type: "string" } },
required: ["CommandLine", "toolSummary"],
additionalProperties: false,
}
const result = await callRunCommand(schema, { CommandLine: "pwd" })
assert.deepEqual(result.schema.required, ["CommandLine"])
assert.deepEqual(result.call.input, { CommandLine: "pwd", toolSummary: "Run command" })
assert.deepEqual(schema.required, ["CommandLine", "toolSummary"])
})
test("run_command keeps supplied summaries and does not add one to unrelated schemas", async () => {
const schema = {
type: "object",
properties: { CommandLine: { type: "string" }, toolSummary: { type: "string" } },
required: ["CommandLine", "toolSummary"],
}
const supplied = await callRunCommand(schema, { CommandLine: "pwd", toolSummary: "Show location" })
assert.equal(supplied.call.input.toolSummary, "Show location")
const withoutSummary = await callRunCommand({
type: "object", properties: { command: { type: "string" } }, required: ["command"], additionalProperties: false,
}, { command: "pwd" })
assert.deepEqual(withoutSummary.call.input, { command: "pwd" })
})