AstrBot
AstrBot copied to clipboard
[Bug] astrbot_plugin_tool_use_cleaner 对 DeepSeek 兼容性: cutoff_index计算错误等3个bug
问题描述
在使用 DeepSeek v4 flash 时,插件 astrbot_plugin_tool_use_cleaner 存在三个严重 bug,导致:
- 工具调用轮数控制完全失效(
tool_context_keep_rounds设任意值都等于 0) - 无法识别 DeepSeek 返回的
content=[{"type":"text","text":""}]空内容模式 - 删除
tool_calls后留下空消息,可能触发 400 错误
Bug 详情
Bug 1:cutoff_index 计算错误(轮数控制失效)
文件:main.py,原第 77 行
# ❌ 原代码(错误)
cutoff_index = round_ends[-self.tool_context_keep_rounds]
当 tool_context_keep_rounds=1 时,round_ends 如 [5, 7, 11],round_ends[-1] = 11,实际上清除了所有轮次,没有保留任何一轮。
修复:
# ✅ 正确:清理前 N 轮,保留最后 keep_rounds 轮
clean_count = len(round_ends) - self.tool_context_keep_rounds
cutoff_index = round_ends[clean_count - 1] if clean_count > 0 else -1
Bug 2:空 content 检查不彻底
文件:main.py,原第 36 行
# ❌ 原代码
if not ctx.get("content"):
continue
DeepSeek 返回的 content 可能是 [{"type":"text","text":""}]——列表非空(truthy),但内容实际为空。原检查无法识别这种情况。
Bug 3:删 tool_calls 后空消息兜底缺失
原代码在删除 tool_calls 后直接保留消息,但如果 content 本身是空([{"type":"text","text":""}]),删完 tool_calls 后就是一条无效消息,应跳过。
复现环境
- AstrBot 版本:latest
- LLM:DeepSeek v4 flash(API)
- 插件版本:v1.3.0
- 触发条件:任何涉及工具调用的对话
本 Issue 内容来自 zhimeng-notes
关闭此重复 issue。更完整的版本(含详细代码分析和修复方案)已提交至 #8735。
Closed as duplicate. Full analysis and fix details at #8735.