Description
I noticed that when I create custom tools in the ./tool directory and use .describe() on the arguments, those descriptions aren't showing up in the prompts sent to the LLM. The agent doesn't seem to know what the parameters are for, which leads to incorrect usage. At the moment I am adding them to the description of the tool itself, which is not ideal.
After digging through the source code, I found the issue. There are two different methods being used to convert Zod schemas to JSON Schema:
- In
server.ts (line 307) - uses zodToJsonSchema() from the zod-to-json-schema package ✅
- In
prompt.ts (line 581) - uses z.toJSONSchema() from Zod's built-in method ❌
The problem is that z.toJSONSchema() doesn't properly extract the .describe() metadata from schema properties, so all those descriptions get dropped before reaching the LLM.
(Possible) Fix:
Change line 581 in session/prompt.ts from:
const schema = ProviderTransform.schema(input.providerID, input.modelID, z.toJSONSchema(item.parameters))
To:
const schema = ProviderTransform.schema(input.providerID, input.modelID, zodToJsonSchema(item.parameters))
And add the import at the top:
import { zodToJsonSchema } from "zod-to-json-schema"
This makes the schema conversion consistent with what's already being done in server.ts and ensures all tool descriptions are properly passed to the LLM.
OpenCode version
v1.0.65
Steps to reproduce
For example, I have a tool like this:
export default tool({
description: "Return the length of a string",
args: {
text: z.string().describe("The text string to measure"),
},
// ...
});
I expected the LLM to see the description "The text string to measure" for the text parameter, but it's not getting that information.
Screenshot and/or share link
No response
Operating System
Arch Linux
Terminal
foot
Description
I noticed that when I create custom tools in the
./tooldirectory and use.describe()on the arguments, those descriptions aren't showing up in the prompts sent to the LLM. The agent doesn't seem to know what the parameters are for, which leads to incorrect usage. At the moment I am adding them to the description of the tool itself, which is not ideal.After digging through the source code, I found the issue. There are two different methods being used to convert Zod schemas to JSON Schema:
server.ts(line 307) - useszodToJsonSchema()from thezod-to-json-schemapackage ✅prompt.ts(line 581) - usesz.toJSONSchema()from Zod's built-in method ❌The problem is that
z.toJSONSchema()doesn't properly extract the.describe()metadata from schema properties, so all those descriptions get dropped before reaching the LLM.(Possible) Fix:
Change line 581 in
session/prompt.tsfrom:To:
And add the import at the top:
This makes the schema conversion consistent with what's already being done in
server.tsand ensures all tool descriptions are properly passed to the LLM.OpenCode version
v1.0.65
Steps to reproduce
For example, I have a tool like this:
I expected the LLM to see the description "The text string to measure" for the
textparameter, but it's not getting that information.Screenshot and/or share link
No response
Operating System
Arch Linux
Terminal
foot