From 0ea9804c68e7383a419fbe612af2b7c7582183aa Mon Sep 17 00:00:00 2001 From: Sureel Bhurat Date: Mon, 10 Aug 2026 12:08:45 -0400 Subject: [PATCH] fix(litellm): avoid duplicate streamed tool-call content - Omit already-streamed text from the final aggregated tool-call response. - Give the streaming tool-call test a unique name. - Assert the final response contains only the function-call part. Fixes #3697 --- src/google/adk/models/lite_llm.py | 2 +- tests/unittests/models/test_litellm.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/google/adk/models/lite_llm.py b/src/google/adk/models/lite_llm.py index 2a33ba70a63..3b0eb42e6e4 100644 --- a/src/google/adk/models/lite_llm.py +++ b/src/google/adk/models/lite_llm.py @@ -3038,7 +3038,7 @@ def _finalize_tool_call_response( llm_response = _message_to_generate_content_response( ChatCompletionAssistantMessage( role="assistant", - content="".join(text_parts), + content=None, tool_calls=tool_calls, ), model_version=model_version, diff --git a/tests/unittests/models/test_litellm.py b/tests/unittests/models/test_litellm.py index bd1729c639c..5591db845b3 100644 --- a/tests/unittests/models/test_litellm.py +++ b/tests/unittests/models/test_litellm.py @@ -4211,7 +4211,7 @@ async def test_generate_content_async_stream_grounding_metadata( @pytest.mark.asyncio -async def test_generate_content_async_stream_with_usage_metadata( +async def test_generate_content_async_stream_tool_call_omits_aggregated_text( mock_completion, lite_llm_instance ): @@ -4234,6 +4234,7 @@ async def test_generate_content_async_stream_with_usage_metadata( assert responses[2].content.parts[0].text == "two:" assert responses[2].model_version == "test_model" assert responses[3].content.role == "model" + assert len(responses[3].content.parts) == 1 assert responses[3].content.parts[-1].function_call.name == "test_function" assert responses[3].content.parts[-1].function_call.args == { "test_arg": "test_value"