From 2ded7fe0407d1fce95ac9c4a320ae9a6e7853d3d Mon Sep 17 00:00:00 2001 From: Charlie Freeman <243496084+cf3901646@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:35:37 +0800 Subject: [PATCH 1/2] fix(gemini): preserve parallel tool calls with identical names and arguments (#48831) --- .../llms/vertex_ai/gemini/transformation.py | 5 ++-- .../test_vertex_ai_gemini_transformation.py | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.py index bbd4a96980a..53db17bd409 100644 --- a/litellm/llms/vertex_ai/gemini/transformation.py +++ b/litellm/llms/vertex_ai/gemini/transformation.py @@ -936,10 +936,11 @@ def gemini_convert_messages_with_history( model=model, forward_function_call_id=forward_function_call_id, ) - ## check if gemini_tool_call already exists in assistant_content + ## check if gemini_tool_call already exists in assistant_content before this batch + pre_existing_parts = list(assistant_content) for gemini_tool_call_part in gemini_tool_call_parts: if not check_if_part_exists_in_parts( - assistant_content, + pre_existing_parts, gemini_tool_call_part, excluded_keys=["thoughtSignature"], ): diff --git a/tests/unit/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py b/tests/unit/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py index c0ff931a41d..b994c36689d 100644 --- a/tests/unit/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py +++ b/tests/unit/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py @@ -3016,3 +3016,28 @@ def test_anthropic_messages_history_replays_to_gemini_without_claude_signature() assert signatures == [_get_dummy_thought_signature()] assert [part for part in parts if part.get("text") == thinking] == [{"thought": True, "text": thinking}] assert next(part for part in parts if "function_call" in part)["thoughtSignature"] == _get_dummy_thought_signature() + +def test_parallel_tool_calls_with_identical_name_and_arguments() -> None: + """Parallel tool calls with identical name and arguments must both be preserved. + + Regression test for https://github.com/BerriAI/litellm/issues/48831 + """ + messages: Final = [ + {"role": "user", "content": "What time is it? Ask twice."}, + { + "role": "assistant", + "content": None, + "tool_calls": [ + {"id": "call_1", "type": "function", "function": {"name": "get_time", "arguments": "{}"}}, + {"id": "call_2", "type": "function", "function": {"name": "get_time", "arguments": "{}"}}, + ], + }, + {"role": "tool", "tool_call_id": "call_1", "content": "12:00"}, + {"role": "tool", "tool_call_id": "call_2", "content": "12:01"}, + ] + + contents = gemini_convert_messages_with_history(messages=messages, model="gemini-2.5-flash") + model_parts = next(c["parts"] for c in contents if c.get("role") == "model") + function_calls = [p for p in model_parts if "function_call" in p or "functionCall" in p] + assert len(function_calls) == 2 + From 3fde52bef52b01fa0809e9af86120ad966ba1fc9 Mon Sep 17 00:00:00 2001 From: Charlie Freeman <243496084+cf3901646@users.noreply.github.com> Date: Wed, 28 Oct 2026 21:41:32 +0800 Subject: [PATCH 2/2] style(gemini): use list.extend to satisfy strict ruff rules --- litellm/llms/vertex_ai/gemini/transformation.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.py index 53db17bd409..bc918381344 100644 --- a/litellm/llms/vertex_ai/gemini/transformation.py +++ b/litellm/llms/vertex_ai/gemini/transformation.py @@ -938,13 +938,15 @@ def gemini_convert_messages_with_history( ) ## check if gemini_tool_call already exists in assistant_content before this batch pre_existing_parts = list(assistant_content) - for gemini_tool_call_part in gemini_tool_call_parts: + assistant_content.extend( + gemini_tool_call_part + for gemini_tool_call_part in gemini_tool_call_parts if not check_if_part_exists_in_parts( pre_existing_parts, gemini_tool_call_part, excluded_keys=["thoughtSignature"], - ): - assistant_content.append(gemini_tool_call_part) + ) + ) # Only record this as the active tool-call message when it actually # carries tool calls. The `if` guard above is also entered for a # text-only assistant message (`assistant_msg.get("tool_calls", [])