Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
The streaming path rebuilt each tool call from its id, name and arguments only, so the thought_signature Gemini 3 attaches to a call (in extra_content on the Vertex AI OpenAI-compatible endpoint) never reached the function-call part. The next request then failed with "Function call is missing a thought_signature in functionCall parts". The non-streaming path kept it. Carry the signature on FunctionChunk, keep it per tool-call index while the stream is assembled, and set it on the assembled tool call, so the existing extraction restores it onto the part as it does for non-streamed responses. Fixes google#7438
vetler
force-pushed
the
fix/litellm-streamed-thought-signature
branch
from
October 7, 2026 17:01
678a42e to
42a5da3
Compare
Resolve the conflict in the streamed tool-call finalizer: keep attaching the thought signature to the assembled tool call, and use main's repaired-JSON arguments for it.
…'s name A tool-call delta carrying only a signature was dropped as empty, so a provider that sends the signature apart from the name and arguments would still lose it. Keep such deltas, attach the signature to the call at the delta's own index, or hold it for the call that starts there next, and never open a call for it, which would reach the model without a name. Neither Vertex AI's OpenAI-compatible endpoint nor LiteLLM's vertex_ai provider sends this shape today; both put the signature on the delta that names the call.
Collaborator
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
With
LiteLlmandstream=True, thethought_signatureGemini 3 attaches to a tool call is dropped while the streamed call is reassembled.FunctionChunkonly carriedid,name,argsandindex, and the assembledChatCompletionMessageToolCallwas built from those, so_extract_thought_signature_from_tool_callfound nothing. The stored function-call part had no signature and Gemini 3 rejected the next request:The non-streaming path keeps the signature (#3627, #4650).
Solution:
FunctionChunkgets an optionalthought_signature. Gemini signs only the first call of a parallel batch, so most chunks carry none._model_response_to_chunkfills it with the existing_extract_thought_signature_from_tool_call, so all the places a signature can arrive are covered (extra_content.google,provider_specific_fields, an id with an embedded signature)._finalize_tool_call_responsesets it asextra_content.google.thought_signatureon the assembled tool call._message_to_generate_content_responsethen restores it onto the part exactly as for a non-streamed response, so no second code path converts signatures.A delta that carries only a signature (no name, no arguments) used to be dropped as empty. It is now kept: the signature goes to the call at the delta's own index (not the fallback index, which may already point past that call), or is held for the call that starts at that index next. Such a delta never opens a call of its own, which would reach the model without a name. Neither Vertex AI's OpenAI-compatible endpoint nor LiteLLM's
vertex_aiprovider sends this shape today (see the raw deltas below); both put the signature on the delta that names the call.Testing Plan
Unit Tests:
New tests in
tests/unittests/models/test_litellm.py:test_model_response_to_chunk_keeps_thought_signature: the signature on a streamed delta reaches theFunctionChunk.test_streaming_tool_call_keeps_thought_signature: the signature on the first of two argument fragments survives assembly, and_content_to_message_paramsends it back on the follow-up request.test_streaming_parallel_tool_calls_keep_signature_per_call: with two parallel calls where only the first is signed, the first part keeps its signature and the second staysNone.test_model_response_to_chunk_keeps_a_signature_only_delta: a delta with only a signature is no longer dropped as empty.test_streaming_signature_after_its_call_signs_that_call: a signature-only delta that arrives after its call, with a second call in between, signs the first call and not the second.test_streaming_signature_before_its_call_signs_that_call: a signature-only delta ahead of its call opens no call of its own and signs the call that follows.All six fail on
mainand pass with the fix.None of the failures involve this change:
TestParseToolCallArgumentslogging tests added in a01b226, andmain's own CI fails on the same four. They pass on their own and fail aftertests/unittests/a2a/utils/test_agent_to_a2a.py, onmainas well:to_a2a()sets thegoogle_adklogger to INFO, andcaplog.at_level(logging.DEBUG)only lowers the root logger, so the payload the tests look for is never logged.test_bigquery_agent_analytics_plugin.py::TestExactlyOnceDelivery::test_finalization_respects_remaining_close_budget[shutdown], which missed its 50 ms shutdown budget while four suites ran at once; it passed when rerun on its own.kuberneteswas pinned to 36.0.3: 37.0.0 breaks fivetest_gke_code_executor.pytests onmain(GKE code executor unit tests fail with kubernetes 37.0.0, turning main CI red #7443, fix in test: fix GKE executor tests broken by kubernetes 37.0.0 #7444). The environments used uv's managed Python, because Homebrew's ships asitecustomizemodule thattest_import_loading.pyflags.pre-commit run --fileson both changed files passes, and mypy reports no new errors inlite_llm.py.Manual End-to-End (E2E) Tests:
The reproduction script from LiteLlm streaming drops Gemini thought_signature from tool calls; Gemini 3 then rejects the follow-up request #7438 (LiteLLM client mocked with the shape the Vertex AI OpenAI-compatible endpoint returns):
Live, against
gemini-3-flash-previewwith parallel calls: aRunnerwithRunConfig(streaming_mode=StreamingMode.SSE)and anLlmAgentwith two tools, asked for the weather and the local time in two cities, so the model makes four parallel calls in one step. A wrapping client prints a summary of every raw tool-call delta. Run on both routes LiteLLM offers to Gemini on Vertex AI, authenticated with Application Default Credentials.Script (
VERTEX_PROJECT=<project> ROUTE=openai|vertex_ai LOG_DELTAS=1 python e2e_parallel.py)OpenAI-compatible endpoint (
custom_llm_provider="openai"). The signature arrives inextra_content.googleon the first call's delta, together with its name and arguments; the other three calls are unsigned. Onmainthe stored calls have no signature and Vertex rejects the follow-up request:With this change:
LiteLLM
vertex_aiprovider. The signature arrives inprovider_specific_fieldsand embedded in the call id, whichmainalready handles; this change keeps it working:Checklist
Additional context
Gemini 3 checks signatures only for function calls in the current turn, so the bug can go unnoticed: if a user-role message follows the function response (for example the
instructionADK adds as user content whenstatic_instructionis set), the request succeeds without the signature.🤖 Generated with Claude Code