refactor(provider): preserve extra_content verbatim for Gemini thought_signature round-trip

Replace the flatten/unflatten approach (merging extra_content.google.*
into provider_specific_fields then reconstructing) with direct pass-through:
parse extra_content as-is, store on ToolCallRequest.extra_content, serialize
back untouched.  This is lossless, requires no hardcoded field names, and
covers all three parsing branches (str, dict, SDK object) plus streaming.
This commit is contained in:
Xubin Ren authored and Xubin Ren committed 2026-03-25 10:00:29 +08:00
1 parent af84b1b8c0
commit b5302b6f3d
4 files changed
+299 -106

No files matched your search

+4 -15
View File
@@ -16,6 +16,7 @@ class ToolCallRequest:
id: str
name: str
arguments: dict[str, Any]
extra_content: dict[str, Any] | None = None
provider_specific_fields: dict[str, Any] | None = None
function_provider_specific_fields: dict[str, Any] | None = None
@@ -29,22 +30,10 @@ class ToolCallRequest:
"arguments": json.dumps(self.arguments, ensure_ascii=False),
},
}
if self.extra_content:
tool_call["extra_content"] = self.extra_content
if self.provider_specific_fields:
# Gemini OpenAI compatibility expects thought signatures in extra_content.google.
if "thought_signature" in self.provider_specific_fields:
tool_call["extra_content"] = {
"google": {
"thought_signature": self.provider_specific_fields["thought_signature"],
}
}
other_fields = {
k: v for k, v in self.provider_specific_fields.items()
if k != "thought_signature"
}
if other_fields:
tool_call["provider_specific_fields"] = other_fields
else:
tool_call["provider_specific_fields"] = self.provider_specific_fields
tool_call["provider_specific_fields"] = self.provider_specific_fields
if self.function_provider_specific_fields:
tool_call["function"]["provider_specific_fields"] = self.function_provider_specific_fields
return tool_call