fix(schema): handle different tool IDs at same index in concatToolCalls#962
Open
Ed1s0nZ wants to merge 1 commit intocloudwego:mainfrom
Open
fix(schema): handle different tool IDs at same index in concatToolCalls#962Ed1s0nZ wants to merge 1 commit intocloudwego:mainfrom
Ed1s0nZ wants to merge 1 commit intocloudwego:mainfrom
Conversation
Some OpenAI-compatible providers (e.g. qwen, deepseek) reuse the same streaming chunk Index for different tool calls, distinguished only by ID. The previous implementation grouped chunks solely by Index, which caused "cannot concat ToolCalls with different tool id" errors when multiple distinct IDs appeared at the same Index. This fix detects when an Index group contains multiple distinct non-empty IDs and splits them into separate sub-groups, each merged independently. Chunks with empty IDs are assigned to the most recently seen non-empty ID (following streaming order). The behavior is unchanged for providers that correctly assign unique indexes per tool call. Fixes cloudwego#927 cloudwego#431 cloudwego#361
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.
Summary
Some OpenAI-compatible providers (e.g. qwen, deepseek) reuse the same streaming chunk
Indexfor different tool calls, distinguished only byID. The currentconcatToolCallsgroups chunks solely byIndex, causing:This PR fixes
concatToolCallsto detect when anIndexgroup contains multiple distinct non-empty IDs and splits them into separate sub-groups, each merged independently. Chunks with empty IDs follow streaming order (assigned to the most recently seen non-empty ID). Behavior is unchanged for providers that correctly assign unique indexes per tool call (e.g. OpenAI).Root Cause
In
schema/message.go,concatToolCallsusesmap[int][]intkeyed byIndexonly. When provider X sends:Both land in the same group, and the ID mismatch check fails.
Fix
Indexgroup, check if multiple distinct non-empty IDs existTest
different_tool_idtest case to verify two tool calls with different IDs at the same index are correctly split into separate merged resultsTestConcatToolCallssub-tests passFixes #927 #431 #361