Skip to content

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

Open

Description

@123qwq943

问题描述

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
  • 我已经阅读了文档和常见问题

相关

Activity

  1. Solaris-star commented on Nov 8, 2026

    @Solaris-star

    I am taking a focused fix for the two runner paths that create an empty ThinkPart when reasoning_content is an empty string and there is no reasoning signature. I will cover both final responses and tool-call responses, while preserving non-empty reasoning and signature-only parts. Historical context cleanup stays outside this patch; the related #10215 and #10224 changes address separate behavior.

  2. moved this from Todo to In Progress in AstrBot Roadmapon Nov 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions