You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]:执行工具调用是,解析的参数发生异常(When executing the tool call, an exception occurred in the parsed parameters) #1216
Describe the [bug]
执行工具调用是,解析的参数发生异常(When executing the tool call, an exception occurred in the parsed parameters)
详细参考附件
To Reproduce
Steps to reproduce the behavior:
通过Langfuse 看到的信息,下面的一次tool_call因参数解析出问题,变成了两次tool_call,最终导致调用失败
(Based on the information obtained through Langfuse, the following issue occurred: due to a problem with parameter parsing, one tool_call was mistakenly executed twice, ultimately resulting in a failed call)
----------------------------trace info---------------------------
...
}
2: {4 Items
type: "tool_call"
id: "call_28281576ef7241a397970399"
name: "retrieveFromMemory"
arguments: "{"keywords": ["关注", "重点", "部类", "品牌", "偏好", "负责"]"
}
3: {4 Items
type: "tool_call"
id: "streaming_1776130606735"
name: "retrieveFromMemory"
arguments: "}"
}
]
finish_reason: "tool_calls"
----------------------------trace info--------------------------- Expected behavior
A clear and concise description of what you expected to happen.
Error messages
Error: Parameter validation failed for tool 'retrieveFromMemory': Schema validation error: Invalid input
Please correct the parameters and try again.
Environment (please complete the following information):
AgentScope-Java Version: [e.g. 1.0.11, check your pom.xml dependency version or run mvn dependency:tree | grep agentscope-parent:pom(only mac/linux)]
Java Version: [e.g. 17]
OS: [e.g. macos, windows]
Additional context
Add any other context about the problem here.
When using OpenAIChatModel with streaming mode, some LLM APIs (e.g., Qwen3.5-397B-A17B) intermittently return malformed tool_call chunks where the last arguments: "}" fragment incorrectly carries a non-null name field. This causes OpenAIChatFormatter to generate a streaming_ prefixed ID instead of treating it as a fragment, leading to tool parameter accumulation failure.
name: "retrieveFromMemory" ❌ Should be null or absent
arguments: "}" ✓ (expected last bracket)
Problem Analysis
Where the Issue Occurs
In OpenAIResponseParser.java (around lines 464-528), the logic for distinguishing new tool_call vs fragment is:
// Lines 464-468: Generate streaming ID when id is nullif (toolCallId == null) {
toolCallId = "streaming_" + System.currentTimeMillis(); // Generated ID
}
if (toolName == null) {
toolName = ""; // Convert null to empty string
}
// Lines 484-528: Branch logicif (!toolName.isEmpty()) {
// Has name → Treat as NEW tool_call with streaming_ ID ← WRONG PATHcontentBlocks.add(ToolUseBlock.builder()
.id(toolCallId) // "streaming_xxx"
.name(toolName) // "retrieveFromMemory"
.content(arguments) // "}"
.build());
} elseif (!arguments.isEmpty()) {
// No name → Treat as fragment with __fragment__ placeholder ← CORRECT PATHcontentBlocks.add(ToolUseBlock.builder()
.id("")
.name("__fragment__")
.content(arguments)
.build());
}
Accumulation Failure in ToolCallsAccumulator
ToolCallsAccumulator.determineKey() uses ID as primary key for merging:
privateStringdetermineKey(ToolUseBlockblock) {
// Priority 1: Use tool ID if non-emptyif (block.getId() != null && !block.getId().isEmpty()) {
returnblock.getId(); // Different IDs → Different keys → No merge!
}
// ...
}
Result: Two different keys → No merging → Chunk #4's "}" not appended → Incomplete JSON "{"keywords": [..." missing closing } → Parameter parsing failure.
Impact
Tool execution fails due to incomplete/unparseable JSON arguments
User receives error instead of expected tool result
Langfuse tracing shows two different tool_call IDs (call_xxx and streaming_xxx) for the same tool invocation
Root Cause
The issue originates from the API/model side: the streaming response incorrectly includes name field in a fragment chunk that should only contain argument content. This violates the OpenAI streaming tool_call format specification.
Reproduction
The issue can be reproduced with any OpenAI-compatible API endpoint when:
I reproduced this locally by tracing OpenAIResponseParser and ToolCallsAccumulator. The malformed final arguments: "}" chunk is being treated as a new tool call when it arrives with a non-null name, so the closing fragment never merges back into the original call. I'm working on a fix that normalizes these malformed trailing chunks into fragments and I'll add regression coverage for the parser and end-to-end accumulation path.
This normalizes the malformed named trailing fragment into a tool-call argument fragment and adds regression coverage across parser, formatter, and accumulation paths.
This normalizes the malformed named trailing fragment into a tool-call argument fragment and adds regression coverage across parser, formatter, and accumulation paths.将格式错误的命名尾部片段规范化为工具调用参数片段,并在解析器、格式化器和累积路径中增加回归测试覆盖。
The index field in the OpenAI streaming protocol is specifically designed to correlate multiple chunks of the same tool call. Wouldn't it be more appropriate to leverage this mechanism to address the issue?
Activity
junefsh commentedon Apr 14, 2026
LearningGp commentedon Apr 14, 2026
Seems like an ID mismatch is causing accumulation issues. Please share the model and formatter types.
junefsh commentedon Apr 14, 2026
AgentScope-Java Version: 1.0.11
Java Version: 21
OS: windows
model:qwen3.5-397b-a17b use stream use shortmem and longmem
CarsonLay commentedon Apr 14, 2026
Summary
When using
OpenAIChatModelwith streaming mode, some LLM APIs (e.g., Qwen3.5-397B-A17B) intermittently return malformed tool_call chunks where the lastarguments: "}"fragment incorrectly carries a non-nullnamefield. This causesOpenAIChatFormatterto generate astreaming_prefixed ID instead of treating it as a fragment, leading to tool parameter accumulation failure.Environment
OpenAIChatFormatterExpected vs Actual Behavior
Expected Streaming Tool Call Format
According to OpenAI streaming API specification, tool_call chunks should follow this pattern:
idnamearguments"call_xxx""tool_name"""nullor absentnullor absent"{"nullor absentnullor absent"\"param\": value"nullor absentnullor absent"}"Key rule: Fragments (chunks after the first) should NOT carry
namefield, ornameshould benull.Actual (Malformed) Response
Malformed chunk #4:
id:null✓ (expected for fragment)name:"retrieveFromMemory"❌ Should benullor absentarguments:"}"✓ (expected last bracket)Problem Analysis
Where the Issue Occurs
In
OpenAIResponseParser.java(around lines 464-528), the logic for distinguishing new tool_call vs fragment is:Accumulation Failure in ToolCallsAccumulator
ToolCallsAccumulator.determineKey()uses ID as primary key for merging:call_xxx, name=retrieveFromMemorycall_xxxstreaming_xxx, name=retrieveFromMemorystreaming_xxxResult: Two different keys → No merging → Chunk #4's
"}"not appended → Incomplete JSON"{"keywords": [..."missing closing}→ Parameter parsing failure.Impact
call_xxxandstreaming_xxx) for the same tool invocationRoot Cause
The issue originates from the API/model side: the streaming response incorrectly includes
namefield in a fragment chunk that should only contain argument content. This violates the OpenAI streaming tool_call format specification.Reproduction
The issue can be reproduced with any OpenAI-compatible API endpoint when:
Alexxigang commentedon Apr 14, 2026
I reproduced this locally by tracing
OpenAIResponseParserandToolCallsAccumulator. The malformed finalarguments: "}"chunk is being treated as a new tool call when it arrives with a non-nullname, so the closing fragment never merges back into the original call. I'm working on a fix that normalizes these malformed trailing chunks into fragments and I'll add regression coverage for the parser and end-to-end accumulation path.Alexxigang commentedon Apr 14, 2026
Opened PR: #1223
This normalizes the malformed named trailing fragment into a tool-call argument fragment and adds regression coverage across parser, formatter, and accumulation paths.
LearningGp commentedon Apr 28, 2026
The index field in the OpenAI streaming protocol is specifically designed to correlate multiple chunks of the same tool call. Wouldn't it be more appropriate to leverage this mechanism to address the issue?