使用 ListMemoryStoreMessages 接口查询短期记忆,即原始会话消息。
前提条件
已创建 AgentStorage 实例且状态为
normal,并获取实例访问地址(endpoint)和实例名。已创建 API Key。
Scope 规则:查询短期记忆需提供完整 Scope,4 个字段(
appId、tenantId、agentId、runId)全部必填,不允许使用通配符*。
请求参数
字段 | 类型 | 必填 | 说明 |
| string | 是 | 记忆库名称。 |
| object | 是 | 完整 Scope,4 字段全部必填,不允许使用通配符 |
| int | 否 | 返回数量。 |
| string | 否 | 下一页标记。 |
| string | 否 | 最小时间,RFC3339 格式。 |
| string | 否 | 最大时间,RFC3339 格式。 |
请求示例
使用 API Key 认证时,通过 x-ots-instancename 和 x-ots-apikey 请求头传入实例名和 API Key。
curl -X POST https://<endpoint>/ListMemoryStoreMessages \
-H "x-ots-instancename: <instance-name>" \
-H "x-ots-apikey: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"memoryStoreName": "agent_memory",
"scope": {
"appId": "app-001",
"tenantId": "user-001",
"agentId": "assistant",
"runId": "session-001"
},
"limit": 100
}'响应
字段 | 说明 |
| 会话消息封装对象。 |
| 查询的 Scope。 |
| 消息列表。 |
| 消息 ID。 |
| 消息角色。 |
| 发言者标识。 |
| 消息内容。 |
| 消息时间,RFC3339 格式。 |
| 消息元数据。 |
{
"session": {
"scope": { "appId": "app-001", "tenantId": "user-001", "agentId": "assistant", "runId": "session-001" },
"messages": [
{
"messageId": "d0d9dd778a27e8cde773a243a5bab13c",
"role": "user",
"speaker": "user",
"content": "[10:00 AM on 13 May, 2026] 我以后出差都优先订靠窗座位",
"timestamp": "2026-05-13T10:00:00Z",
"metadata": { "channel": "chat", "source": "chat" }
}
]
}
}记忆库存在但该 Scope 暂无消息时,返回 200 与空的 messages 列表。