You need to enable JavaScript to run this app.
导航
工具调用
最近更新时间:2025.12.04 15:45:07首次发布时间:2025.12.04 15:45:07
复制全文
我的收藏
有用
有用
无用
无用

Responses API 支持使用方舟大模型内置工具、函数调用 Function Calling 等工具来扩展模型的功能。这些功能使模型能够搜索网络资料、图片处理、私域知识库搜索或者调用自定义函数。

快速开始

以天气查询场景为例,介绍使用函数调用 Function Calling 的方法。

第一轮请求: 触发工具调用

curl https://ark.cn-beijing.volces.com/api/v3/responses \
  -H "Authorization: Bearer $ARK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seed-1-6-251015",
    "store": true,
    "input": [
        {
            "type": "message",
            "role": "user",
            "content": "查询北京今天的天气"
        }
    ],
    "tools": [
        {
            "type": "function",
            "name": "get_weather",
            "description": "根据城市名称查询该城市当日天气(含温度、天气状况)",
            "parameters": {
                "type": "object",
                "properties": {
                    "location": {
                        "type": "string",
                        "description": "城市名称,如北京、上海(仅支持国内地级市)"
                    }
                },
                "required": ["location"]
            }
        }
    ]
  }'

第一轮响应:返回 function_call 指令
模型会返回工具调用指令,关键字段为call_id(关联后续结果)、arguments(调用参数):

{
    "created_at": 1756980000,
    "id": "resp_02175698000123456789abcdef0123",  # previous_response_id 
    "model": "doubao-seed-1-6-251015",
    "object": "response",
    "output": [
        {
            "arguments": "{\"location\":\"北京\"}",  # Parameters automatically extracted by the model
            "call_id": "call_abc123def456ghi789jkl0",  # Unique invocation ID for result correlation
            "name": "get_weather",
            "type": "function_call",
            "id": "fc_02175698000abcdef0123456789gh",
            "status": "completed"
        }
    ],
    "status": "completed",
    "store": true,
    "expire_at": 1757239200
}

执行工具:获取天气结果
开发者根据 arguments 调用实际天气工具(如第三方天气API),假设返回结果为:

{
    "city": "北京",
    "date": "2025-10-13",
    "temperature": "18~28℃",
    "condition": "晴转多云",
    "wind": "东北风2级"
}

第二轮请求:回传结果并生成最终响应
传入上一轮 response_id、工具结果,模型生成自然语言回答:

curl https://ark.cn-beijing.volces.com/api/v3/responses \
  -H "Authorization: Bearer $ARK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "doubao-seed-1-6-251015",
    "previous_response_id": "resp_02175698000123456789abcdef0123",  # Associate with the previous request
    "input": [
        {
            "type": "function_call_output",  # Return tool results
            "call_id": "call_abc123def456ghi789jkl0",   #  Consistent with the call_id of the instruction
            "output": "{\"city\":\"北京\",\"date\":\"2025-10-13\",\"temperature\":\"18~28℃\",\"condition\":\"晴转多云\",\"wind\":\"东北风2级\"}"
        }
    ]
  }'

第二轮响应:生成最终回答
模型结合工具结果,返回自然语言响应:

{
    "created_at": 1756980100,
    "id": "resp_02175698010abcdef0123456789gh",
    "model": "doubao-seed-1-6-250615",
    "object": "response",
    "output": [
        {
            "type": "message",
            "role": "assistant",
            "content": [
                {
                    "type": "output_text",
                    "text": "北京今天(2025-10-13)的天气为晴转多云,气温在18~28℃之间,东北风2级。"
                }
            ],
            "status": "completed",
            "id": "msg_02175698010abcdef0123456789ij"
        }
    ],
    "status": "completed",
    "store": true
}

支持工具

内置工具

当通过 Responses API 创建模型响应时,您可以通过在参数中配置tools字段来访问工具。每个工具中都有独特的配置要求,具体见如下教程:

  • 联网搜索 Web Search
    支持获取实时公开网络信息(如新闻、商品、天气等),解决数据时效性、知识盲区、信息同步等核心问题,并且无需自行开发搜索引擎或维护数据资源。
  • 图像处理 Image Process
    支持通过 Responses API 调用对输入图片执行画点、画线、旋转、缩放、框选/裁剪关键区域等基础操作,适用于需模型通过视觉处理提升图片理解的场景(如图文内容分析、物体定位标注、多轮视觉推理等)。工具通过模型自动判断图像处理逻辑,支持与自定义 Function 混合使用,且可处理多轮视觉输入(上一轮输出图片作为下一轮输入)。
  • 私域知识库搜索 Knowledge Search
    支持通过 Responses API 调用直接获取企业私域知识库中的信息(如内部文档、产品手册、行业资料等),适用于需基于企业专属数据解答问题的场景(如内部培训问答、产品功能咨询、行业方案查询等)。工具通过模型自动判断是否需要调用私域知识库,支持与自定义 Function、MCP 等工具混合使用,目前仅支持旗舰版知识库。
  • 云部署 MCP / Remote MCP
    对接“MCP MarketPlace”,支持调用市场内各类垂直领域MCP工具(如巨量千川、知识库),无需自行开发工具逻辑。适用于复杂任务(如多步数据查询 + 分析)场景,支持与自定义 Function、Web Search 工具混合使用。

函数调用 Function Calling

您也可以在创建模型响应时,使用tools来定义自定义函数。模型通过调用自定义函数代码,来访问模型中无法直接使用的特定数据或功能。了解更多信息,请参见函数调用 Function Calling