From eda82bac924ddd14b32f500b4e162a814ac45127 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Wed, 11 Mar 2026 02:04:09 +0800 Subject: [PATCH] fix: gemini tool call bug --- agent/protocol/agent_stream.py | 8 ++++++++ models/openai_compatible_bot.py | 3 +++ 2 files changed, 11 insertions(+) diff --git a/agent/protocol/agent_stream.py b/agent/protocol/agent_stream.py index 119b775..df6b0db 100644 --- a/agent/protocol/agent_stream.py +++ b/agent/protocol/agent_stream.py @@ -521,6 +521,7 @@ class AgentStreamExecutor: # Streaming response full_content = "" tool_calls_buffer = {} # {index: {id, name, arguments}} + gemini_raw_parts = None # Preserve Gemini thoughtSignature for round-trip stop_reason = None # Track why the stream stopped try: @@ -612,6 +613,10 @@ class AgentStreamExecutor: if "arguments" in func: tool_calls_buffer[index]["arguments"] += func["arguments"] + # Preserve _gemini_raw_parts for Gemini thoughtSignature round-trip + if "_gemini_raw_parts" in delta: + gemini_raw_parts = delta["_gemini_raw_parts"] + except Exception as e: error_str = str(e) error_str_lower = error_str.lower() @@ -793,6 +798,9 @@ class AgentStreamExecutor: "input": tc.get("arguments", {}) }) + if gemini_raw_parts: + assistant_msg["_gemini_raw_parts"] = gemini_raw_parts + # Only append if content is not empty if assistant_msg["content"]: self.messages.append(assistant_msg) diff --git a/models/openai_compatible_bot.py b/models/openai_compatible_bot.py index 4b50feb..baac068 100644 --- a/models/openai_compatible_bot.py +++ b/models/openai_compatible_bot.py @@ -294,6 +294,9 @@ class OpenAICompatibleBot: if tool_calls: openai_msg["tool_calls"] = tool_calls + if msg.get("_gemini_raw_parts"): + openai_msg["_gemini_raw_parts"] = msg["_gemini_raw_parts"] + openai_messages.append(openai_msg) else: # Other list content, keep as is