fix(models): stream LiteLlm function-call args instead of buffering - #7040
Open
claxman wants to merge 2 commits into
Open
fix(models): stream LiteLlm function-call args instead of buffering#7040claxman wants to merge 2 commits into
claxman wants to merge 2 commits into
Conversation
LiteLlm appended FunctionChunk args until finish_reason. Text already streamed. Gemini already yields partial function-call events when PROGRESSIVE_SSE_STREAMING is on. Yield a partial LlmResponse after each FunctionChunk and keep the aggregated finish event. Fixes google#5342
partial_args.string_value is a per-event delta in interactions_utils and Gemini. Joining the buffer on every FunctionChunk duplicated JSON for consumers that concatenate string_value. Fixes google#5342
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
LiteLlm's
FunctionChunkbranch appends toargs_partsand only yields onfinish_reason. Onb0180620,test_streaming_tool_call_args_assembled_from_many_fragmentspassed withlen(responses) == 1, andgrep PROGRESSIVE_SSE_STREAMING src/google/adk/models/lite_llm.pywas empty. Long tool-call args do not stream.Solution:
When
PROGRESSIVE_SSE_STREAMINGis on, yield apartial=TrueLlmResponseafter eachFunctionChunk. TheFunctionCalluseswill_continue=Trueandpartial_args=[PartialArg(string_value=chunk.args)], wherestring_valueis a delta (same as interactions_utils and the Gemini path). Nojson.loadson the partial path._finalize_tool_call_responsestays the last event. Flag off keeps today's single event.Did not move LiteLlm onto
StreamingResponseAggregator. It is Gemini-shaped (json_pathon eachPartialArg) and the change would be much larger.Testing Plan
Unit Tests:
New tests in
tests/unittests/models/test_litellm.py:test_streaming_function_chunks_yield_partials_when_progressive_sse_onandtest_streaming_function_chunks_stay_buffered_when_progressive_sse_off.test_generate_content_async_stream_tool_call_includes_aggregated_textnow pins the flag on and expects two function-call partials plus the aggregated event.426 passed.
Reverted
lite_llm.pytob0180620and reran. The flag-on test failed (0 == 3partials) andtest_generate_content_async_stream_tool_call_includes_aggregated_textfailed (4 == 6events). The flag-off test still passed.pytest tests/unittests/{models,a2a,sessions,artifacts}on the fix: 2905 passed, 49 skipped, 3 xfailed.Manual End-to-End (E2E) Tests:
Not run. No live LiteLLM provider key. The flag-on unit test covers a mock stream of three FunctionChunks plus
finish_reason=tool_calls.Additional context
Claim: #5342 (comment)
Checklist