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) {