Skip to content

消息管理

分页查询指定会话的对话历史消息,按时间正序返回每一轮问答及其执行明细(思考、工具调用、工作流节点、回复内容等)。Agent、AgentLite 和 ChatFlow 类型应用支持(TextCompletion 无对话上下文)。

  • 接口路径:POST /v1/openapi/chat/history

INFO

Agent、AgentLite 与 ChatFlow 共用同一接口路径,由 app_id 对应应用的类型分发。

请求头

参数名必填说明
Content-Typeapplication/json
Authorization鉴权凭证,格式 Bearer sk_xxx

请求参数

json
{
    "app_id": "",            // 必填-应用ID
    "conversation_id": "",   // 必填-会话ID
    "page": 1,               // 页码,缺省 1
    "page_size": 10          // 每页条数,缺省 10
}
参数名类型必填说明
app_idstring(uuid)应用 ID
conversation_idstring(uuid)会话 ID
pageint页码,缺省 1
page_sizeint每页条数,缺省 10

返回数据

json
{
    "code": 200,
    "message": "success",
    "data": [
        {
            "id": "01965de1-1920-7fe4-aa38-2e6836c46f22",   // 消息ID
            "query": "帮我分析这张报表",                        // 用户提问
            "files": [                                       // 用户上传的多模态附件
                {"type": "image", "url": "https://example.com/a.png"}
            ],
            "content": "根据报表数据,...",                    // AI 最终回复内容
            "thinking": "让我先看一下数据结构...",              // 深度思考内容(如有)
            "input": {"tone": "正式"},                        // 本轮变量参数
            "status": 1,                                     // 消息状态
            "total_tokens": 168,                             // 总 tokens
            "duration": 1500,                                // 总耗时(毫秒)
            "tool_calls": [                                  // 工具调用汇总(如有)
                {
                    "tool_call_id": "",
                    "tool_name": "web_search",
                    "tool_arguments": "{\"query\":\"报表\"}",
                    "tool_result": "搜索结果",
                    "status": 1,
                    "duration": 120
                }
            ],
            "items": [                                       // 消息明细条目(按 sort_order 排序)
                {
                    "item_type": 3,
                    "sort_order": 0,
                    "is_sub_agent": false,
                    "content": {"text": "根据报表数据,..."}
                }
            ],
            "created_at": "2025-04-22 22:22:34",             // 创建时间
            "is_favorited": false                            // 是否已收藏
        }
    ]
}

TIP

返回的 data 为消息数组(不含分页 total 包裹),按时间正序排列;每个元素代表一轮完整问答。

消息项字段

字段类型说明
idstring(uuid)消息 ID
querystring用户提问内容
filesarray用户上传的多模态附件,每项含 type(目前仅 image)与 url,无附件时省略
contentstringAI 最终回复内容
thinkingstring深度思考内容,无则省略
inputobject本轮变量参数
statusuint8消息状态,见下表
total_tokensint本轮总 tokens
durationint64总耗时(毫秒)
tool_callsarray工具调用汇总列表,无则省略
itemsarray消息明细条目(思考 / 工具 / 回复分片等),按 sort_order 排序
created_atstring创建时间,YYYY-MM-DD HH:mm:ss
is_favoritedbool是否已收藏

消息状态(status):

说明
1成功
2失败
3取消
4中断(等待人工输入)

tool_calls 字段

字段类型说明
tool_call_idstring工具调用 ID
tool_namestring工具名称
tool_argumentsstring工具入参(JSON 字符串)
tool_resultstring工具执行结果
statusuint8状态:1-成功、2-失败
durationint64工具耗时(毫秒)

items 明细条目

items 还原一轮对话的完整执行过程,每个条目通过 item_type 区分类型。

字段类型说明
item_typeuint8条目类型,见下表
sort_orderint排序序号
is_sub_agentbool是否来自 Sub-Agent
agent_idstringSub-Agent 运行时的当前智能体 ID(如有)
parent_agent_idstring父智能体 ID(如有)
root_agent_idstring主智能体 ID(如有)
tool_call_idstring工具调用 ID(item_type=1 时)
tool_namestring工具名称(item_type=1 时)
tool_labelstring工具显示名称(item_type=1 时)
filesarray工具产生的工作空间文件(如有),每项含 namepath
statusuint8条目状态
errorstring错误信息(如有)
durationint64总耗时(毫秒)
llm_durationint64LLM 耗时(毫秒)
tool_durationint64工具耗时(毫秒)
contentobject条目内容(结构随类型而定)

条目类型(item_type):

说明
1工具调用
2思考消息
3助手回复分片
4错误消息
5取消

AI 应用开发平台 - 面向医疗场景的 AI 应用创新引擎