fix: keep parallel tool calls from separate Gemini stream chunks in GoogleGenAIChatGenerator by pcbeingused333 · Pull Request #4141 · deepset-ai/haystack-core-integrations · GitHub
Skip to content

fix: keep parallel tool calls from separate Gemini stream chunks in GoogleGenAIChatGenerator - #4141

Open
pcbeingused333 wants to merge 1 commit into
deepset-ai:mainfrom
pcbeingused333:fix/google-genai-stream-parallel-tool-calls
Open

pcbeingused333 wants to merge 1 commit into
deepset-ai:mainfrom
pcbeingused333:fix/google-genai-stream-parallel-tool-calls

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Gemini sends each parallel function call in its own stream chunk. _convert_google_chunk_to_streaming_chunk numbered tool calls per chunk, so every call got ToolCallDelta(index=0), and _convert_streaming_chunks_to_chat_message merged them into one call with concatenated names and arguments. That call failed to parse and was dropped, so a streamed reply with parallel calls had no tool calls at all.

  • _convert_google_chunk_to_streaming_chunk takes a keyword-only tool_call_index_offset (default 0), and tool call indices start from it.
  • The sync and async stream handlers count tool calls across the stream and pass that count, next to the existing tool_calls_seen.

Calls that share a chunk are numbered as before.

How did you test it?

  • New tests in tests/test_chat_generator.py: test_run_streaming_parallel_tool_calls_in_separate_chunks and test_run_async_streaming_parallel_tool_calls_in_separate_chunks. They use hand-built chunks shaped like a Gemini 3 stream (text, call, call, empty text with STOP). Both fail on main (no tool calls) and pass with the change.
  • tests/test_chat_generator.py + tests/test_chat_generator_utils.py (-m "not integration"): 85 passed.
  • ruff check / ruff format --check clean.

Notes for the reviewer

Function call ids exist on Gemini 3 but not on older models, so the fix keys on a running index rather than on the id.

Checklist

This PR was made with Claude Code (Anthropic); the unit tests above were run on main and on this branch. No live Gemini calls were made for this change.

🤖 Generated with Claude Code

…oogleGenAIChatGenerator

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner October 21, 2026 13:08
@pcbeingused333
pcbeingused333 requested review from julian-risch and removed request for a team October 21, 2026 13:08
@github-actions

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot added the type:documentation Improvements or additions to documentation label Oct 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report (google_genai)

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  integrations/google_genai/src/haystack_integrations/components/generators/google_genai/chat
  chat_generator.py
  utils.py
Project Total  

This report was generated by python-coverage-comment-action

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration:google-genai type:documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

google_genai: streamed parallel function calls are dropped (tool call index restarts in every chunk)

1 participant