From 82f6f6952202924952af6b9c84df42e5fd204bc3 Mon Sep 17 00:00:00 2001 From: silencezhoudev Date: Wed, 21 Jan 2026 18:16:12 +0800 Subject: [PATCH] fix: support object-type arguments in tool call parsing Add type check in safeParseToolCallArgs to handle cases where toolCall.function.arguments is already an object instead of a JSON string. This prevents parameter loss and 'argument is required' errors in tool calls. --- core/tools/parseArgs.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/tools/parseArgs.ts b/core/tools/parseArgs.ts index f919ddc92..79f504d56 100644 --- a/core/tools/parseArgs.ts +++ b/core/tools/parseArgs.ts @@ -3,6 +3,17 @@ import { ToolCallDelta } from ".."; export function safeParseToolCallArgs( toolCall: ToolCallDelta, ): Record { + const args = toolCall.function?.arguments; + + if ( + args && + typeof args === "object" && + !Array.isArray(args) && + Object.keys(args).length > 0 + ) { + return args; + } + try { return JSON.parse(toolCall.function?.arguments?.trim() || "{}"); } catch (e) {