Skip to content

fix(schema): handle multiple complete tool calls with the same index#1057

Open
Dennisadira wants to merge 1 commit into
cloudwego:mainfrom
Dennisadira:fix/concat-tool-calls-same-index
Open

fix(schema): handle multiple complete tool calls with the same index#1057
Dennisadira wants to merge 1 commit into
cloudwego:mainfrom
Dennisadira:fix/concat-tool-calls-same-index

Conversation

@Dennisadira

Copy link
Copy Markdown

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. concatToolCalls groups chunks by index, so both calls land in the same bucket and the second chunk's different ID triggered:

cannot concat ToolCalls with different tool id: 'call_a22ee75...' 'call_067d72...'

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.Name that differs from the accumulated name, treat it as a new independent tool call — finalize the current accumulation into merged and start fresh. The existing same-name/different-id error path is preserved (that case is still ambiguous and wrong).

Test plan

  • New sub-test multiple_complete_calls_same_index exercises the exact pattern from the issue (two complete calls, index=0, different ids/names → two entries in output)
  • Existing different_tool_id test (same name, different id → still errors) still passes
  • Full go test ./schema/... passes

Assisted-by: Claude Sonnet 4.6 noreply@anthropic.com

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

cannot concat ToolCalls with different tool id: 'call_357e63aa8d8643be8e6f8f0f' call_ab19881a9bc94938ab215902'

1 participant