[Bug] reasoning_content 为空字符串时会生成空 ThinkPart 并写入上下文

未关闭 适合新手
#11,034 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
ai, backend

调研方向

从 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,并写进对话上下文。表现是:

  1. data_v4.db 里 conversations.content 的 assistant 消息几乎每条开头都多一个空思考块:
[
  {"type": "think", "think": "", "encrypted": null},
  {"type": "text", "text": "……正常正文……"}
]
  1. 个别轮次模型会把这个结构当成正文原样输出,QQ 里直接显示成
    {"type": "think", "think": "", "encrypted": null},后面再跟一句模型自己写的「(来源:本对话)」。
如何复现?
  1. 配置一个会返回 reasoning_content="" 的 OpenAI 兼容 Provider(我用的是 deepseek 系推理模型,很多轮返回空字符串)。
  2. 正常和机器人聊 3~5 轮。
  3. 查 data_v4.db 的 conversations.content,assistant 消息开头就是上面那个空 think 块。
  4. 继续聊,偶尔就能看到模型把这段 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

AstrBotDevs/AstrBot 的其他 Issue

查看 AstrBotDevs/AstrBot 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。