fix(core): return a renamed tool's structured output in Code Mode (#64333)

This commit is contained in:
Aiden Cline
2026-11-16 19:18:22 -06:00
committed by GitHub
Unverified
parent 62d06fab22
commit 18c9da079e
2 changed files with 34 additions and 1 deletions
+3 -1
View File
@@ -325,7 +325,9 @@ function inventoryTools(inventory: Inventory) {
description: child.description,
input: child.inputSchema,
freeform: registration.freeform !== undefined,
output: child.outputSchema ?? Schema.NullOr(Schema.String),
// JSON Schema, which Code Mode renders but does not check: Core has validated the result of the tool that ran,
// and a plugin may have renamed the call to a tool with another output.
output: child.outputSchema ?? { type: ["string", "null"] },
execute: (input) => Run.use((run) => run.executeTool(name, registration, input)),
})
}
+31
View File
@@ -1008,6 +1008,37 @@ describe("Tool", () => {
}),
)
it.effect("a call renamed inside a Code Mode program returns the renamed tool's structured output", () =>
Effect.gen(function* () {
const service = yield* Tool.Service
const hooks = yield* PluginHooks.Service
const plain: Info = {
name: "plain",
description: "Return text",
input: Schema.Struct({ text: Schema.String }),
execute: () => Effect.succeed({ content: "plain" }),
}
yield* transform(service, { plain, constant: constant("structured") })
yield* hooks.register("tool", "execute.before", (event) =>
Effect.sync(() => {
if (event.tool === "plain") event.tool = "constant"
}),
)
const snapshot = yield* service.snapshot()
const result = yield* snapshot.execute({
sessionID,
...identity,
call: {
type: "tool-call",
id: "call-program",
name: "execute",
input: { code: 'return await tools.plain({ text: "x" })' },
},
})
expect(result.output).toMatchObject({ output: JSON.stringify({ text: "structured" }) })
}),
)
it.effect("hooks see one ID per call inside a Code Mode program", () =>
Effect.gen(function* () {
const service = yield* Tool.Service