全部产品
Search
文档中心

表格存储:短期记忆

更新时间:Oct 21, 2026

管理记忆库中的短期消息(原始会话消息),短期消息通过结构记忆(AddMemories)产生,本页只涉及查询。

前提条件

  • 已创建输入类型为 messages 的记忆库。参见记忆库管理。

  • 已安装Agent Storage SDK:Python ≥ 1.0.10,TypeScript ≥ 0.0.13

列出短期消息

分页查询指定 Scope 下的原始会话消息记录。

  • scope 必须完整四级且不支持通配符,否则查询不到对应会话。

  • 记忆库存在但该 Scope 无消息时返回 200 和空 messages 列表,不代表出错。

  • 可选 minTimestamp/maxTimestamp(RFC3339)按时间范围过滤,limit 控制每页数量,nextToken 翻页。

控制台

  1. 登录Agent Storage控制台,打开目标记忆库,进入短期记忆页。

  2. 选择具体的应用、租户、智能体,再通过右上角会话选择器选择会话。

  3. 列表展示该会话的原始对话消息(角色、内容、时间)。

SDK

Python

from tablestore_agent_storage import AgentStorageClient

client = AgentStorageClient(
    api_key="<your-api-key>",
    ots_endpoint="https://<instance>.<region>.ots.aliyuncs.com",
    ots_instance_name="<instance-name>",
)

resp = client.list_memory_store_messages({
    "memoryStoreName": "agent_memory",
    "scope": {
        "appId": "app-001",
        "tenantId": "user-001",
        "agentId": "assistant",
        "runId": "session-001",
    },
    "limit": 50,
})

session = resp.get("session", resp)
for msg in session.get("messages", []):
    print(f"[{msg['role']}] {msg['content']}")

TypeScript

import { AgentStorageClient } from '@tablestore/agent-storage';

const client = new AgentStorageClient({
  apiKey: '<your-api-key>',
  endpoint: 'https://<instance>.<region>.ots.aliyuncs.com',
  instanceName: '<instance-name>',
});

const resp = await client.listMemoryStoreMessages({
  memoryStoreName: 'agent_memory',
  scope: {
    appId: 'app-001',
    tenantId: 'user-001',
    agentId: 'assistant',
    runId: 'session-001',
  },
  limit: 50,
});

const session = resp.session ?? resp;
for (const msg of session.messages) {
  console.log(`[${msg.role}] ${msg.content}`);
}

API

调用 ListMemoryStoreMessages 列出短期消息。完整字段参见列出短期消息。

相关文档