代码解释器Agent对话
更新时间:2025-12-12
POST
https://qianfan.baidubce.com/v2/agent/code_interpreter/run
本接口用于调用“代码解释器”智能体。该 Agent 会自动分析用户需求,生成代码并运行,基于运行结果回答问题。
权限说明
调用本文API,需使用API Key鉴权方式。使用API Key鉴权调用API流程,具体调用流程,请查看认证鉴权。
请求参数
Headers 参数
除公共头域外,无其它特殊头域
Body 参数
query
string
输入的对话信息。
必选
file_ids
array
文件ID列表,通过文件上传接口获取。 file_id必须由当前对话(即本次请求的conversation_id)上传生成,且仅限在本对话中使用。
可选
显示子属性
隐藏子属性
items
string
conversation_id
string
对话ID。
首轮对话:可不填,由服务端自动生成并在响应中返回,也可通过对话创建接口预先获取对话ID。
后续对话:必须填写,以保持上下文连续性,可在sse数据流获取conversation_id。
可选
请求结构
POST /v2/agent/code_interpreter/run HTTP/1.1
HOST: qianfan.baidubce.com
Authorization: Bearer <API Key>
Content-Type: application/json
{
"query": "读取上传的文件并分析数据",
"file_ids": ["file-****55xw"]
}
示例代码
请求示例
curl -i --location 'https://qianfan.baidubce.com/v2/agent/browser_use/run' \
--header 'Authorization: Bearer bce-v3/ALTAK-********/86356c2efcefb5776024ddb7d7958640f2fc16bf' \
--header 'Content-Type: application/json' \
--data '{
"query": "今日时事新闻"
}'
返回响应
Headers 参数
除公共头域外,无其它特殊头域
返回参数
响应示例
data: {"role": "assistant", "status": "running", "content": [{"name": "/thought/thought_agent", "type": "text", "text": {"info": "用户询问北京今天的天气...需要调用浏览器工具搜索。"}, "event": {"id": "1", "status": "running", "name": "/thought/thought_agent"}}]}
data: {"role": "tool", "status": "running", "content": [{"name": "/toolcall/browser_use", "type": "browser", "text": {"status": "preparing", "thought": {"next_goal": "Navigate to weather.com"}, "action": [{"go_to_url": {"url": "https://weather.com", "new_tab": false}}], "screenshot": {"browser_url": "about:blank"}}, "event": {"id": "2", "status": "preparing", "name": "/toolcall/browser_use"}}]}
data: {"role": "tool", "status": "running", "content": [{"name": "/toolcall/browser_use", "type": "browser", "text": {"status": "success", "thought": {"next_goal": "Click 'Accept' to handle cookie consent."}, "action": [{"click_element": {"index": 11}}], "screenshot": {"url": "https://agi-dev-platform-file.bj.bcebos.com/.../screenshot_1.jpg", "file_id": "file-w6rudwik"}}, "event": {"id": "2", "status": "running", "name": "/toolcall/browser_use"}}]}
data: {"role": "tool", "status": "running", "content": [{"name": "/toolcall/browser_use", "type": "browser", "text": {"status": "success", "action": [{"done": {"text": "北京今日(2025年12月10日)天气实况:\n• 天气状况:晴朗\n• 当前温度:2°C...", "success": true}}]}, "event": {"id": "2", "status": "done", "name": "/toolcall/browser_use"}}]}
data: {"role": "assistant", "status": "running", "content": [{"name": "/chat/chat_agent", "type": "text", "text": {"info": "根据"}, "event": {"id": "6", "status": "running", "name": "/chat/chat_agent"}}]}
data: {"role": "assistant", "status": "running", "content": [{"name": "/chat/chat_agent", "type": "text", "text": {"info": "weather.com"}, "event": {"id": "6", "status": "running", "name": "/chat/chat_agent"}}]}
data: {"role": "assistant", "status": "running", "content": [{"name": "/chat/chat_agent", "type": "text", "text": {"info": "的数据,北京今天天气晴朗..."}, "event": {"id": "6", "status": "running", "name": "/chat/chat_agent"}}]}
data: {"role": "tool", "status": "done", "content": [], "conversation_id": "b041e3b3-...", "end_user_id": "", "message_id": "945dd3bb-..."}
