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字段来访问工具。每个工具中都有独特的配置要求,具体见如下教程:
您也可以在创建模型响应时,使用tools来定义自定义函数。模型通过调用自定义函数代码,来访问模型中无法直接使用的特定数据或功能。了解更多信息,请参见函数调用 Function Calling。