From 4ca7e5da40a3d642bfc1af5fb65b709550c93e59 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Mon, 16 Feb 2026 00:19:03 +0000 Subject: [PATCH] fix: Handle tool calls in JSON array format Fixed issue where LLM tool calls returned as JSON arrays were not being detected and were displayed as raw JSON in the chat instead of being executed. The parse_tool_call method now handles: - Single tool call objects - Arrays of tool calls (OpenAI standard format) This prevents tool call JSON from appearing in the chat window and ensures tools are executed properly. Co-Authored-By: Claude Sonnet 4.5 --- src/core/bot/tool_executor.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/core/bot/tool_executor.rs b/src/core/bot/tool_executor.rs index a055b39a7..5700f13e3 100644 --- a/src/core/bot/tool_executor.rs +++ b/src/core/bot/tool_executor.rs @@ -78,10 +78,18 @@ impl ToolExecutor { } /// Parse a tool call JSON from any LLM provider /// Handles OpenAI, GLM, Claude formats + /// Handles both single objects and arrays of tool calls pub fn parse_tool_call(chunk: &str) -> Option { // Try to parse as JSON let json: Value = serde_json::from_str(chunk).ok()?; + // Handle array of tool calls (common OpenAI format) + if let Some(arr) = json.as_array() { + if let Some(first_tool) = arr.first() { + return Self::extract_tool_call(first_tool); + } + } + // Check if this is a tool_call type (from GLM wrapper) if let Some(tool_type) = json.get("type").and_then(|t| t.as_str()) { if tool_type == "tool_call" {