Repository navigation
fix(py/openai): keep streamed tool calls apart when the endpoint omits index - #145
Merged
huangjeff5 merged 2 commits intoNov 30, 2026
Conversation
…s index OpenAI-compatible endpoints such as Gemini omit tool_call.index in streamed fragments, so every call accumulated into slot None and parallel calls were merged into invalid JSON. Choose the slot from the fragment id/name when index is absent.
Contributor
Author
|
I added coverage for interleaved tool calls whose fragments carry IDs but omit the index. A later fragment for A now joins A even if a fragment for B arrived in between. The full OpenAI plugin suite passed with 500 tests. This comment was drafted with Claude Code. |
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.
Moved from genkit-ai/genkit#6954 at the maintainers' request after the Python SDK moved to this repository.
Some OpenAI-compatible endpoints omit the tool-call index in streaming responses. Grouping those fragments by index alone puts every call in the same slot. Comparing IDs only against the latest slot also breaks an A/B/A sequence by splitting A's arguments into two slots.
Use the supplied index when present. Otherwise, match a known ID to its existing slot and allocate a new slot for a new ID. Fragments without an ID still use the function-name and latest-slot heuristics.
The regression test covers both consecutive and interleaved fragments with the same ID and checks the resulting tool request references, names, and decoded arguments. The full OpenAI plugin suite covers indexed streams and wrapped tool inputs.
AI assistance was used to prepare this change.