使用 ListItemVersions 接口按 Scope 倒序列出文件的历史版本,支持按文件、会话、时间范围和操作类型过滤。
前提条件
-
已创建 AgentStorage 实例且状态为
normal,并获取实例访问地址(endpoint)和实例名。 -
已创建 API Key。
-
版本查询使用精确 Scope,
scope的四级字段(appId、tenantId、agentId、runId)全部必填,不支持通配符*。范围版本删除清理后轮询时使用通配 Scope,参见 DeleteItemVersions。 -
读取版本内容时设置
view=full。
请求参数
|
字段 |
类型 |
必填 |
说明 |
|
|
string |
否 |
只列出一个文件的版本 |
|
|
string |
否 |
按调用会话过滤 |
|
|
string |
否 |
RFC3339 时间范围 |
|
|
string |
否 |
|
|
|
string |
否 |
|
|
|
int |
否 |
默认 20,最大 100; |
|
|
string |
否 |
分页令牌 |
请求示例
使用 API Key 认证时,通过 x-ots-instancename 和 x-ots-apikey 请求头传入实例名和 API Key。
curl -X POST https://<endpoint>/ListItemVersions \
-H "x-ots-instancename: <instance-name>" \
-H "x-ots-apikey: <your-api-key>" \
-H "Content-Type: application/json" \
-d '{
"type": "memoryfile",
"memoryStoreName": "agent_files",
"scope": {
"appId": "app-001",
"tenantId": "user-001",
"agentId": "assistant",
"runId": "session-001"
},
"itemId": "mem_01K...",
"limit": 20
}'
响应
版本响应包含自包含的 versionId、所属 itemId、操作类型、Scope、时间和操作者信息。
{
"type": "memoryfile",
"versions": [
{
"versionId": "<version-id>",
"itemId": "mem_01M2Z...",
"scope": { "appId": "app-001", "tenantId": "user-001", "agentId": "assistant", "runId": "run-001" },
"operation": "modified",
"path": "/profile/preferences.md",
"contentSha256": "b43e966f...",
"contentSizeBytes": 31,
"createdAt": "2026-09-20T09:03:24Z"
}
],
"nextToken": "<next-token>"
}
该文章对您有帮助吗?