agentscope-ai / agentscope-ai/agentscope-java

Bug Report: stream=true 模式下 tool call 参数 JSON 不完整导致工具调用失败

Aberta
#1,309 0 comentários 1 reação 2 responsáveis Reivindicada por @chickenlj Ver no GitHub
area/core/model bug
Linguagem predominante
Java
Estrelas
5.6k
Forks
1.3k
Merge médio
4d 12h
PRs com merge (30d)
77

Descrição

# **Bug Report: stream=true 模式下 tool call 参数 JSON 不完整导致工具调用失败**
## 摘要
在 `stream=true` 模式下,MCP 工具调用的 arguments 会出现 JSON 格式错误(`unexpected end-of-input in property name`),导致框架将工具调用失败视为模型输出并以自然语言返回错误说明,而非正确执行工具。`stream=false` 模式下完全正常。

该问题由 commit `6ec423255e3f4ca103275e49d552f7bf3f1ab1f1` 引入。

---

## 环境
| **项** | **值** |
| --- | --- |
| 版本基线 | 1.0.11(tag release/1.0.11,commit cd2b599e) |
| 回归引入 commit | 6ec423255e3f4ca103275e49d552f7bf3f1ab1f1 |
| 回归版本 | 1.0.11-yqg(= release/1.0.11 + 6ec4232) |
| 测试入口 | POST [http://localhost:9000/openai/v1/chat/completions](http://localhost:9000/openai/v1/chat/completions) |
| 受影响配置 | stream=true |

---

## 复现步骤
### 测试 1 — baseline `1.0.11-snapshot`,`stream=false/true` ✅
```plain
# 基于 commit cd2b599e(origin/release/1.0.11)打包 1.0.11-snapshot
curl -X POST "http://localhost:9000/openai/v1/chat/completions" \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "read https://fintopia.feishu.cn/wiki/GZCdwxZJGil04WkVA6wc6L1ln9g"}]
}'
```

结果: 工具调用成功,返回 wiki 内容。✅

---

### 测试 2 — `1.0.11-yqg`,`stream=false` ✅
```plain
# 基于 cd2b599e + 6ec4232 打包 1.0.11-yqg
curl -X POST "http://localhost:9000/openai/v1/chat/completions" \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "read https://fintopia.feishu.cn/wiki/GZCdwxZJGil04WkVA6wc6L1ln9g"}]
}'
```

结果: 工具调用成功,返回 wiki 内容。✅

---

### 测试 3 — `1.0.11-yqg`,`stream=true` ❌
```plain
curl -X POST "http://localhost:9000/openai/v1/chat/completions" \
-H "Content-Type: application/json" \
-d '{
"messages": [{"role": "user", "content": "read https://fintopia.feishu.cn/wiki/GZCdwxZJGil04WkVA6wc6L1ln9g"}]
}'
```

实际输出(错误):

```plain
{
"choices": [{
"message": {
"role": "assistant",
"content": "It seems there is a recurring issue with the parameter formatting when attempting to use the `get_feishu_docx_markdown` tool. The error message indicates a problem with the JSON structure, specifically an \"unexpected end-of-input in property name,\" which typically suggests that the JSON is malformed or incomplete.\n\nTo resolve this, ensure that the parameters passed to the tool are correctly formatted as valid JSON..."
},
"finish_reason": "length"
}]
}
```

期望输出: 工具调用成功,返回 wiki 内容(同测试 1/2)。

关键特征:

+ `finish_reason: "length"`(非 `"stop"`),说明模型在重试中耗尽 token
+ LLM 收到了 tool execution error,将其当成自然语言上下文,陷入无效重试循环
+ 根本原因是传给工具的 arguments JSON 不完整(`unexpected end-of-input in property name`)

---

## 影响范围
+ 仅影响 `stream=true` + MCP 工具调用 的场景
+ `stream=false` 不受影响(无 fragment accumulation 路径)
+ 所有依赖 streaming tool call 的 MCP 工具均可能受影响

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.