Skip to content
This repository was archived by the owner on Apr 16, 2026. It is now read-only.

fix: accumulate tool_calls from merged assistant messages for Gemini parallel tool calls - #1

Open
jschomay wants to merge 2 commits into
mainfrom
fix/gemini-parallel-tool-calls-responses-api
Open

fix: accumulate tool_calls from merged assistant messages for Gemini parallel tool calls#1
jschomay wants to merge 2 commits into
mainfrom
fix/gemini-parallel-tool-calls-responses-api

Conversation

@jschomay

@jschomay jschomay commented Mar 2, 2026

Copy link
Copy Markdown

Summary

Fixes BerriAI#22578

  • Fixes parallel tool calls failing with "Missing corresponding tool call for tool response message" when using the Responses API (/v1/responses) with Gemini 3 models
  • Root cause: when the Responses API creates separate assistant messages for each parallel tool call, the Gemini transformation merges consecutive assistant messages but last_message_with_tool_calls only kept the last assistant message's tool_calls — so earlier tool results couldn't find their matching tool call
  • Fix: accumulate tool_calls from all consecutive assistant messages into last_message_with_tool_calls

Reproduction

Two parallel tool calls via Responses API streaming with Gemini 3 Pro. The Responses API transformation creates one assistant message per function_call input item. The Gemini format converter then fails matching the first tool result because last_message_with_tool_calls only contains the second tool call.

Test plan

  • Added test_convert_gemini_tool_call_result_parallel_tool_calls that reproduces the exact bug scenario
  • Test fails without fix (raises "Missing corresponding tool call" with call_aaa vs call_bbb)
  • Test passes with fix
  • Existing tests still pass

🤖 Generated with Claude Code

jschomay and others added 2 commits March 2, 2026 11:42
…parallel tool calls

When the Responses API creates separate assistant messages for parallel
tool calls, the Gemini transformation merges consecutive assistant
messages but only kept the last message's tool_calls in
last_message_with_tool_calls. This caused convert_to_gemini_tool_call_result
to fail matching tool results from earlier assistant messages.

Now accumulates tool_calls from ALL consecutive assistant messages so
that all parallel tool results can find their corresponding tool call.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Andrerm124

Copy link
Copy Markdown

Is there any update on this?
It makes litellm pretty much unusable for me 😬

@jschomay

Copy link
Copy Markdown
Author

@Andrerm124 Hi. I'm not sure what the status is, I haven't heard anything on my PR (BerriAI#22599) and I can't tell what needs to happen to get it merged. You can use this fork for now, but ideally they'll accept it. If you have any suggestions I'd appreciate them!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parallel tool calls fail with Gemini 3 via Responses API: "Missing corresponding tool call for tool response message"

2 participants