Skip to content

fix(py/openai): keep streamed tool calls apart when the endpoint omits index - #145

Merged
huangjeff5 merged 2 commits into
genkit-ai:mainfrom
pcbeingused33:fix/openai-stream-tool-calls-no-index
Nov 30, 2026
Merged

huangjeff5 merged 2 commits into
genkit-ai:mainfrom
pcbeingused33:fix/openai-stream-tool-calls-no-index

Conversation

@pcbeingused33

@pcbeingused33 pcbeingused33 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

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.

…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.
@pcbeingused33

Copy link
Copy Markdown
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.

@huangjeff5 huangjeff5 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@huangjeff5
huangjeff5 enabled auto-merge (squash) November 30, 2026 19:51
@huangjeff5
huangjeff5 merged commit 69a19c1 into genkit-ai:main Nov 30, 2026
20 checks passed
@huangjeff5 huangjeff5 mentioned this pull request Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants