通過 OpenClaw 和 Hermes 官方外掛程式接入記憶服務,對話前自動檢索相關長期記憶並注入上下文,對話結束後自動寫回。
OpenClaw 外掛程式
openclaw-tablestore-memory 是面向 OpenClaw 的記憶外掛程式,基於Table Store Node.js SDK 調用記憶服務。
安裝
openclaw plugins install @tablestore/openclaw-tablestore-memory配置
最小配置如下:
{
"plugins": {
"slots": {
"memory": "tablestore-mem"
},
"entries": {
"tablestore-mem": {
"enabled": true,
"config": {
"endpoint": "https://<instance>.cn-beijing.ots.aliyuncs.com",
"otsInstanceName": "<instance-name>",
"accessKeyId": "<AccessKey ID>",
"accessKeySecret": "<AccessKey Secret>"
}
}
}
}
}可選配置
參數 | 預設值 | 說明 |
|
| 應用標識。 |
| 從會話使用者資訊推導 | 租戶或使用者標識。 |
|
| 記憶庫名稱。 |
|
| 記憶庫不存在時自動建立。 |
|
| 是否在對話結束後寫回。 |
|
| 檢索返回數量。 |
|
| 是否啟用 Rerank。 |
Scope 映射
OpenClaw 外掛程式寫入時使用當前運行時身份:
{
"appId": "openclaw",
"tenantId": "<current-user>",
"agentId": "<runtime-agent>",
"runId": "<runtime-session>"
}檢索時使用租戶維度跨 Agent、跨會話範圍,agentId 和 runId 通配為 *:
{
"appId": "openclaw",
"tenantId": "<current-user>",
"agentId": "*",
"runId": "*"
}運行行為
在
before_prompt_build階段檢索相關長期記憶。將檢索到的記憶注入隱藏上下文,不直接寫入可見會話記錄。
在
agent_end階段收集本輪使用者和助手訊息。預設以非同步方式調用
AddMemories寫回記憶庫。
CLI 和 Slash 命令
OpenClaw 外掛程式提供調試命令:
openclaw tablestore-mem add "Alice likes jasmine tea" --uid alice
openclaw tablestore-mem search "what does Alice like" --uid alice在 OpenClaw 會話內可使用:
/tablestore-mem-add Alice likes jasmine tea
/tablestore-mem-search jasmine teaHermes 外掛程式
hermes-tablestore-memory 是面向 Hermes Agent 的外接記憶提供器,基於Table Store Python SDK 調用記憶服務。
安裝
hermes plugins install https://github.com/aliyun/hermes-tablestore-memory
hermes memory setup在 hermes memory setup 中選擇 tablestore-mem。
外掛程式依賴 tablestore>=6.4.5。如果 Hermes 使用的 Python 環境未安裝該依賴,需要將 SDK 安裝到 Hermes 實際使用的 Python 環境中。
配置密鑰
密鑰建議寫入 ~/.hermes/.env:
TABLESTORE_MEMORY_AK=<AccessKey ID>
TABLESTORE_MEMORY_SK=<AccessKey Secret>配置記憶服務
非敏感配置寫入 $HERMES_HOME/tablestore_memory.json:
{
"endpoint": "https://<instance>.cn-beijing.ots.aliyuncs.com",
"instance_name": "<instance-name>",
"memory_store_name": "hermes_mem",
"description": "",
"app_id": "hermes",
"tenant_id": "",
"enable_rerank": true,
"auto_create_store": true,
"timeout": 30
}預設值
參數 | 預設值 | 說明 |
|
| 記憶庫名稱。 |
|
| 應用標識。 |
| Null 字元串 | 為空白時從會話上下文或 |
|
| 是否啟用 Rerank。 |
|
| 記憶庫不存在時自動建立。 |
|
| 請求逾時時間,單位為秒。 |
Scope 映射
Hermes 外掛程式按以下規則填充 Scope 4 段:
欄位 | 來源 |
|
|
| 優先取 Hermes 會話 |
| Hermes 會話身份,預設 |
| 優先取 |
寫入時使用當前會話的精確 Scope;檢索時使用當前租戶下的跨 Agent、跨會話範圍,即 agentId=""、runId=""。
提供的工具
工具 | 說明 |
| 查看當前 Scope 下的記憶。 |
| 檢索長期記憶。 |
| 寫入一條長期記憶。 |
| 刪除一條長期記憶。 |
外掛程式還會在每輪對話完成後自動同步處理的使用者和助手訊息,並在下一輪對話前預取相關記憶。
Hermes CLI 命令
當 memory.provider 設定為 tablestore-mem 後,可使用:
hermes tablestore-mem add "使用者偏好簡潔回答"
hermes tablestore-mem add "使用者喜歡 Rust" --metadata source=manual --metadata topic=preferences
hermes tablestore-mem add "同步寫入這條記憶" --sync
hermes tablestore-mem search "簡潔回答"
hermes tablestore-mem search "Rust" --top-k 10接入建議
應用已使用 OpenClaw 或 Hermes,優先選擇對應官方外掛程式接入。
需要自訂記憶寫入策略、檢索策略或上下文拼接方式時,直接使用 SDK,詳見 Python SDK 使用介紹 或 Node.js SDK 使用介紹。
外掛程式預設在同一租戶下跨 Agent、跨會話檢索長期記憶,適合多數個人助理與業務助手情境。
業務需要嚴格按會話隔離檢索時,使用 SDK 自行指定完整 Scope,欄位語義參見 API 介面介紹。
雙側 Agent 共用記憶時,使用同一 Tablestore 執行個體,
appId、tenantId和memoryStoreName在雙側精確一致;agentId由各 Agent runtime 決定,檢索時通配為*。