最近在折腾 AI 应用开发的朋友可能遇到了一个棘手的问题:原本跑得好好的 DeepSeek 模型,突然在调用工具(Function Calling / Tool Use)时开始疯狂报错。

特别是当你尝试切换到最新的 DeepSeek V4 Flash 模型(deepseek-v4-flash)时,无论是直接请求还是通过像 Claude 这样的中间层转发,都会碰到类似的错误提示:

Error from provider (DeepSeek): Thinking mode does not support this tool_choice

DeepSeek Thinking mode 报错界面

Error from provider (DeepSeek): Thinking mode does not support this tool_choice

对应的 HTTP 状态码通常是 400 Bad Request。这到底是什么情况?是接口挂了还是我们的姿势不对?今天就来扒一扒这个问题的根源和解决办法。

问题复现:参数是怎么传的?

在很多支持 OpenAI 兼容协议的网关(例如 opencode.ai)上,我们通常会按照标准格式发送请求。当需要强制模型调用某个工具时,我们会设置 tool_choicerequired

一个典型的报错请求 Payload 大概长这样:

{
  "apiType": "openai-compatible",
  "baseUrl": "https://opencode.ai/zen/go",
  "modelId": "deepseek-v4-flash",
  "prompt": "Call the verify_tool tool once. Reply with a short sentence that includes the returned time.",
  "tool": {
    "name": "verify_tool",
    "description": "Return a timestamp string.",
    "inputSchema": {
      "type": "object",
      "properties": {}
    }
  },
  "toolChoice": "required"
}
``

这时候后端直接甩回来一个 400 错误,并明确告诉你:Thinking mode 不支持这种 `tool_choice`。

### 深度分析:Thinking 模式的限制

核心原因就在于 **DeepSeek V4 引入了“Thinking”机制**(类似 o1 的推理扩展模式)。

在传统的 OpenAI 协议交互中,`tool_choice` 设置为 `required` 意味着强制模型在第一次输出时就调用工具。然而,DeepSeek V4 的 Thinking 模式在处理复杂推理时,其内部流程通常是:

1.  **思考阶段:** 模型先进行内部思维的链式推导,这一阶段通常不对外输出具体的函数调用参数。
2.  **输出阶段:** 思考结束后,再生成最终答案或工具调用。

当你强制要求 `tool_choice: required` 时,API 会尝试在思考阶段就锁定一个工具调用,但这与 V4 模型当前的架构设计冲突了——它还没想完,不确定该不该调用,或者接口层还没准备好在思考流中穿插工具调用指令。这就是它会抛出 `Thinking mode does not support this tool_choice` 的根本原因。

### 解决方案:怎么绕过这个坑?

既然官方接口目前的逻辑是“思考阶段不支持强制工具调用”,那我们只能通过调整参数或切换模型来规避。这里有几个实用建议:

#### 1. 放弃 `tool_choice: required`,改用 Prompt 强制

如果你的业务逻辑允许,不要将 `tool_choice` 设为 `required`(或者 `{

标签: none

评论已关闭