You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(llm): preserve OpenAI-compatible tool call extra content
Problem
Some OpenAI-compatible providers attach protocol metadata to an individual
tool call under tool_calls[].extra_content. Gemini 3 uses extra_content.google.thought_signature and requires that signature to be
returned unchanged when the conversation continues after a function call.
The OpenAI SDK retains this field, but OpenAIModelClient converted each SDK
tool call into agent-core's ToolCall using only id, type, name, arguments, and index. The metadata was therefore discarded before BaseModelClient rebuilt the assistant message for the next request. A Gemini
3 function-calling loop then failed on the continuation request with a 400
error for the missing thought signature.
Root cause and fix
This change treats extra_content as optional, opaque protocol metadata rather
than adding Gemini-specific detection or manufacturing a signature:
add optional extra_content to the internal ToolCall schema;
extract it from OpenAI SDK objects, including Pydantic model_extra;
preserve it through nested message conversion and streaming chunk merges;
serialize it back into conversation history only when present.
Standard OpenAI tool calls remain unchanged because no extra_content key is
emitted when the field is absent.
Reproduction
On an unmodified clean checkout of upstream/develop, the new round-trip
regression test fails because extra_content is absent after:
parsing an OpenAI-compatible tool call;
storing it as an agent-core AssistantMessage;
serializing that message for the next model request.
With this change, the metadata survives the complete round trip.
Added coverage for non-streaming responses, OpenAI SDK model objects,
streaming chunk merges, parallel tool calls, nested message conversion, and
standard tool calls without extension metadata.
Real two-request tool loop against gemini-3.1-flash-lite through Google's
OpenAI-compatible endpoint: first request returned a tool call and signature;
the parsed and serialized metadata matched; the continuation request with the
tool result completed successfully.
ruff check, codespell, and git diff --check pass for the change; the new
test also passes isolated mypy checking.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Paired: GitHub #78 ↔ GitCode !2018
fix(llm): preserve OpenAI-compatible tool call extra content
Problem
Some OpenAI-compatible providers attach protocol metadata to an individual
tool call under
tool_calls[].extra_content. Gemini 3 usesextra_content.google.thought_signatureand requires that signature to bereturned unchanged when the conversation continues after a function call.
The OpenAI SDK retains this field, but
OpenAIModelClientconverted each SDKtool call into agent-core's
ToolCallusing onlyid,type,name,arguments, andindex. The metadata was therefore discarded beforeBaseModelClientrebuilt the assistant message for the next request. A Gemini3 function-calling loop then failed on the continuation request with a 400
error for the missing thought signature.
Root cause and fix
This change treats
extra_contentas optional, opaque protocol metadata ratherthan adding Gemini-specific detection or manufacturing a signature:
extra_contentto the internalToolCallschema;model_extra;Standard OpenAI tool calls remain unchanged because no
extra_contentkey isemitted when the field is absent.
Reproduction
On an unmodified clean checkout of
upstream/develop, the new round-tripregression test fails because
extra_contentis absent after:AssistantMessage;With this change, the metadata survives the complete round trip.
Validation
pytest tests/unit_tests/core/foundation/llm -q: 301 passed, 3 skippedstreaming chunk merges, parallel tool calls, nested message conversion, and
standard tool calls without extension metadata.
gemini-3.1-flash-litethrough Google'sOpenAI-compatible endpoint: first request returned a tool call and signature;
the parsed and serialized metadata matched; the continuation request with the
tool result completed successfully.
ruff check,codespell, andgit diff --checkpass for the change; the newtest also passes isolated
mypychecking.Reference: https://ai.google.dev/gemini-api/docs/generate-content/thought-signatures