fix(schema): handle multiple complete tool calls with the same index#1057
Open
Dennisadira wants to merge 1 commit into
Open
fix(schema): handle multiple complete tool calls with the same index#1057Dennisadira wants to merge 1 commit into
Dennisadira wants to merge 1 commit into
Conversation
Some models (DeepSeek, certain Qwen variants) emit every tool call as a standalone complete chunk all with index=0, rather than streaming a single call's arguments across chunks. concatToolCalls grouped chunks by index and errored when two chunks in the same group had different IDs. A different non-empty Function.Name is a reliable signal that the new chunk is an independent call, not a conflicting continuation of the same one. When detected, finalize the accumulated call and start a fresh accumulation for the new chunk. The existing "different tool id, same name" error path is preserved: that case (same name, different id) remains ambiguous and wrong. Closes cloudwego#927 Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Fixes #927.
Some models (DeepSeek, certain Qwen variants) emit every tool call as a standalone complete chunk, all with
index=0, rather than streaming a single call's arguments across multiple chunks.concatToolCallsgroups chunks by index, so both calls land in the same bucket and the second chunk's different ID triggered:Root cause: the function assumed that within one index-group all chunks belong to the same logical tool call. That holds for streaming-argument models but not for models that emit complete calls with a shared index.
Fix: when a chunk has a non-empty ID and a non-empty
Function.Namethat differs from the accumulated name, treat it as a new independent tool call — finalize the current accumulation intomergedand start fresh. The existing same-name/different-id error path is preserved (that case is still ambiguous and wrong).Test plan
multiple_complete_calls_same_indexexercises the exact pattern from the issue (two complete calls, index=0, different ids/names → two entries in output)different_tool_idtest (same name, different id → still errors) still passesgo test ./schema/...passesAssisted-by: Claude Sonnet 4.6 noreply@anthropic.com