功能指南

工具调用

编程 Agent(Claude Code、OpenCode、Cline 等)靠工具调用读写文件、执行命令。只有部分模型支持。

哪些模型支持

当前支持工具调用的模型:gemma-4-uncensored、deepseek-v4-1-flash、olafangensan-glm-4.7-flash-heretic、z-ai/glm-5.3-uncensored。

GET /v1/models?type=chat 返回的 supportsTools 为 true 的就是。给不支持的模型传 tools,会得到 400:

{"error": {"code": "VALIDATION_ERROR", "message": "模型 <模型 id> 不支持工具调用。支持工具调用的模型:…", "details": {"field": "tools"}}}

OpenAI 格式:一次完整往返

第一步,带上工具定义发问:

curl https://sichang.xyz/api/v1/chat/completions \
  -H "Authorization: Bearer $SICHANG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<模型 id>",
    "messages": [{"role": "user", "content": "北京现在天气怎么样?"}],
    "tools": [{"type": "function", "function": {
      "name": "get_weather",
      "description": "查询城市当前天气",
      "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}
    }}]
  }'

模型决定调用工具时,finish_reason 是 tool_calls,参数在 message.tool_calls:

"tool_calls": [{"id": "call_1", "type": "function",
  "function": {"name": "get_weather", "arguments": "{\"city\": \"北京\"}"}}]

第二步,执行工具,把结果作为 role: tool 消息追加回去(tool_call_id 对应上一步的 id),连同原来的 tools 再发一次:

"messages": [
  {"role": "user", "content": "北京现在天气怎么样?"},
  {"role": "assistant", "content": null, "tool_calls": [{"id": "call_1", "type": "function",
    "function": {"name": "get_weather", "arguments": "{\"city\":\"北京\"}"}}]},
  {"role": "tool", "tool_call_id": "call_1", "content": "{\"temp\":18,\"sky\":\"晴\"}"}
]

模型据此给出最终回答,finish_reason 变回 stop。

支持的字段:tools(只支持 type: function,最多 128 个,工具名 1~64 位字母、数字、下划线或连字符)、tool_choice(auto、none、required 或指定函数)、parallel_tool_calls。旧版的 functions / function_call 不支持,请改用 tools。

个别模型单次接受的工具数更少,超出时返回 400(field 为 tools),错误信息里写明该模型的上限。

Anthropic 格式

/v1/messages 接受 Anthropic 标准的 tools(name + input_schema)与 tool_choice(auto、any、tool、none),返回 tool_use 内容块,结果用 tool_result 块回传。Claude Code 用的就是这一套。

Anthropic 的服务端工具(如网页搜索)不支持,会被忽略。

内容审核与工具结果

内容审核只看用户消息,工具返回的结果(代码、命令输出)不参与审核,不会因为代码里的关键词被误拦。