Run
本文档描述 Assistants API 中与 Run 相关的接口。
1. 运行
功能介绍
一个 Assistant 的一次具体运行,区分初次对话和继续对话两种情况
请求说明
基本信息
请求地址:https://appbuilder.baidu.com/v2/threads/runs
请求方式:POST
请求参数
Header
请参考 公共类型定义中,公共请求头的定义
Body
参数 | 语义 | 是否必填 | 取值/类型 | 备注 |
---|---|---|---|---|
thread_id | 一个对话流的标识ID | 否 | string | 当传参时:使用一个已经存在的thread继续对话 当不传参时:创建一个新的空thread进行对话 |
thread | 本次对话追加的thread | 否 | Thread |
本次对话追加的thread 请注意,在run接口中追加的Thread中,仅可以存在一轮role为user的message。thread内的对话内容,会追加到thread_id查出来的历史对话之后。即: 本轮对话的完整上下文 = thread_id查出来的历史对话 + 本轮追加的thread中的messages 例如: thread_id为空,thread的messages有值的情况: 1. thread_id为空 2. thread的messages为[{"role": "user", "content": "你好"}] 3. 完整对话为[{"role": "user", "content": "你好"}] thread_id有值,thread的messages有值的情况: 1. thread_id历史对话内容为:[{"role": "user", "content": "你好"}, {"role": "assistant", "content": "你好,我能帮你做什么?"}] 2. thread的messages为[{"role": "user", "content": "帮我算下$$2^{16}$$"}] 3. 完整对话为:[{"role": "user", "content": "你好"}, {"role": "assistant", "content": "你好,我能帮你做什么?"}, {"role": "user", "content": "帮我算下$$2^{16}$$"}]] thread_id有值,thread为空的情况: 1. thread_id历史对话内容为:[{"role": "user", "content": "你好"}, {"role": "assistant", "content": "你好,我能帮你做什么?"}, {"role": "user", "content": "帮我算下$$2^{16}$$"} ] 2. thread为空 3. 完整对话为:[{"role": "user", "content": "你好"}, {"role": "assistant", "content": "你好,我能帮你做什么?"}, {"role": "user", "content": "帮我算下$$2^{16}$$"} ] 注意: 1. 若thread_id没有传,则thread必须要传值 2. 若这里不传值,thread_id查出来的历史对话,最后一条消息的role必须为user 3. 若这里传值,则需要保证thread_id查出来的历史对话 + 本轮追加的thread对话,最后一条消息的role必须为user |
model | 模型名 | 否 | string | 枚举 - ERNIE-4.0-8K - ERNIE-3.5-8K 这里填写时,执行会覆盖Assistant对象中的model参数的值。 |
assistant_id | 一个assistant的标识ID | 是 | string | assistant_id需要提前调用创建接口创建 |
response_format | 回复格式 | 否 | string | 枚举: - text(默认) - json_object 这里填写时,执行会覆盖assistant对象中的response_format参数的值 |
instructions | 系统人设指令 | 否 | string | 建议填写,能够提升模型的整体效果 长度限制4096,所有用户输入的token和需要小于4096 概述Agent的整体功能和定位,需要它扮演一个什么样的"角色。 1. 可以参考“你是xxx,你具有xx的特点,你可以做xxx,你需要满足用户xxx的需求”这样的结构。 2. 可以指定一些与能力边界相关要求(对于哪些类型的问题,无法回答) 示例: 你是一个音乐智能语音助手,可以通过调用技能的方式满足用户听音乐,看电影,追剧,刷短视频,听有声读物,信息问答等需求。你无法提供与政治和政策相关的内容;当用户提出与音乐、视频等娱乐信息不相关的问题时,你需要委婉地拒绝用户。 这里填写时,执行会覆盖Assistant对象中的instructions参数的值。 |
thought_instructions | 思考规范 | 否 | string | 建议填写,能够提升模型的整体效果 长度限制4096,所有用户输入的token和需要小于4096 与业务逻辑和规则相关的指令。希望模型遵守的行为规范和准则、要求都尽可能清晰、详尽地在这里给出描述。包括但不限于: 在什么情况下需要调用什么工具;在调用xxx工具之前需要先调用xxx工具获取什么信息; xxx工具填参的要求和偏好;(优先设定在工具描述中,如果较复杂,可以在这里强调) 在模型判断结果无法满足用户时采取什么行动(换一个工具,或者改变参数调同一个工具,或是告知用户无法满足但努力基于当前信息提供结果,等); 示例: 你需要遵循以下要求: 1.当用户给出特定的歌曲名,或者给出特定歌手,或者给出特定风格的音乐时,优先调用music_player工具 2.如果发现用户给出的是歌词,或者判断不出歌曲的名字、歌手时,请优先调用调用web_search工具获取歌名以及歌手,然后再去调用music_player工具 3.当web_search返回结果存在内容错误、质量差、不相关、资源陈旧以及信息量不足等情况时,你可以尝试优化查询词并重新调用web_search。 这里填写时,执行会覆盖Assistant对象中的thought_instructions参数的值。 |
chat_instructions | 回复规范 | 否 | string | 建议填写,能够提升模型的整体效果 长度限制4096,所有用户输入的token和需要小于4096 与模型最终给出的回复内容相关的指令。包括但不限于: 1. 语气偏好 2. 回复格式要求 3. 回复内容的丰富程度 4. 开头和结尾的形式要求,例如在结尾时需要向用户提问引导话题深入进行 示例: 1.你需要对用户的需求和问题给予耐心细致的回应;根据用户的输入,灵活调整对话内容,确保对话流畅自然。 2.当需要推荐电影给用户时,你需要按照以下格式输出:[电影名称](url):推荐理由 3.可以在回复中适当插入emoji表情,提升亲切感 这里填写时,执行会覆盖Assistant对象中的chat_instructions参数的值。 |
model_parameters | 模型参数 | 否 | ModelParameters |
模型超参定义,包含思考模型和回复模型 |
stream | 是否流式输出 | 否 | bool | 当需要流式调用时,设置为true; 当需要非流式调用时,设置为false; 默认为true (流式调用) |
tools | 启用的工具列表 | 否 | array [Tool ] |
用于动态修改assistant的工具集 建议 <= 5个,整体挂载工具个数 <= 10。 这里填写时,执行会覆盖assistant对象中的tools参数的值 |
metadata | 元信息 | 否 | map<string, string> | 一组可以附加到对象的16个键值对。这对于以结构化格式存储关于对象的附加信息非常有用。键的长度最多为64个字符,值的长度最多可为512个字符 目前我们通过该字段,设计了一些键值对,用于细粒度控制流式输出的内容 详细信息请查看metadata文档 |
tool_output | 提交工具输出结果 | 否 | ToolOutput |
仅非流式接口使用 提交外部工具结果 |
响应说明
流式响应参数
Header
Content-Type:text/event-stream
其他参数请参考 公共类型定义中,公共响应头的定义
Body
注:其它不能识别的消息类型,请务必自动跳过,以保持对后续新增消息类型的兼容性
event: ping 心跳包,保持连接用,直接忽略
event: status 状态包,表示状态机的流转
参数名称 | 类型 | 描述 |
---|---|---|
status | string | 状态,枚举同上 |
send_id | integer | 当前的消息ID,用来标记每条消息的编号 |
message | string | 当前的状态描述 |
event_type | string | 当前通知的消息类型 run_begin :run开始运行,暂时不用处理 run_cancelling:run被取消运行,尚未终止,暂时不用处理 tool_calls:触发了function_call的requires_action动作 message_creation:run运行过程中,大模型产出消息 run_end:run结束运行,暂时不用处理 tool_step_begin:工具步骤开始运行,暂时不用处理 tool_step_end:工具步骤结束运行,暂时不用处理 |
details | object | 事件的详细信息 |
+type | string | 当前detail的类型,不同type,有不同的detail字段名 请注意,其它不能识别的type,请务必自动跳过,以保持对后续新增type的兼容性 message_creation: run运行过程中,产生了大模型的最终消息时,将message内容通知调用方 run_object: run开始运行或者结束运行时,将 RunObject 完整对象通知调用方。run_step_object: 单独的一个工具步骤开始运行、或结束运行时,将 RunStepObject 完整对象通知调用方tool_calls: run运行中,触发了function_call的requires_action动作时,将tool_calls的信息(含tool_calls_id,arguments等)通知调用方 action_info: 插件工具运行过程中,通知action_name、action_content状态消息 |
+message_creation | object | |
++message_id | string | 消息ID |
+run_object | RunObject | 参见RunObject 对象 |
+run_step_object | RunStepObject | 参见RunStepObject 对象 |
+tool_calls | array [object] | function_call的事件,注意这里是个array |
++id | string | 工具调用的ID |
++type | string | 固定为function |
++function | object | function_call参数 |
+++name | string | function名 |
+++arguments | string | function调用参数 |
+++output | string | function输出 |
+action_info | object | |
++tool_name | string | 工具名 |
++action_name | string | 工具状态名 |
++action_content | string | 工具状态内容 |
+error_info | LastError | 报错信息 |
event: message
参数名称 | 类型 | 描述 |
---|---|---|
status | string | 状态,枚举同上 |
send_id | integer | 消息顺序ID,从1开始,顺序递增 |
is_end | integer | 0 / 1 |
message_id | string | message的id |
message_index | string | message的顺序 |
content | array [Content] | 消息内容 |
非流式响应参数
Header
请参考 公共类型定义中,公共响应头的定义
Body
请参考 公共类型定义 中的 RunObject 对象
请求与响应示例
流式首次请求示例
1curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs' \
2-H "Authorization: Bearer $APPBUILDER_TOKEN" \
3-H "Content-Type: application/json" \
4-d '{
5 "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
6 "tools": [
7 {
8 "type": "code_interpreter"
9 },
10 {
11 "type": "function",
12 "function": {
13 "name": "get_cur_whether",
14 "description": "这是一个获得当地天气的工具",
15 "parameters": {
16 "type": "object",
17 "properties": {
18 "location": {
19 "type": "string",
20 "description": "省,市名,例如:河北省"
21 },
22 "unit": {
23 "type": "string",
24 "enum": [
25 "摄氏度",
26 "华氏度"
27 ]
28 }
29 },
30 "required": [
31 "location"
32 ]
33 }
34 }
35 }
36 ],
37 "instructions": "自由发挥",
38 "thread": {
39 "messages": [
40 {
41 "role": "user",
42 "content": "北京的天气咋样呢?"
43 }
44 ]
45 }
46}'
流式首次请求响应示例
1event:ping
2
3event:status
4
5data:{"status":"queued","send_id":1,"message":"begin to run. logId:06130a86-1600-43a8-b614-607ece389a1a","event_type":"run_begin","details":{"type":"run_object","run_object":{"object":"thread.run","status":"queued","instructions":"自由发挥","tools":[{"type":"code_interpreter"},{"type":"function","function":{"name":"get_cur_whether","description":"这是一个获得当地天气的工具","parameters":{"type":"object","properties":{"location":{"type":"string","description":"省,市名,例如:河北省"},"unit":{"type":"string","enum":["摄氏度","华氏度"]}},"required":["location"]}}}],"id":"run_242250253bd145fbac27e34bca4e221b","created_at":1712689169289,"assistant_id":"asst_0a1d030f277f4ad2abe0297959f219e8","thread_id":"thread_c9ec4a6a9308416995cf3c549bf79e8a","expires_at":1712689769289,"expired_at":0,"started_at":1712689169376,"cancelled_at":0,"failed_at":0,"completed_at":0,"user_storage":"","response_format":"text"}}}
6
7event:status
8
9data:{"status":"in_progress","send_id":2,"message":"begin to run step","event_type":"tool_step_begin","details":{"type":"run_step_object","run_step_object":{"object":"thread.run.step","status":"in_progress","id":"step-1","created_at":1712689169384,"assistant_id":"asst_0a1d030f277f4ad2abe0297959f219e8","thread_id":"thread_c9ec4a6a9308416995cf3c549bf79e8a","run_id":"run_242250253bd145fbac27e34bca4e221b","expired_at":0,"cancelled_at":0,"failed_at":0,"completed_at":0}}}
10
11event:status
12
13data:{"status":"requires_action","send_id":3,"message":"requires action","event_type":"tool_calls","details":{"type":"tool_calls","tool_calls":[{"id":"call-thread_c9ec4a6a9308416995cf3c549bf79e8a-run_242250253bd145fbac27e34bca4e221b-step-1","type":"function","function":{"name":"get_cur_whether","arguments":"{\"location\":\"北京市\"}"}}]}}
注意:requires_action事件时,请调用提交工具输出接口进行工具结果提交
流式提交完毕工具输出后继续输出
1event:status
2
3data:{"status":"in_progress","send_id":4,"message":"After submitted outputs, the functionCall continues to run","event_type":"tool_submitted_output","details":{"type":"tool_calls","tool_calls":[{"id":"call-thread_6c8da8556fcc4bcb95d2c15dc81b2654-run_8c7a6c1da9ea46148a86735c697d1cb9-step-1","type":"function","function":{"name":"get_cur_whether","arguments":"{\"location\":\"北京市\"}","output":"{\"temperature\": 30, \"humidity\": \"30%\"}"}}]}}
4
5event:status
6
7data:{"status":"in_progress","send_id":5,"message":"step end","event_type":"tool_step_end","details":{"type":"run_step_object","run_step_object":{"object":"thread.run.step","status":"completed","id":"step-1","created_at":1712689299862,"assistant_id":"asst_0a1d030f277f4ad2abe0297959f219e8","thread_id":"thread_6c8da8556fcc4bcb95d2c15dc81b2654","run_id":"run_8c7a6c1da9ea46148a86735c697d1cb9","step_details":{"type":"tool_calls","tool_calls":[{"id":"call-thread_6c8da8556fcc4bcb95d2c15dc81b2654-run_8c7a6c1da9ea46148a86735c697d1cb9-step-1","type":"function","function":{"name":"get_cur_whether","arguments":"{\"location\":\"北京市\"}","output":"{\"temperature\": 30, \"humidity\": \"30%\"}"}}]},"expired_at":0,"cancelled_at":0,"failed_at":0,"completed_at":1712689367912}}}
8
9event:status
10
11data:{"status":"in_progress","send_id":6,"message":"begin to run step","event_type":"tool_step_begin","details":{"type":"run_step_object","run_step_object":{"object":"thread.run.step","status":"in_progress","id":"step-2","created_at":1712689367913,"assistant_id":"asst_0a1d030f277f4ad2abe0297959f219e8","thread_id":"thread_6c8da8556fcc4bcb95d2c15dc81b2654","run_id":"run_8c7a6c1da9ea46148a86735c697d1cb9","expired_at":0,"cancelled_at":0,"failed_at":0,"completed_at":0}}}
12
13event:status
14
15data:{"status":"in_progress","send_id":7,"message":"message created","event_type":"message_creation","details":{"type":"message_creation","message_creation":{"message_id":"chatmsg_979c8bfa026d4894a2c1f4adbdf1975c"}}}
16
17event:message
18
19data:{"status":"completed","send_id":8,"message_id":"chatmsg_979c8bfa026d4894a2c1f4adbdf1975c","content":[{"type":"text","text":{"value":"根据查询,今天北京的天气情况如下:\n\n温度:30摄氏度\n湿度:30%\n\n如果您需要更详细的天气信息,比如风向、风速、气压等,请告诉我,我会尽力为您提供。"}}]}
20
21event:status
22
23data:{"status":"completed","send_id":9,"message":"step end","event_type":"tool_step_end","details":{"type":"run_step_object","run_step_object":{"object":"thread.run.step","status":"completed","id":"step-2","created_at":1712689367913,"assistant_id":"asst_0a1d030f277f4ad2abe0297959f219e8","thread_id":"thread_6c8da8556fcc4bcb95d2c15dc81b2654","run_id":"run_8c7a6c1da9ea46148a86735c697d1cb9","step_details":{"type":"message_creation","message_creation":{"message_id":"chatmsg_979c8bfa026d4894a2c1f4adbdf1975c"}},"expired_at":0,"cancelled_at":0,"failed_at":0,"completed_at":1712689373968}}}
24
25event:status
26
27data:{"status":"completed","send_id":10,"message":"run end. duration:74s logId:e8bfdc0a-13a1-422a-8da1-2a14795a762f","event_type":"run_end","details":{"type":"run_object","run_object":{"object":"thread.run","status":"completed","instructions":"***","tools":[{"type":"code_interpreter"},{"type":"function","function":{"name":"get_cur_whether","description":"这是一个获得当地天气的工具","parameters":{"type":"object","properties":{"location":{"type":"string","description":"省,市名,例如:河北省"},"unit":{"type":"string","enum":["摄氏度","华氏度"]}},"required":["location"]}}}],"id":"run_8c7a6c1da9ea46148a86735c697d1cb9","created_at":1712689299768,"assistant_id":"asst_0a1d030f277f4ad2abe0297959f219e8","thread_id":"thread_6c8da8556fcc4bcb95d2c15dc81b2654","expires_at":1712689899768,"expired_at":0,"started_at":1712689299855,"cancelled_at":0,"failed_at":0,"completed_at":1712689373968,"user_storage":"","response_format":"text"}}}
非流式首次调用请求示例
1curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs' \
2-H "Authorization: Bearer $APPBUILDER_TOKEN" \
3-H "Content-Type: application/json" \
4-d '{
5 "assistant_id": "asst_551b2d29d5604711a40a1a0411f916e5",
6 "stream": false,
7 "tools": [
8 {
9 "type": "code_interpreter"
10 },
11 {
12 "type": "function",
13 "function": {
14 "name": "get_cur_whether",
15 "description": "这是一个获得当地天气的工具",
16 "parameters": {
17 "type": "object",
18 "properties": {
19 "location": {
20 "type": "string",
21 "description": "省,市名,例如:河北省"
22 },
23 "unit": {
24 "type": "string",
25 "enum": [
26 "摄氏度",
27 "华氏度"
28 ]
29 }
30 },
31 "required": [
32 "location"
33 ]
34 }
35 }
36 }
37 ],
38 "thread": {
39 "messages": [
40 {
41 "role": "user",
42 "content": "北京的天气咋样呢?"
43 }
44 ]
45 }
46}'
非流式响应示例(等待外部工具输出)
1{
2 "id": "run_9cedcbf2cf8c4b12b9a6f946a897c9af",
3 "object": "run.result",
4 "status": "requires_action",
5 "log_id": "0862fcf1-bade-4212-932f-d9e9638915fa",
6 "created_at": 1713065647614,
7 "assistant_id": "asst_551b2d29d5604711a40a1a0411f916e5",
8 "thread_id": "thread_1bc2ee388abf4984b59dfda53e2d6878",
9 "started_at": 1713065647682,
10 "expired_at": 0,
11 "cancelled_at": 0,
12 "failed_at": 0,
13 "completed_at": 0,
14 "required_action": {
15 "type": "submit_tool_outputs",
16 "submit_tool_outputs": {
17 "tool_calls": [
18 {
19 "id": "call-thread_1bc2ee388abf4984b59dfda53e2d6878-run_9cedcbf2cf8c4b12b9a6f946a897c9af-step-1",
20 "type": "function",
21 "function": {
22 "name": "get_cur_whether",
23 "arguments": "{\"location\":\"北京\"}"
24 }
25 }
26 ]
27 }
28 },
29 "final_answer": null,
30 "last_error": null
31}
非流式提交外部工具输出请求示例
1curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs' \
2-H "Authorization: Bearer $APPBUILDER_TOKEN" \
3-H "Content-Type: application/json" \
4-d '{
5 "assistant_id": "asst_551b2d29d5604711a40a1a0411f916e5",
6 "thread_id": "thread_53542434d56a49a580431ada3a7c778f",
7 "stream": false,
8 "tool_output": {
9 "run_id": "run_acc62d1a5a1942aeb940ac531e475de2",
10 "tool_call_id": "call-thread_53542434d56a49a580431ada3a7c778f-run_acc62d1a5a1942aeb940ac531e475de2-step-1",
11 "output": "{\"temperature\": 30, \"humidity\": \"30%\"}"
12 }
13}'
非流式提交完毕工具输出后继续输出响应示例
1{
2 "id": "run_acc62d1a5a1942aeb940ac531e475de2",
3 "object": "run.result",
4 "status": "completed",
5 "log_id": "c54f7410-c769-458c-ac94-0b923a8b208d",
6 "created_at": 1713072771076,
7 "assistant_id": "asst_551b2d29d5604711a40a1a0411f916e5",
8 "thread_id": "thread_53542434d56a49a580431ada3a7c778f",
9 "started_at": 1713072946394,
10 "expired_at": 0,
11 "cancelled_at": 0,
12 "failed_at": 0,
13 "completed_at": 1713072952421,
14 "required_action": null,
15 "final_answer": {
16 "type": "message",
17 "message": {
18 "content": {
19 "type": "text",
20 "text": {
21 "value": "根据查询,今天北京的天气情况如下:温度约为30度,湿度为30%。希望这些信息能对您有所帮助。如果您还有其他问题或需要更多信息,请随时告诉我。"
22 }
23 },
24 "message_id": "chatmsg_669409fc23b844a3ba2b1cbee416f6ff"
25 }
26 },
27 "last_error": null
28}
2. 流式调用时提交工具输出
功能介绍
仅流式调用时使用,提交外部工具调用结果
请求说明
基本信息
请求地址:https://appbuilder.baidu.com/v2/threads/runs/submit_tool_outputs
请求方式: POST
请求参数
Header
请参考 公共类型定义中,公共请求头的定义
Body
参数名称 | 是否必填 | 类型 | 描述 |
---|---|---|---|
thread_id | 是 | string | 要提交的结果并继续运行的thread的ID,来源于上一轮Run请求返回thread_id字段 |
run_id | 是 | string | 要提交的结果并继续运行的run的ID,来源于上一轮run请求返回的id字段。 |
tool_outputs | 是 | array [ToolOutput ] |
工具输出列表 请参考公共类型中ToolOutput对象 |
请求示例
1curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/submit_tool_outputs' \
2-H "Authorization: Bearer $APPBUILDER_TOKEN" \
3-H "Content-Type: application/json" \
4-d '{
5 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
6 "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
7 "tool_outputs": [
8 {"tool_call_id": "call-thread_6c8da8556fcc4bcb95d2c15dc81b2654-run_8c7a6c1da9ea46148a86735c697d1cb9-step-1", "output": "{\"temperature\": 30, \"humidity\": \"30%\"}"}
9 ]
10}'
响应说明
响应参数
Header
请参考 公共类型定义中,公共响应头的定义
Body
请参考 公共类型定义 中的 RunObject 对象
响应示例
1{
2 "id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
3 "object": "thread.run",
4 "status": "in_progress",
5 "instructions": "",
6 "tools": [],
7 "created_at": 1712689299768,
8 "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
9 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
10 "required_action": null,
11 "started_at": 0,
12 "expires_at": 0,
13 "expired_at": 0,
14 "cancelled_at": 0,
15 "failed_at": 0,
16 "completed_at": 0,
17 "last_error": null,
18 "file_ids": null
19}
3. 流式调用时取消运行
功能介绍
仅流式调用时使用,取消当前运行
请求说明
基本信息
请求地址:https://appbuilder.baidu.com/v2/threads/runs/cancel
请求方式: POST
请求参数
Header
请参考 公共类型定义中,公共请求头的定义
Body
参数名称 | 是否必填 | 类型 | 描述 |
---|---|---|---|
thread_id | 是 | string | 要提交的结果并继续运行的thread的ID,来源于上一轮run请求返回thread_id字段 |
run_id | 是 | string | 要提交的结果并继续运行的run的ID,来源于上一轮run请求返回的id字段。 |
请求示例
1curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/cancel' \
2-H "Authorization: Bearer $APPBUILDER_TOKEN" \
3-H "Content-Type: application/json" \
4-d '{
5 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
6 "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9"
7}'
响应说明
响应参数
Header
请参考 公共类型定义中,公共响应头的定义
Body
请参考 公共类型定义 中的 RunObject 对象
响应示例
1{
2 "id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
3 "object": "thread.run",
4 "status": "completed",
5 "instructions": "",
6 "tools": [],
7 "created_at": 1712689299768,
8 "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
9 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
10 "required_action": null,
11 "started_at": 0,
12 "expires_at": 0,
13 "expired_at": 0,
14 "cancelled_at": 0,
15 "failed_at": 0,
16 "completed_at": 1712689373969,
17 "last_error": null,
18 "file_ids": null
19}
4. 列出对应thread的历史run记录
功能介绍
列出对应thread的历史run记录
请求说明
基本信息
请求地址:https://appbuilder.baidu.com/v2/threads/runs/list
请求方式: POST
请求参数
Header
请参考 公共类型定义中,公共请求头的定义
Body
参数名称 | 是否必填 | 类型 | 描述 |
---|---|---|---|
thread_id | 是 | string | thread_id |
limit | 否 | integer | 一次列举结果条数,默认20 |
order | 否 | string | 升序还是降序输出,默认desc,枚举: - desc - asc |
after | 否 | string | 从指定run_id之后开始列出 |
before | 否 | string | 从指定run_id之前开始列出 |
请求示例
1curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/list' \
2-H "Authorization: Bearer $APPBUILDER_TOKEN" \
3-H "Content-Type: application/json" \
4-d '{
5 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654"
6}'
响应说明
响应参数
Header
请参考 公共类型定义中,公共响应头的定义
Body
参数名称 | 类型 | 描述 |
---|---|---|
object | string | 固定为list |
first_id | string | 起始run Id |
last_id | string | 结束run Id |
has_more | bool | 是否还有更多 |
data | array[RunObject ] |
run信息列表 |
响应示例
1{
2 "object": "list",
3 "data": [
4 {
5 "id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
6 "object": "thread.run",
7 "status": "completed",
8 "instructions": "",
9 "tools": null,
10 "metadata": null,
11 "usage": null,
12 "created_at": 1712689299768,
13 "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
14 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
15 "required_action": {
16 "type": "submit_tool_outputs",
17 "submit_tool_outputs": {
18 "tool_calls": [
19 {
20 "id": "call-thread_6c8da8556fcc4bcb95d2c15dc81b2654-run_8c7a6c1da9ea46148a86735c697d1cb9-step-1",
21 "type": "function",
22 "function": {
23 "name": "get_cur_whether",
24 "arguments": "{\"location\":\"北京市\"}"
25 }
26 }
27 ]
28 }
29 },
30 "started_at": 0,
31 "expires_at": 0,
32 "expired_at": 0,
33 "cancelled_at": 0,
34 "failed_at": 0,
35 "completed_at": 1712689373969,
36 "last_error": null,
37 "file_ids": null
38 }
39 ],
40 "first_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
41 "last_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
42 "has_more": false
43}
5. 查询对应run的信息
功能介绍
根据thread_id和run_id,查询run的详情
请求说明
基本信息
请求地址:https://appbuilder.baidu.com/v2/threads/runs/query
请求方式: POST
请求参数
Header
请参考 公共类型定义 中,公共请求头的定义
Body
参数名称 | 是否必填 | 类型 | 描述 |
---|---|---|---|
thread_id | 是 | string | thread_id |
run_id | 是 | string | run_id |
请求示例
1curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/query' \
2-H "Authorization: Bearer $APPBUILDER_TOKEN" \
3-H "Content-Type: application/json" \
4-d '{
5 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
6 "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9"
7}'
响应说明
响应参数
Header
请参考 公共类型定义中,公共响应头的定义
Body
请参考 公共类型定义 中的 RunObject 对象
响应示例
1{
2 "id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
3 "object": "thread.run",
4 "status": "completed",
5 "instructions": "",
6 "tools": [],
7 "metadata": null,
8 "usage": null,
9 "created_at": 1712689299768,
10 "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
11 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
12 "required_action": {
13 "type": "submit_tool_outputs",
14 "submit_tool_outputs": {
15 "tool_calls": [
16 {
17 "id": "call-thread_6c8da8556fcc4bcb95d2c15dc81b2654-run_8c7a6c1da9ea46148a86735c697d1cb9-step-1",
18 "type": "function",
19 "function": {
20 "name": "get_cur_whether",
21 "arguments": "{\"location\":\"北京市\"}"
22 }
23 }
24 ]
25 }
26 },
27 "started_at": 0,
28 "expires_at": 0,
29 "expired_at": 0,
30 "cancelled_at": 0,
31 "failed_at": 0,
32 "completed_at": 1712689373969,
33 "last_error": null,
34 "file_ids": null
35}
6. 列出对应run的历史step记录
功能介绍
根据thread_id和run_id,列出对应run的历史step记录
请求说明
基本信息
请求地址:https://appbuilder.baidu.com/v2/threads/runs/steps/list
请求方式: POST
请求参数
Header
请参考 公共类型定义中,公共请求头的定义
Body
参数名称 | 是否必填 | 类型 | 描述 |
---|---|---|---|
thread_id | 是 | string | thread_id |
run_id | 是 | string | run_id |
limit | 否 | integer | 一次列举结果条数,默认20 |
order | 否 | string | 升序还是降序输出,默认desc,枚举: - desc - asc |
after | 否 | string | 从指定step_id之后开始列出 |
before | 否 | string | 从指定step_id之前开始列出 |
请求示例
1curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/steps/list' \
2-H "Authorization: Bearer $APPBUILDER_TOKEN" \
3-H "Content-Type: application/json" \
4-d '{
5 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
6 "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9"
7}'
响应说明
响应参数
Header
请参考 公共类型定义中,公共响应头的定义
Body
参数名称 | 类型 | 描述 |
---|---|---|
object | string | 固定为list |
first_id | string | 起始run step_id |
last_id | string | 结束run step_id |
has_more | bool | 是否还有更多 |
data | array[RunStepObject ] |
run step信息列表 |
响应示例
1{
2 "object": "list",
3 "data": [
4 {
5 "id": "step-2",
6 "object": "thread.run.step",
7 "type": null,
8 "status": "completed",
9 "usage": null,
10 "created_at": 1712689373981,
11 "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
12 "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
13 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
14 "cancelled_at": 0,
15 "completed_at": 1712689373969,
16 "expired_at": 0,
17 "failed_at": 0,
18 "last_error": "",
19 "step_detail": {
20 "type": "message_creation",
21 "message_creation": {
22 "message_id": "chatmsg_979c8bfa026d4894a2c1f4adbdf1975c"
23 }
24 }
25 },
26 {
27 "id": "step-1",
28 "object": "thread.run.step",
29 "type": null,
30 "status": "completed",
31 "usage": null,
32 "created_at": 1712689303754,
33 "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
34 "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
35 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
36 "cancelled_at": 0,
37 "completed_at": 1712689367912,
38 "expired_at": 0,
39 "failed_at": 0,
40 "last_error": "",
41 "step_detail": {
42 "type": "tool_calls",
43 "tool_calls": [
44 {
45 "id": "call-thread_6c8da8556fcc4bcb95d2c15dc81b2654-run_8c7a6c1da9ea46148a86735c697d1cb9-step-1",
46 "type": "function",
47 "function": {
48 "name": "get_cur_whether",
49 "arguments": "{\"location\":\"北京市\"}",
50 "output": "{\"temperature\": 30, \"humidity\": \"30%\"}"
51 }
52 }
53 ]
54 }
55 }
56 ],
57 "first_id": "step-2",
58 "last_id": "step-1",
59 "has_more": false
60}
7. 查询对应step的信息
功能介绍
根据thread_id,run_id和step_id,查询对应step的信息
请求说明
基本信息
请求地址:https://appbuilder.baidu.com/v2/threads/runs/steps/query
请求方式: POST
请求参数
Header
请参考公共类型定义中,公共请求头的定义
Body
参数名称 | 是否必填 | 类型 | 描述 |
---|---|---|---|
thread_id | 是 | string | thread_id |
run_id | 是 | string | run_id |
step_id | 是 | string | step_id |
请求示例
1curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/steps/query' \
2-H "Authorization: Bearer $APPBUILDER_TOKEN" \
3-H "Content-Type: application/json" \
4-d '{
5 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
6 "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
7 "step_id": "step-2"
8}'
响应说明
响应参数
Header
请参考 公共类型定义中,公共响应头的定义
Body
请参考 公共类型定义中,RunStepObject
的定义
响应示例
1{
2 "id": "step-2",
3 "object": "thread.run.step",
4 "type": null,
5 "status": "completed",
6 "usage": null,
7 "created_at": 1712689373981,
8 "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
9 "assistant_id": null,
10 "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
11 "cancelled_at": 0,
12 "completed_at": 1712689373969,
13 "expired_at": 0,
14 "failed_at": 0,
15 "last_error": "",
16 "step_detail": {
17 "type": "message_creation",
18 "message_creation": {
19 "message_id": "chatmsg_979c8bfa026d4894a2c1f4adbdf1975c"
20 }
21 }
22}