[Bug] reasoning_content 为空字符串时会生成空 ThinkPart 并写入上下文
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 astrbot/core/agent/runners/tool_loop_agent_runner.py 中约第 190 行的 _complete_with_assistant_response 开始,然后检查约第 1084 行的工具调用分支,确认是否存在相同条件。使用返回空 reasoning_content 的 OpenAI 兼容提供商复现问题,并检查在没有 reasoning 签名时,这两条路径是否都会避免创建 ThinkPart。Issue 还建议清理历史记录中的空 think 块;请单独确认这部分的范围和测试。
由索引模型根据 Issue 内容生成。
描述
问题描述
Provider 返回的 reasoning_content 是空字符串时,AstrBot 仍然会生成一个 think 为空的 ThinkPart,并写进对话上下文。表现是:
data_v4.db里conversations.content的 assistant 消息几乎每条开头都多一个空思考块:
[
{"type": "think", "think": "", "encrypted": null},
{"type": "text", "text": "……正常正文……"}
]
- 个别轮次模型会把这个结构当成正文原样输出,QQ 里直接显示成
{"type": "think", "think": "", "encrypted": null},后面再跟一句模型自己写的「(来源:本对话)」。
如何复现?
- 配置一个会返回
reasoning_content=""的 OpenAI 兼容 Provider(我用的是 deepseek 系推理模型,很多轮返回空字符串)。 - 正常和机器人聊 3~5 轮。
- 查
data_v4.db的conversations.content,assistant 消息开头就是上面那个空 think 块。 - 继续聊,偶尔就能看到模型把这段 JSON 当正文吐出来。
AstrBot 版本
4.29.4(Windows 桌面版,runtime-manifest.json 里 core 也是 4.29.4)
操作系统
Windows
部署方式
桌面版(Desktop 安装包)
使用的消息平台适配器
aiocqhttp(QQ,SnowLuma 反向 WS)
错误日志
不报错,属于静默数据问题。关键代码在 astrbot/core/agent/runners/tool_loop_agent_runner.py:190(_complete_with_assistant_response):
if llm_resp.reasoning_content is not None or llm_resp.reasoning_signature:
parts.append(
ThinkPart(
think=llm_resp.reasoning_content or "",
encrypted=llm_resp.reasoning_signature,
)
)
reasoning_content 为 "" 时 "" is not None 为真,于是生成了 think="" 的 ThinkPart。
同样的写法在工具调用分支 tool_loop_agent_runner.py:1084 还有一处。
期望行为:reasoning_content 为空且没有 reasoning_signature 时不生成 ThinkPart。
建议修复(两处都改):
if llm_resp.reasoning_content or llm_resp.reasoning_signature:
另外可以考虑在读取历史时丢弃 {"type": "think", "think": ""} 的块,把已经写进库的脏数据清掉。
辅助信息
无
检查清单
- 我已经搜索了现有的 issues,没有找到重复的问题
- 我使用的是最新版本的 AstrBot
- 我已经阅读了文档和常见问题
相关
- #10215(handle empty OpenAI completions and Gemini history parts)
- #10866(Gemini 原始 provider 回放历史时空 text part 触发 400)
- 主要语言
- Python
- 星标
- 46.4k
- 派生
- 3.4k
- 平均合并
- 1 天 9 小时
- 30 天内合并 PR
- 123
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
AstrBotDevs/AstrBot 的其他 Issue
-
enhancement
难度 2/5 1-3 小时 新手友好度 75/100
AstrBotDevs/AstrBot#11038 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
AstrBotDevs/AstrBot#10999 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug] OpenAI-compatible Gemini 工具 schema const 导致 400可能已有人在做 @arccat-114 于 15 天前认领。 未关闭bug
难度 2/5 1-3 小时 新手友好度 77/100
AstrBotDevs/AstrBot#10720 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug] Discord slash command sync aborts with KeyError when a plugin handler is defined in a submodule可能已有人在做 @yuexia5 于 20 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 77/100
AstrBotDevs/AstrBot#10626 · 1 条评论 ·
维护者通常 1 天内回复
-
[Bug] QQ频道消息无法回复:markdown 回退顺序有误,误用主动消息导致 304049 限频可能已有人在做 @he-yufeng 于 31 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
AstrBotDevs/AstrBot#10420 · 4 条评论 ·
维护者通常 1 天内回复
查看 AstrBotDevs/AstrBot 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 77/100
-
needs-triage tooling
难度 1/5 1 小时以内 新手友好度 90/100
neilsh/stunt-reel#317 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 85/100
TandoorRecipes/recipes#4926 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
PyTomography/PyTomography#431 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
igormcsouza/tether#278 ·
维护者通常 1 天内回复