全部產品
Search
文件中心

Tablestore:CLI 使用介紹

更新時間:May 22, 2026

tablestore-agent-cli 提供記憶庫管理、記憶寫入、長期記憶檢索、短期記憶查詢、請求審計和 Dashboard 能力,適用於本地調試、營運管理和自動化指令碼。

安裝

通過 npm 全域安裝 CLI,要求 Node.js 18 或以上版本。

npm install -g @tablestore/tablestore-agent-cli
tablestore-agent-cli version

配置

CLI 首次使用前需配置訪問憑證、Table Store執行個體和記憶服務預設值。配置項寫入本地設定檔,環境變數優先順序高於設定檔。

配置訪問憑證

tablestore-agent-cli configure set access_key_id '...'
tablestore-agent-cli configure set access_key_secret '...'
tablestore-agent-cli configure set region 'cn-beijing'

配置Table Store執行個體

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_endpointots_instance_name 時,CLI 會在執行 doctor 或實際操作時自動建立並複用託管Table Store執行個體。

配置記憶服務預設值

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

環境變數優先順序高於設定檔,對應關係如下:

環境變數

配置項

TABLESTORE_ACCESS_KEY_ID

access_key_id

TABLESTORE_ACCESS_KEY_SECRET

access_key_secret

TABLESTORE_ENDPOINT

ots_endpoint

TABLESTORE_INSTANCE_NAME

ots_instance_name

TABLESTORE_REGION

region

TABLESTORE_MEMORY_STORE_NAME

memory_store_name

TABLESTORE_MEMORY_APP_ID

memory_app_id

TABLESTORE_MEMORY_TENANT_ID

memory_tenant_id

TABLESTORE_MEMORY_AGENT_ID

memory_agent_id

TABLESTORE_MEMORY_RUN_ID

memory_run_id

診斷

執行 doctor memory 檢查訪問憑證、Table Store執行個體配置和記憶服務連通性。任一檢查項失敗時命令返回非 0 退出碼。

tablestore-agent-cli doctor memory

記憶庫管理

記憶庫(Memory Store)是長期記憶和短期記憶的儲存單元,每個記憶庫對應Table 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>

lslist 的別名。該命令單頁返回,如需翻頁繼續讀取,請使用響應中的 nextToken

查看記憶庫

tablestore-agent-cli memory describe --store agent_memory
tablestore-agent-cli memory show --store agent_memory

showdescribe 的別名。

更新記憶庫

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 -y

rmdelete 的別名。TTY 環境下刪除會提示確認,傳入 -y 跳過確認。

寫入記憶

寫入記憶需指定完整 Scope,包含 app-idtenant-idagent-idrun-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-idagent-idrun-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-rerank

Rerank 預設啟用,傳入 --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 與得分 scoreunit 內部欄位使用 snake_case 命名,詳見 API 介面介紹

管理長期記憶

針對單條長期記憶單元的查詢、更新與刪除操作。memory-idmemory add 響應或 list-units 命令返回。擷取、更新、刪除單條記憶時必須傳入與寫入時一致的完整 Scope(app-idtenant-idagent-idrun-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-unitslist-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-001

catget 的別名。

更新單條記憶

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-001

rm-unitdelete-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-idtenant-idagent-idrun-id)全部填寫,不允許使用萬用字元 *ls-msgsmsg-list 的別名。

查詢請求審計

--operation 過濾指定操作類型的請求審計記錄,Scope 中 tenant-idagent-idrun-id 支援反引號包裹的萬用字元 *

tablestore-agent-cli memory req-list \
  --store agent_memory \
  --app-id app-001 \
  --tenant-id '*' \
  --agent-id '*' \
  --run-id '*' \
  --operation AddMemories

ls-reqsreq-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.0

Dashboard 預設監聽 127.0.0.1:3000,瀏覽器開啟該地址即可訪問。-p 自訂連接埠;--host 0.0.0.0 允許從其他機器訪問。