Skip to content

fix(openai): round-trip Gemini 3 thought_signature on tool calls - #338

Open
OtavioTavares wants to merge 1 commit into
HKUDS:mainfrom
OtavioTavares:fix/gemini3-thought-signature
Open

fix(openai): round-trip Gemini 3 thought_signature on tool calls#338
OtavioTavares wants to merge 1 commit into
HKUDS:mainfrom
OtavioTavares:fix/gemini3-thought-signature

Conversation

@OtavioTavares

@OtavioTavares OtavioTavares commented Jul 24, 2026

Copy link
Copy Markdown

Problem

With Gemini 3 models (e.g. gemini-3.1-flash-lite, gemini-3.5-flash) via the OpenAI-compatible endpoint, multi-turn tool calling fails on the follow-up request:

400 - Function call is missing a thought_signature in functionCall parts.
This is required for tools to work correctly ...

Gemini 3 is a thinking model: each tool call carries a thought_signature that MUST be echoed back on the next request. In the OpenAI-compat protocol it is surfaced as tool_calls[].extra_content ({"google": {"thought_signature": "..."}}). openai_client.py dropped this field when parsing tool calls and never resent it, so the 2nd turn 400s.

Fix

Mirror the existing reasoning_content / _reasoning round-trip pattern for extra_content:

  • Capture extra_content off each tool call (streaming and non-streaming). In streaming, Gemini sends it on a trailing index-less delta, so it is attached to the current tool call.
  • Stash it on the message as _tool_extra_content (keyed by tool-call id).
  • Replay it in _convert_assistant_message on the assistant tool_calls.

Gated on presence: providers that do not set extra_content (OpenAI, DashScope, GitHub Models, Kimi, ...) are unaffected.

Tests

  • New TestThoughtSignatureRoundTrip (capture from attr / model_extra, replay, and omission when absent).
  • Full tests/test_api/test_openai_client.py passes (46 tests).
  • Verified against the live Gemini OpenAI-compat endpoint: a 2-turn tool call 400s WITHOUT the field and succeeds WITH it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant