资讯 文档
技术能力
语音技术
文字识别
人脸与人体
图像技术
语言与知识
视频技术

Run

本文档描述 Assistants API 中与 Run 相关的接口。

1. 运行

功能介绍

一个 Assistant 的一次具体运行,区分初次对话和继续对话两种情况

请求说明

基本信息

请求地址:https://appbuilder.baidu.com/v2/threads/runs

请求方式:POST

请求参数

请参考 公共类型定义中,公共请求头的定义

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 对象

请求与响应示例

流式首次请求示例

curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs' \
-H "Authorization: Bearer $APPBUILDER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
    "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"
                    ]
                }
            }
        }
    ],
    "instructions": "自由发挥",
    "thread": {
        "messages": [
            {
                "role": "user",
                "content": "北京的天气咋样呢?"
            }
        ]
    }
}'

流式首次请求响应示例

event:ping

event:status

data:{"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"}}}

event:status

data:{"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}}}

event:status

data:{"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事件时,请调用提交工具输出接口进行工具结果提交

流式提交完毕工具输出后继续输出

event:status

data:{"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%\"}"}}]}}

event:status

data:{"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}}}

event:status

data:{"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}}}

event:status

data:{"status":"in_progress","send_id":7,"message":"message created","event_type":"message_creation","details":{"type":"message_creation","message_creation":{"message_id":"chatmsg_979c8bfa026d4894a2c1f4adbdf1975c"}}}

event:message

data:{"status":"completed","send_id":8,"message_id":"chatmsg_979c8bfa026d4894a2c1f4adbdf1975c","content":[{"type":"text","text":{"value":"根据查询,今天北京的天气情况如下:\n\n温度:30摄氏度\n湿度:30%\n\n如果您需要更详细的天气信息,比如风向、风速、气压等,请告诉我,我会尽力为您提供。"}}]}

event:status

data:{"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}}}

event:status

data:{"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"}}}

非流式首次调用请求示例

curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs' \
-H "Authorization: Bearer $APPBUILDER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "assistant_id": "asst_551b2d29d5604711a40a1a0411f916e5",
    "stream": false,
    "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"
                    ]
                }
            }
        }
    ],
    "thread": {
        "messages": [
            {
                "role": "user",
                "content": "北京的天气咋样呢?"
            }
        ]
    }
}'

非流式响应示例(等待外部工具输出)

{
    "id": "run_9cedcbf2cf8c4b12b9a6f946a897c9af",
    "object": "run.result",
    "status": "requires_action",
    "log_id": "0862fcf1-bade-4212-932f-d9e9638915fa",
    "created_at": 1713065647614,
    "assistant_id": "asst_551b2d29d5604711a40a1a0411f916e5",
    "thread_id": "thread_1bc2ee388abf4984b59dfda53e2d6878",
    "started_at": 1713065647682,
    "expired_at": 0,
    "cancelled_at": 0,
    "failed_at": 0,
    "completed_at": 0,
    "required_action": {
        "type": "submit_tool_outputs",
        "submit_tool_outputs": {
            "tool_calls": [
                {
                    "id": "call-thread_1bc2ee388abf4984b59dfda53e2d6878-run_9cedcbf2cf8c4b12b9a6f946a897c9af-step-1",
                    "type": "function",
                    "function": {
                        "name": "get_cur_whether",
                        "arguments": "{\"location\":\"北京\"}"
                    }
                }
            ]
        }
    },
    "final_answer": null,
    "last_error": null
}

非流式提交外部工具输出请求示例

curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs' \
-H "Authorization: Bearer $APPBUILDER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "assistant_id": "asst_551b2d29d5604711a40a1a0411f916e5",
    "thread_id": "thread_53542434d56a49a580431ada3a7c778f",
    "stream": false,
    "tool_output": {
        "run_id": "run_acc62d1a5a1942aeb940ac531e475de2",
        "tool_call_id": "call-thread_53542434d56a49a580431ada3a7c778f-run_acc62d1a5a1942aeb940ac531e475de2-step-1",
        "output": "{\"temperature\": 30, \"humidity\": \"30%\"}"
    }
}'

非流式提交完毕工具输出后继续输出响应示例

{
    "id": "run_acc62d1a5a1942aeb940ac531e475de2",
    "object": "run.result",
    "status": "completed",
    "log_id": "c54f7410-c769-458c-ac94-0b923a8b208d",
    "created_at": 1713072771076,
    "assistant_id": "asst_551b2d29d5604711a40a1a0411f916e5",
    "thread_id": "thread_53542434d56a49a580431ada3a7c778f",
    "started_at": 1713072946394,
    "expired_at": 0,
    "cancelled_at": 0,
    "failed_at": 0,
    "completed_at": 1713072952421,
    "required_action": null,
    "final_answer": {
        "type": "message",
        "message": {
            "content": {
                "type": "text",
                "text": {
                    "value": "根据查询,今天北京的天气情况如下:温度约为30度,湿度为30%。希望这些信息能对您有所帮助。如果您还有其他问题或需要更多信息,请随时告诉我。"
                }
            },
            "message_id": "chatmsg_669409fc23b844a3ba2b1cbee416f6ff"
        }
    },
    "last_error": null
}

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对象

请求示例

curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/submit_tool_outputs' \
-H "Authorization: Bearer $APPBUILDER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
    "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
    "tool_outputs": [
        {"tool_call_id": "call-thread_6c8da8556fcc4bcb95d2c15dc81b2654-run_8c7a6c1da9ea46148a86735c697d1cb9-step-1", "output": "{\"temperature\": 30, \"humidity\": \"30%\"}"}
    ]
}'

响应说明

响应参数

Header

请参考 公共类型定义中,公共响应头的定义

Body

请参考 公共类型定义 中的 RunObject 对象

响应示例

{
    "id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
    "object": "thread.run",
    "status": "in_progress",
    "instructions": "",
    "tools": [],
    "created_at": 1712689299768,
    "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
    "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
    "required_action": null,
    "started_at": 0,
    "expires_at": 0,
    "expired_at": 0,
    "cancelled_at": 0,
    "failed_at": 0,
    "completed_at": 0,
    "last_error": null,
    "file_ids": null
}

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字段。

请求示例

curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/cancel' \
-H "Authorization: Bearer $APPBUILDER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
    "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9"
}'

响应说明

响应参数

Header

请参考 公共类型定义中,公共响应头的定义

Body

请参考 公共类型定义 中的 RunObject 对象

响应示例

{
    "id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
    "object": "thread.run",
    "status": "completed",
    "instructions": "",
    "tools": [],
    "created_at": 1712689299768,
    "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
    "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
    "required_action": null,
    "started_at": 0,
    "expires_at": 0,
    "expired_at": 0,
    "cancelled_at": 0,
    "failed_at": 0,
    "completed_at": 1712689373969,
    "last_error": null,
    "file_ids": null
}

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之前开始列出

请求示例

curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/list' \
-H "Authorization: Bearer $APPBUILDER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654"
}'

响应说明

响应参数

Header

请参考 公共类型定义中,公共响应头的定义

Body
参数名称 类型 描述
object string 固定为list
first_id string 起始run Id
last_id string 结束run Id
has_more bool 是否还有更多
data array[RunObject] run信息列表

响应示例

{
    "object": "list",
    "data": [
        {
            "id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
            "object": "thread.run",
            "status": "completed",
            "instructions": "",
            "tools": null,
            "metadata": null,
            "usage": null,
            "created_at": 1712689299768,
            "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
            "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
            "required_action": {
                "type": "submit_tool_outputs",
                "submit_tool_outputs": {
                    "tool_calls": [
                        {
                            "id": "call-thread_6c8da8556fcc4bcb95d2c15dc81b2654-run_8c7a6c1da9ea46148a86735c697d1cb9-step-1",
                            "type": "function",
                            "function": {
                                "name": "get_cur_whether",
                                "arguments": "{\"location\":\"北京市\"}"
                            }
                        }
                    ]
                }
            },
            "started_at": 0,
            "expires_at": 0,
            "expired_at": 0,
            "cancelled_at": 0,
            "failed_at": 0,
            "completed_at": 1712689373969,
            "last_error": null,
            "file_ids": null
        }
    ],
    "first_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
    "last_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
    "has_more": false
}

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

