工具调用是一个由客户端驱动的两段流程:模型先返回 tool_calls,客户端执行函数并回传 role="tool" 结果,模型再生成最终回答。启用 strict beta 时,必须使用 beta 端点、为每个函数设置 strict: true,并提交符合服务端支持范围的 JSON Schema;Chat Completion 不支持把模型未生成的工具调用插入历史中间。
适合的任务:需要模型调用天气、数据库、搜索或业务函数,并要求函数参数严格符合 Schema 的 Agent 工作流。
不适合的任务:需要在 Chat Completion 历史中途动态插入工具调用及结果的场景;此时应改用 Anthropic API 或 Responses API。
适用的模型版本:deepseek-flash,对应 DeepSeek-V4.1-Flash。
适用的客户端、Agent 或 API:OpenAI 兼容的 Chat Completion API;严格模式同时支持 thinking 和 non-thinking mode。
推荐的推理档位和参数:未注明;本文只规定工具调用和 Schema 配置。
下面是可放入请求 tools 数组的一个工具定义,不是完整 API 请求或可直接运行的 Python 脚本:
{
"type": "function",
"function": {
"name": "get_weather",
"strict": true,
"description": "Get weather of a location.",
"parameters": {
"type": "object",
"properties": {
"location": { "type": "string" }
},
"required": ["location"],
"additionalProperties": false
}
}
}使用 strict 模式还需要把客户端端点设为:
https://api.deepseek.com/beta请求中的每个 function 都必须设置 strict: true。服务端会校验函数 Schema;Schema 不符合要求或包含不支持的类型时,请求返回错误。
支持的类型或组合包括:object、string、number、integer、boolean、array、enum、anyOf;页面还说明可用 $def 定义复用模块、用 $ref 引用模块或表达递归结构。
对象必须同时满足:
{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" }
},
"required": ["name", "age"],
"additionalProperties": false
}也就是每个 property 都列入 required,并将 additionalProperties 设为 false。字符串支持 pattern 和 format;当前支持的 format 为 email、hostname、ipv4、ipv6、uuid,不支持 minLength、maxLength。数字和整数支持 const、default、minimum、maximum、exclusiveMinimum、exclusiveMaximum、multipleOf;数组不支持 minItems、maxItems。
在 tools 中定义函数及参数 Schema;严格模式下将每个函数的 strict 设为 true,并使用 https://api.deepseek.com/beta。
将用户消息和 tools 发给 deepseek-flash,读取返回 assistant 消息中的 tool_calls。
客户端根据 tool_calls 中的函数名和参数执行真实函数。模型只提出调用,不会替客户端执行具体函数。
将完整 assistant 消息追加到历史,再追加对应的工具结果:
{ "role": "tool", "tool_call_id": "<对应调用 ID>", "content": "<客户端函数结果>" }再次发送消息历史,直到 assistant 不再返回 tool_calls,然后读取自然语言回答。
工具调用中途插入的协议边界如下:
sequenceDiagram
participant U as 用户
participant M as 模型
participant C as 客户端
participant T as 外部工具
U->>M: messages + tools
M-->>C: assistant.tool_calls
C->>T: 执行函数
T-->>C: 结果
C->>M: 完整 assistant + role=tool
M-->>C: 最终回答Anthropic API(/messages)和 Responses API 支持把客户端动态插入的工具调用及结果放入对话中间,也支持中间插入 system message。
Chat Completion 支持中间插入 system message,但不支持中间插入工具调用;需要该能力时改用前述两种 API。
官方页面的 Non-thinking Mode 小节给出 get_weather 示例:模型返回 get_weather({location: 'Hangzhou'}),客户端提供结果后,模型返回“杭州当前温度为 24°C”的自然语言回答。
示例中的 "content": "24℃" 是代码直接写入的固定模拟结果,代表客户端工具回传,不是真实天气工具或实时天气数据。
页面明确写明 get_weather 的具体功能必须由用户提供,模型本身不执行函数。
strict beta 的要求是:端点使用 https://api.deepseek.com/beta;每个 function 设置 strict: true;服务端校验用户提交的 JSON Schema。
strict 模式支持 thinking 和 non-thinking mode;页面没有给出 thinking 开关或推理档位配置。
页面把示例放在标题为 “Non-thinking Mode” 的小节,但示例请求未显式传入 thinking 字段。当前模型首页默认 thinking 开启,因此该标题不能单独证明代码显式关闭了 thinking;复现时应按当前 API 的 thinking 配置确认实际模式。
strict 是 beta 能力,并非任意 JSON Schema 都能通过服务端校验;尤其要检查嵌套对象的 required 和 additionalProperties: false。
工具结果必须由客户端生成并按对应 tool_call_id 回传;不能把模型返回的函数调用当成已执行结果。
本文的 JSON 仅为最小工具定义片段,不包含 API key、完整客户端初始化、异常处理或真实工具实现。
2026-09-16 使用 Tabbit 浏览器完整读取 DeepSeek Tool Calls 页面;未执行真实 API 请求。复现 strict 配置时,按页面要求使用 beta 端点、strict: true 和完整 Schema;天气示例的 24℃ 应视为客户端固定模拟回传。
DeepSeek V4.1 Flash