Skip to content

[Bug] Thinking Mode: reasoning_content must be passed back to API #570

@Clawiee

Description

@Clawiee

Bug 描述

使用 Agent 时遇到 HTTP 400 错误:

HTTP 400: {"error":{"message":"The `reasoning_content` in the thinking mode must be passed back to the API.","type":"invalid_request_error","param":null,"code":"invalid_request_error"}}

问题分析

这个错误发生在以下场景:

  1. Agent 配置开启了 thinking mode(思考模式)
  2. LLM 返回了包含 reasoning_content(思考内容)的响应
  3. 系统在构建下一轮 API 请求时,没有正确将 reasoning_content 传回给 API

技术原因推测

使用 thinking mode 时,API 要求在后续请求中必须包含之前返回的 reasoning_content。可能的错误代码位置:

场景 1:消息历史构建时丢失 reasoning_content

# 错误:只保留了 text,丢失了 reasoning
message = {
    "role": "assistant",
    "content": [{"type": "text", "text": "..."}]  # 缺少 reasoning_content
}

场景 2:消息转换时过滤掉了 reasoning block

# 错误:过滤掉了 thinking 类型的 content block
content = [b for b in response.content if b.type != "thinking"]

场景 3:工具调用时遗漏 reasoning_content

# 错误:消息中包含 reasoning_content,但 API 请求中没有传递
{
    "role": "user",
    "content": [{"type": "reasoning", "reasoning_content": "..."}]  # 这类块需要传回
}

建议的修复方向

  1. 保留完整的 content blocks:在存储和处理消息时,保留所有类型的 content blocks,包括 reasoning_content
  2. API 请求时包含 thinking:在调用 LLM API 时,确保将之前的 reasoning_content 正确传递
  3. 检查消息转换逻辑:审查 conversation_to_messages 或类似的转换函数,确保不过滤掉 thinking 相关的 blocks

影响范围

  • 使用 thinking mode 的 Agent
  • 所有 LLM 调用都可能受影响

环境信息

  • 版本:v1.9.3
  • 相关配置:thinking mode / 思考模式

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions