fix: 修复 thinking 模式 reasoning_content 未回传#1696
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (3)
Walkthrough本 PR 在消息模型、序列化、Maisaka 上下文、OpenAI 客户端、对话循环与 WebUI 路由处新增或传播 reasoning_content 字段,并补充对应单元测试以验证该字段在消息构建、序列化、toolless 清理与历史过滤中的保留与映射行为。 变更详情推理内容端到端支持链路
Sequence DiagramsequenceDiagram
participant LLM
participant chat_loop_step
participant OpenaiClient
participant AssistantMessage
participant chat_history
participant ChatResponse
LLM->>chat_loop_step: 返回 response + reasoning_content
chat_loop_step->>AssistantMessage: 构造并 set reasoning_content
chat_loop_step->>OpenaiClient: 调用 _convert_messages(reasoning_key)
AssistantMessage->>chat_history: 写入历史(含 reasoning_content)
chat_loop_step->>ChatResponse: 返回 reasoning_content
预估代码审查工作量🎯 3 (Moderate) | ⏱️ ~20 分钟 已更新总体变更说明(供合并请求描述使用)本 PR 在系统各层添加了模型推理内容( 可能相关的问题
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 14ff8f4e5f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| tool_call_id=message.tool_call_id, | ||
| tool_name=message.tool_name, | ||
| tool_calls=None, | ||
| reasoning_content=message.reasoning_content, |
There was a problem hiding this comment.
Preserve reasoning when sanitizing tool-call-only assistant turns
在无工具请求清洗链路里,reasoning_content 只会在重建 assistant 消息时被拷贝,但这段逻辑仍受前面的 if not message.parts: continue 约束。对于“仅有 tool_calls、正文为空”的 assistant 历史(这是模型函数调用常见返回形态),该消息会被直接丢弃,导致上一轮推理内容无法回传到下一轮请求,thinking 模式下仍可能触发要求回传 reasoning 的 400 错误。
Useful? React with 👍 / 👎.
|
补充说明一下当前 PR 的状态,方便维护者判断后续处理方式:
如果维护上希望继续推进到绿灯,我可以继续补修这些全局 lint 问题;但从 issue 边界和最小 bugfix 原则看,它们已经明显超出本 PR 原始修复范围,所以想先同步给维护者确认一下处理策略。 |

摘要
reasoning_content。reasoning_content传递。背景
部分 OpenAI 兼容服务商在 thinking mode 下要求多轮请求必须把上一轮 assistant 返回的
reasoning_content原样传回 API。目前 MaiBot 已经能从模型响应中读取
reasoning_content,但该字段没有被保存到 assistant 历史消息中,也不会在下一轮请求中回传。因此在使用 mimoAPI、DeepSeek 兼容 thinking mode 等接口时,可能触发 400 错误:Refs #1608
修改内容
Message和 MaisakaAssistantMessage增加reasoning_content字段。generation_result.reasoning写入 assistant 历史消息。_convert_messages()在 assistant 历史存在 reasoning 时按 provider 字段名写入 OpenAI-compatible payload。reasoning_content。response.reasoning_content,避免把正式输出误当成推理内容。临时规避方案
在该修复合入前,受影响用户可以对相关模型配置额外参数:
{ enable_thinking: false }这样可以临时关闭 thinking mode,绕过上游对
reasoning_content回传的强制要求。测试
已运行:
结果:
已运行:
结果:
已运行:
结果:
已知情况
uv run pytest pytests/test_maisaka_timing_gate.py全量运行时仍有 3 个既有测试失败,原因是当前代码中的 timing 工具名已经是no_action,但部分旧测试仍断言no_reply。该失败与本次reasoning_content修复无关。影响范围
该修改只在 assistant 历史消息存在
reasoning_content时额外回传字段。普通非 thinking 模式、没有 reasoning 的模型请求不会额外增加该字段。Summary by CodeRabbit
New Features
Tests