Skip to content

Commit 9664e47

Browse files
author
shihzu
committed
fix: preserve tool parameter descriptions in schema conversion
- Replace z.toJSONSchema() with zodToJsonSchema() in prompt.ts - Ensures .describe() metadata is properly passed to LLM - Fixes anomalyco#4357 The z.toJSONSchema() method was dropping .describe() metadata from tool parameters, causing the LLM to not understand what the parameters are for. This change aligns with the approach already used in server.ts.
1 parent 48412f7 commit 9664e47

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

‎.opencode/tools/test-describe.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { z } from "zod"
2+
import { Tool } from "@/tool/tool"
3+
4+
export default Tool.define("test_describe", async () => {
5+
return {
6+
description: "Test tool to verify parameter descriptions are passed to LLM",
7+
parameters: z.object({
8+
message: z.string().describe("The message to process"),
9+
count: z.number().describe("Number of times to repeat the message"),
10+
}),
11+
async execute(args) {
12+
return Array(args.count).fill(args.message).join("\n")
13+
},
14+
}
15+
})

‎packages/opencode/src/session/prompt.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "path"
22
import os from "os"
33
import fs from "fs/promises"
44
import z from "zod"
5+
import { zodToJsonSchema } from "zod-to-json-schema"
56
import { Filesystem } from "../util/filesystem"
67
import { Identifier } from "../id/id"
78
import { MessageV2 } from "./message-v2"
@@ -784,7 +785,7 @@ export namespace SessionPrompt {
784785
{ modelID: input.model.api.id, providerID: input.model.providerID },
785786
input.agent,
786787
)) {
787-
const schema = ProviderTransform.schema(input.model, z.toJSONSchema(item.parameters))
788+
const schema = ProviderTransform.schema(input.model, zodToJsonSchema(item.parameters) as any)
788789
tools[item.id] = tool({
789790
id: item.id as any,
790791
description: item.description,

0 commit comments

Comments
 (0)