Skip to content

fix(schema): handle different tool IDs at same index in concatToolCalls#962

Open
Ed1s0nZ wants to merge 1 commit intocloudwego:mainfrom
Ed1s0nZ:fix/concat-toolcalls-different-id-same-index
Open

fix(schema): handle different tool IDs at same index in concatToolCalls#962
Ed1s0nZ wants to merge 1 commit intocloudwego:mainfrom
Ed1s0nZ:fix/concat-toolcalls-different-id-same-index

Conversation

@Ed1s0nZ
Copy link
Copy Markdown

@Ed1s0nZ Ed1s0nZ commented Apr 14, 2026

Summary

Some OpenAI-compatible providers (e.g. qwen, deepseek) reuse the same streaming chunk Index for different tool calls, distinguished only by ID. The current concatToolCalls groups chunks solely by Index, causing:

[NodeRunError] cannot concat ToolCalls with different tool id: 'toolu_xxx' 'toolu_yyy'

This PR fixes concatToolCalls to detect when an Index group 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, concatToolCalls uses map[int][]int keyed by Index only. When provider X sends:

chunk 1: Index=0, ID="tool_a", Name="nmap" 
chunk 2: Index=0, ID="tool_b", Name="sqlmap"

Both land in the same group, and the ID mismatch check fails.

Fix

  • Within each Index group, check if multiple distinct non-empty IDs exist
  • If yes, split into sub-groups by ID (empty-ID chunks follow the last seen non-empty ID)
  • Reassign sequential indexes to all sub-groups
  • Existing single-ID-per-index behavior is preserved (no sub-grouping needed)

Test

  • Updated different_tool_id test case to verify two tool calls with different IDs at the same index are correctly split into separate merged results
  • All existing TestConcatToolCalls sub-tests pass

Fixes #927 #431 #361

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
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 14, 2026

CLA assistant check
All committers have signed the CLA.

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'

2 participants