fix: gemini tool call bug

This commit is contained in:
zhayujie
2026-03-11 02:04:09 +08:00
parent e8d4f7dc4f
commit eda82bac92
2 changed files with 11 additions and 0 deletions

View File

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

View File

@@ -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