Skip to content

fix(openai): keep parallel streamed tool calls apart when the server omits index - #642

Merged
JackChen-me merged 3 commits into
open-multi-agent:mainfrom
pcbeingused333:fix/openai-stream-unindexed-tool-calls
Oct 29, 2026
Merged

JackChen-me merged 3 commits into
open-multi-agent:mainfrom
pcbeingused333:fix/openai-stream-unindexed-tool-calls

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Problem

OpenAIAdapter.stream() keys its tool-call buffers by toolCallDelta.index. OpenAI-compatible servers that do not send index make every streamed call share one buffer (undefined), so parallel calls collapse into one: the last id and name win and the arguments are concatenated. Gemini's OpenAI-compatible endpoint (https://generativelanguage.googleapis.com/v1beta/openai) streams parallel calls like this: in a captured gemini-3.5-flash stream, two get_weather calls arrive as two chunks, each a whole call with its own id, name and arguments, and no index. The agent then runs one tool call with merged, invalid arguments instead of two.

Fix

The slot is chosen like this: an index is used when the server sent one (unchanged for OpenAI and any indexed stream); otherwise a delta with a new id opens a new slot, a delta with a known id continues that slot, and a fragment with neither continues the latest one.

Tests

In tests/openai-adapter.test.ts: two whole, unindexed calls in separate chunks yield two tool_use blocks (fails without the change, one merged call before), and an id-then-fragment pair without index still yields one call. The existing OpenAI, Azure and fallback-repair adapter tests pass (60 tests) and npm run lint for core is clean. No request was made to a live API for this change.

This change was prepared with an AI coding assistant (Claude).

@JackChen-me
JackChen-me merged commit 7737fae into open-multi-agent:main Oct 29, 2026
7 checks passed
JackChen-me pushed a commit that referenced this pull request Nov 4, 2026
…ot adapters (#652)

`AzureOpenAIAdapter.stream()` and `CopilotAdapter.stream()` keyed every streamed tool-call delta by `toolCallDelta.index`; when a server omits `index`, all calls collapsed into one buffer and surfaced as a single `tool_use` with the last id and empty input. Move the slot-selection logic added to the OpenAI adapter in #642 into a shared `createToolCallSlotResolver()` in `openai-common.ts` and use it from all three adapters. Indexed streams are unchanged; tests cover Azure and Copilot alongside the existing OpenAI cases.
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