文档
API 参考登录

工具调用

仅向目录元数据明确包含工具支持的模型发送函数定义。

定义工具

聊天请求
{
  "model": "YOUR_APPROVED_MODEL_ID",
  "messages": [
    {
      "role": "user",
      "content": "What is the weather in Paris?"
    }
  ],
  "max_tokens": 256,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_weather",
        "description": "Look up weather for a city",
        "parameters": {
          "type": "object",
          "properties": {
            "city": {
              "type": "string"
            }
          },
          "required": [
            "city"
          ]
        }
      }
    }
  ],
  "tool_choice": "auto"
}

运行工具循环

  1. 读取响应中助手的 tool_calls。
  2. 在您自己的应用中验证请求的函数及参数。
  3. 取得操作所需授权后再执行工具。
  4. 使用对应 tool_call_id 回传工具结果。

网关转发工具定义及结果,不运行工具。请将模型输出及工具参数视为不可信输入。

能力错误

未验证工具支持的模型收到工具或工具消息时会返回 unsupported_capability 错误。启用客户端工具模式前请检查目录。