请求示例

curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/query' \
-H "Authorization: Bearer $APPBUILDER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
    "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9"
}'

响应说明

响应参数

Header

请参考 公共类型定义中,公共响应头的定义

Body

请参考 公共类型定义 中的 RunObject 对象

响应示例

{
    "id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
    "object": "thread.run",
    "status": "completed",
    "instructions": "",
    "tools": [],
    "metadata": null,
    "usage": null,
    "created_at": 1712689299768,
    "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
    "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
    "required_action": {
        "type": "submit_tool_outputs",
        "submit_tool_outputs": {
            "tool_calls": [
                {
                    "id": "call-thread_6c8da8556fcc4bcb95d2c15dc81b2654-run_8c7a6c1da9ea46148a86735c697d1cb9-step-1",
                    "type": "function",
                    "function": {
                        "name": "get_cur_whether",
                        "arguments": "{\"location\":\"北京市\"}"
                    }
                }
            ]
        }
    },
    "started_at": 0,
    "expires_at": 0,
    "expired_at": 0,
    "cancelled_at": 0,
    "failed_at": 0,
    "completed_at": 1712689373969,
    "last_error": null,
    "file_ids": null
}

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之前开始列出

请求示例

curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/steps/list' \
-H "Authorization: Bearer $APPBUILDER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
    "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9"
}'

响应说明

响应参数

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信息列表

响应示例

{
    "object": "list",
    "data": [
        {
            "id": "step-2",
            "object": "thread.run.step",
            "type": null,
            "status": "completed",
            "usage": null,
            "created_at": 1712689373981,
            "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
            "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
            "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
            "cancelled_at": 0,
            "completed_at": 1712689373969,
            "expired_at": 0,
            "failed_at": 0,
            "last_error": "",
            "step_detail": {
                "type": "message_creation",
                "message_creation": {
                    "message_id": "chatmsg_979c8bfa026d4894a2c1f4adbdf1975c"
                }
            }
        },
        {
            "id": "step-1",
            "object": "thread.run.step",
            "type": null,
            "status": "completed",
            "usage": null,
            "created_at": 1712689303754,
            "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
            "assistant_id": "asst_0a1d030f277f4ad2abe0297959f219e8",
            "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
            "cancelled_at": 0,
            "completed_at": 1712689367912,
            "expired_at": 0,
            "failed_at": 0,
            "last_error": "",
            "step_detail": {
                "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%\"}"
                        }
                    }
                ]
            }
        }
    ],
    "first_id": "step-2",
    "last_id": "step-1",
    "has_more": false
}

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

请求示例

curl -X POST 'https://appbuilder.baidu.com/v2/threads/runs/steps/query' \
-H "Authorization: Bearer $APPBUILDER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
    "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
    "step_id": "step-2"
}'

响应说明

响应参数

Header

请参考 公共类型定义中,公共响应头的定义

Body

请参考 公共类型定义中,RunStepObject的定义

响应示例

{
    "id": "step-2",
    "object": "thread.run.step",
    "type": null,
    "status": "completed",
    "usage": null,
    "created_at": 1712689373981,
    "run_id": "run_8c7a6c1da9ea46148a86735c697d1cb9",
    "assistant_id": null,
    "thread_id": "thread_6c8da8556fcc4bcb95d2c15dc81b2654",
    "cancelled_at": 0,
    "completed_at": 1712689373969,
    "expired_at": 0,
    "failed_at": 0,
    "last_error": "",
    "step_detail": {
        "type": "message_creation",
        "message_creation": {
            "message_id": "chatmsg_979c8bfa026d4894a2c1f4adbdf1975c"
        }
    }
}