tablestore-agent-cli 提供记忆库管理、记忆写入、长期记忆检索、短期记忆查询、请求审计和 Dashboard 能力,适用于本地调试、运维管理和自动化脚本。
安装
通过 npm 全局安装 CLI,要求 Node.js 18 或以上版本。
npm install -g @tablestore/tablestore-agent-cli
tablestore-agent-cli version配置
CLI 首次使用前需配置访问凭证、表格存储实例和记忆服务默认值。配置项写入本地配置文件,环境变量优先级高于配置文件。
配置访问凭证
tablestore-agent-cli configure set access_key_id '...'
tablestore-agent-cli configure set access_key_secret '...'
tablestore-agent-cli configure set region 'cn-beijing'配置表格存储实例
tablestore-agent-cli configure set ots_endpoint 'https://<instance>.cn-beijing.ots.aliyuncs.com'
tablestore-agent-cli configure set ots_instance_name '<instance-name>'未配置 ots_endpoint 与 ots_instance_name 时,CLI 会在执行 doctor 或实际操作时自动创建并复用托管表格存储实例。
配置记忆服务默认值
tablestore-agent-cli configure set memory_store_name 'agent_memory'
tablestore-agent-cli configure set memory_app_id 'app-001'
tablestore-agent-cli configure set memory_tenant_id 'tenant-001'
tablestore-agent-cli configure set memory_agent_id 'agent-001'
tablestore-agent-cli configure set memory_run_id 'run-001'配置默认值后,后续命令可省略对应参数。
配置文件与环境变量
配置文件路径:
~/.config/tablestore-agent-cli/config.toml环境变量优先级高于配置文件,对应关系如下:
环境变量 | 配置项 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
诊断
执行 doctor memory 检查访问凭证、表格存储实例配置和记忆服务连通性。任一检查项失败时命令返回非 0 退出码。
tablestore-agent-cli doctor memory记忆库管理
记忆库(Memory Store)是长期记忆和短期记忆的存储单元,每个记忆库对应表格存储实例上的一组数据表与索引。
创建记忆库
tablestore-agent-cli memory create --store agent_memory --description "Agent 长期记忆库"记忆库创建后会异步初始化二级索引,需等待约 1 分钟索引就绪后才能正常写入和检索。
列出记忆库
tablestore-agent-cli memory list
tablestore-agent-cli memory ls --limit 50 --next-token <token>ls 是 list 的别名。该命令单页返回,如需翻页继续读取,请使用响应中的 nextToken。
查看记忆库
tablestore-agent-cli memory describe --store agent_memory
tablestore-agent-cli memory show --store agent_memoryshow 是 describe 的别名。
更新记忆库
tablestore-agent-cli memory update --store agent_memory --description "新的描述"删除记忆库
tablestore-agent-cli memory delete --store agent_memory
tablestore-agent-cli memory rm --store agent_memory -yrm 是 delete 的别名。TTY 环境下删除会提示确认,传入 -y 跳过确认。
写入记忆
写入记忆需指定完整 Scope,包含 app-id、tenant-id、agent-id、run-id 四段。写入命令的 Scope 不允许使用通配符 *。
写入文本
通过 --text 直接传入预加工的文本:
tablestore-agent-cli memory add \
--store agent_memory \
--app-id app-001 \
--tenant-id user-001 \
--agent-id assistant \
--run-id session-001 \
--text "用户喜欢喝咖啡"同步写入
默认写入为异步模式,文本由服务端在后台抽取记忆。需要写入完成后立即可检索时使用 --sync:
tablestore-agent-cli memory add \
--store agent_memory \
--app-id app-001 \
--tenant-id user-001 \
--agent-id assistant \
--run-id session-001 \
--text "用户偏好简洁的回答风格" \
--sync通过消息文件写入
通过 --messages-file 传入对话消息列表,文件内容必须为 JSON 数组:
tablestore-agent-cli memory add \
--store agent_memory \
--app-id app-001 \
--tenant-id user-001 \
--agent-id assistant \
--run-id session-001 \
--messages-file ./messages.json附加元数据
通过 --metadata 传入 JSON 字符串,附加业务自定义字段:
tablestore-agent-cli memory add \
--store agent_memory \
--app-id app-001 \
--text "用户喜欢川菜" \
--metadata '{"source":"chat","topic":"preference"}'检索长期记忆
通过 memory search 进行语义检索。Scope 中 tenant-id、agent-id、run-id 支持反引号包裹的通配符 *,跨范围聚合命中。
tablestore-agent-cli memory search \
--store agent_memory \
--app-id app-001 \
--tenant-id user-001 \
--agent-id '*' \
--run-id '*' \
--query "用户喜欢什么食物" \
--top-k 5--top-k 默认值为 10,取值范围 1~50。
关闭 Rerank:
tablestore-agent-cli memory search \
--store agent_memory \
--app-id app-001 \
--tenant-id user-001 \
--query "用户偏好" \
--disable-rerankRerank 默认启用,传入 --disable-rerank 关闭重排,结果仅按向量距离排序。
使用 Metadata 精确匹配过滤:
tablestore-agent-cli memory search \
--store agent_memory \
--app-id app-001 \
--tenant-id user-001 \
--query "用户偏好" \
--metadata '{"source":"chat"}'响应 results 列表的每个元素包含命中的记忆单元 unit 与得分 score。unit 内部字段使用 snake_case 命名,详见 API 接口介绍。
管理长期记忆
针对单条长期记忆单元的查询、更新与删除操作。memory-id 由 memory add 响应或 list-units 命令返回。获取、更新、删除单条记忆时必须传入与写入时一致的完整 Scope(app-id、tenant-id、agent-id、run-id 四段全填,不允许使用通配符 *)。
列出记忆单元
tablestore-agent-cli memory list-units --store agent_memory --app-id app-001
tablestore-agent-cli memory ls-units --store agent_memory --app-id app-001 --limit 20 --next-token <token>ls-units 是 list-units 的别名。
获取单条记忆
tablestore-agent-cli memory get \
--store agent_memory \
--memory-id mem-001 \
--app-id app-001 \
--tenant-id user-001 \
--agent-id assistant \
--run-id session-001cat 是 get 的别名。
更新单条记忆
tablestore-agent-cli memory update-unit \
--store agent_memory \
--memory-id mem-001 \
--app-id app-001 \
--tenant-id user-001 \
--agent-id assistant \
--run-id session-001 \
--text "用户偏好咖啡,且喜欢简洁回答"删除单条记忆
tablestore-agent-cli memory delete-unit \
--store agent_memory \
--memory-id mem-001 \
--app-id app-001 \
--tenant-id user-001 \
--agent-id assistant \
--run-id session-001rm-unit 是 delete-unit 的别名。
查询短期记忆和审计
查询短期记忆
tablestore-agent-cli memory msg-list \
--store agent_memory \
--app-id app-001 \
--tenant-id user-001 \
--agent-id assistant \
--run-id session-001短期记忆查询要求 Scope 四级(app-id、tenant-id、agent-id、run-id)全部填写,不允许使用通配符 *。ls-msgs 是 msg-list 的别名。
查询请求审计
按 --operation 过滤指定操作类型的请求审计记录,Scope 中 tenant-id、agent-id、run-id 支持反引号包裹的通配符 *:
tablestore-agent-cli memory req-list \
--store agent_memory \
--app-id app-001 \
--tenant-id '*' \
--agent-id '*' \
--run-id '*' \
--operation AddMemoriesls-reqs 是 req-list 的别名。
面向脚本的输出
在脚本或 Agent 中调用 CLI 时,使用 -q(或 --quiet)只输出响应中的 data 字段,便于管道处理:
tablestore-agent-cli -q memory search \
--store agent_memory \
--app-id app-001 \
--tenant-id user-001 \
--query "用户喜欢什么饮品"Dashboard
CLI 内置 Web Dashboard,用于可视化管理与调试。
tablestore-agent-cli dashboard start
tablestore-agent-cli dashboard start -p 9999
tablestore-agent-cli dashboard start --host 0.0.0.0Dashboard 默认监听 127.0.0.1:3000,浏览器打开该地址即可访问。-p 自定义端口;--host 0.0.0.0 允许从其他机器访问。