Skip to content

fix(ToolCallsAccumulator): fallback to 'unknown_tool' for null tool names and use stable synthetic IDs for streaming tool calls#1238

Closed
chickenlj wants to merge 1 commit into
agentscope-ai:mainfrom
chickenlj:fix-toolcall-accumulator
Closed

fix(ToolCallsAccumulator): fallback to 'unknown_tool' for null tool names and use stable synthetic IDs for streaming tool calls#1238
chickenlj wants to merge 1 commit into
agentscope-ai:mainfrom
chickenlj:fix-toolcall-accumulator

Conversation

@chickenlj

Copy link
Copy Markdown
Collaborator

Fixes #1237

…ames and use stable synthetic IDs for streaming tool calls
@chickenlj chickenlj requested review from a team and Copilot April 17, 2026 07:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a streaming-mode tool-calling bug (Issue #1237) where tool-call fragments could end up persisted with a null tool name and/or unstable identifiers, causing downstream conversion to skip ToolUseBlocks and breaking subsequent agent iterations.

Changes:

  • Generate stable synthetic tool call IDs during OpenAI-like streaming using toolIndex (e.g., streaming_idx_0) when provider IDs are missing.
  • Propagate the resolved tool call ID into fragment ToolUseBlocks (instead of emitting fragments with an empty id).
  • Add a null-name fallback in ToolCallsAccumulator (unknown_tool) and extend test coverage for the streaming edge cases.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
agentscope-core/src/main/java/io/agentscope/core/formatter/openai/OpenAIResponseParser.java Uses stable synthetic IDs (by tool index) and assigns IDs to fragment ToolUseBlocks to enable consistent merging across chunks.
agentscope-core/src/main/java/io/agentscope/core/agent/accumulator/ToolCallsAccumulator.java Ensures built ToolUseBlocks always have a non-null name by falling back to unknown_tool.
agentscope-core/src/test/java/io/agentscope/core/formatter/openai/OpenAIResponseParserTest.java Adds a test asserting stable synthetic IDs across streaming chunks by index.
agentscope-core/src/test/java/io/agentscope/core/agent/accumulator/ToolCallsAccumulatorTest.java Adds a test ensuring fragment-only streams still produce a ToolUseBlock with a non-null name.

Comment on lines +468 to +472
if (toolIndex != null) {
toolCallId = "streaming_idx_" + toolIndex;
} else {
toolCallId = "streaming_" + System.currentTimeMillis();
}

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When toolCallId is missing and toolIndex is also null, the fallback "streaming_" + System.currentTimeMillis() will generate a different synthetic ID for each chunk. That makes it impossible for downstream accumulators to reliably merge multiple chunks belonging to the same tool call (and can lead to duplicated/fragmented tool calls). Consider using a deterministic/stable fallback in this branch (e.g., reuse a per-parser last-seen synthetic ID for fragments, or derive one from choice index + position-in-toolCalls list) so repeated chunks map to the same tool call.

Copilot uses AI. Check for mistakes.
@codecov

codecov Bot commented Apr 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...pe/core/formatter/openai/OpenAIResponseParser.java 80.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@LearningGp LearningGp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LearningGp

Copy link
Copy Markdown
Member
image

@LearningGp LearningGp added the wait-for-response PRs that require further response label May 19, 2026
@github-actions

Copy link
Copy Markdown

Closing due to inactivity. Feel free to reopen when ready.

@github-actions github-actions Bot added the stale label May 27, 2026
@github-actions github-actions Bot closed this May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale wait-for-response PRs that require further response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 1.0.11 流式模式下 ToolUseBlock name 为 null

3 participants