mem9:AI 智能体的持久化云端记忆 - Openclaw Skills

作者:互联网

2026-03-31

AI教程

什么是 mem9?

mem9 是一个高性能云端记忆层,旨在解决无状态 AI 智能体的遗忘问题。通过将此功能集成到您的 Openclaw Skills 库中,您可以确保事实、决策和用户上下文在不同会话之间永不丢失。它充当本地智能体环境与专用 REST API 之间的桥梁,将信息存储在由唯一 Space ID 标识的安全云端数据库中。

该插件利用混合搜索技术,结合向量嵌入与关键词匹配,提供高度相关的上下文注入。这使得智能体能够轻松召回以往对话或技术文档中的特定细节,将它们从瞬时工具转变为长期合作伙伴。

下载入口:https://github.com/openclaw/skills/tree/main/skills/c4pt0r/mem9-ai

安装与下载

1. ClawHub CLI

从源直接安装技能的最快方式。

npx clawhub@latest install mem9-ai

2. 手动安装

将技能文件夹复制到以下位置之一

全局模式 ~/.openclaw/skills/ 工作区 /skills/

优先级:工作区 > 本地 > 内置

3. 提示词安装

将此提示词复制到 OpenClaw 即可自动安装。

请帮我使用 Clawhub 安装 mem9-ai。如果尚未安装 Clawhub,请先安装(npm i -g clawhub)。

mem9 应用场景

  • 在多个独立的对话会话中保持用户偏好和项目上下文。
  • 使用单个 Space ID 在不同机器或环境之间同步智能体知识。
  • 构建外部知识库,使智能体可以通过语义混合搜索进行查询。
  • 自动捕获会话摘要和最终回复,以便进行长期审计和历史记录。
  • 将现有的本地记忆文件导入中心化云端仓库,以便更轻松地访问。
mem9 工作原理
  1. 智能体使用指向特定云端记忆空间的唯一 Space ID 初始化 mem9 插件。
  2. 在每次 LLM 调用期间,before_prompt_build 钩子会自动在云端数据库中搜索相关上下文并将其注入提示词中。
  3. 用户或智能体使用 memory_store 工具存储新信息,该工具通过 mem9 REST API 持久化数据。
  4. 会话转换由生命周期钩子管理,这些钩子在重置前总结进度并捕获最终智能体响应。
  5. 通过标准 CRUD 操作和高级过滤技术,根据需要检索、更新或删除数据。

mem9 配置指南

将 mem9 集成到您的 Openclaw Skills 环境中需要几个简单的配置步骤:

  1. 配置或识别 Space ID: 如果您没有 ID,请创建一个新 ID:
curl -sX POST https://api.mem9.ai/v1alpha1/mem9s | jq .
  1. 安装插件:
openclaw plugins install @mem9/mem9
  1. 配置 openclaw.json: 更新您的配置以启用 memory 插槽并设置 tenantID(将 $SPACE_ID 替换为您的实际 ID):
jq --arg sid "$SPACE_ID" '
  .plugins.slots.memory = "mem9" |
  .plugins.entries.mem9 = {
    enabled: true,
    config: { apiUrl: "https://api.mem9.ai", tenantID: $sid }
  } |
  .plugins.allow = ((.plugins.allow // []) + ["mem9"] | unique)
' openclaw.json > tmp.json && mv tmp.json openclaw.json

mem9 数据架构与分类体系

mem9 通过结构化的记忆对象组织数据,确保您的 Openclaw Skills 拥有高质量的检索元数据:

字段 类型 描述
content 字符串 存储的主要文本、事实或上下文。
tags 数组 用于分类过滤和组织的元数据标签。
source 字符串 标识生成该记忆的智能体或过程。
id UUID 用于执行更新或删除的唯一标识符。

系统还支持批量导入本地 JSON 文件,自动将现有历史记录映射到此云端模式中。

name: mem9
version: 1.0.1
description: |
  Persistent cloud memory for OpenClaw agents.

  Use when users say:
  - "install mem9"
  - "setup memory"
  - "add memory plugin"
  - "openclaw memory"
  - "mem9 onboarding"
  - "memory not working"
  - "import memories"
  - "upload sessions"

author: qiffang
keywords:
  - mem9
  - memory plugin
  - persistent memory
  - agent memory
  - install memory
  - setup memory
  - openclaw memory
  - cloud memory
metadata:
  openclaw:
    emoji: "??"
┌──────────────────────────────────────────────────────────────┐
│                                                              │
│   ███╗   ███╗███████╗███╗   ███╗ █████╗                      │
│   ████╗ ████║██╔════╝████╗ ████║██╔══██╗                     │
│   ██╔████╔██║█████╗  ██╔████╔██║╚██████║                     │
│   ██║╚██╔╝██║██╔══╝  ██║╚██╔╝██║ ╚═══██║                     │
│   ██║ ╚═╝ ██║███████╗██║ ╚═╝ ██║ █████╔╝                     │
│   ╚═╝     ╚═╝╚══════╝╚═╝     ╚═╝ ╚════╝                      │
│                                                              │
│   persistent memory for ai agents                            │
│                                                              │
└──────────────────────────────────────────────────────────────┘

mem9

Your agent forgets nothing. Stateless plugin → REST API → DB.

Persistent memory for AI agents.

The plugin connects to one cloud memory space, identified by a space ID.

When talking to end users:

  • Say "space ID", "memory space", or "cloud memory space"
  • Do not mention tenantID unless you are editing raw plugin config
  • Explain that the space ID tells mem9 which cloud memory space to connect to
  • Treat the space ID as something the user should save for reconnecting later

What You Get

Tool When
memory_store Persist facts, decisions, context
memory_search Hybrid vector + keyword search
memory_get Retrieve by ID
memory_update Modify existing memory
memory_delete Remove

Lifecycle hooks (automatic — no agent action needed):

Hook Trigger What happens
before_prompt_build Every LLM call Relevant memories injected as context
before_reset Before /reset Session summary saved
agent_end Agent finishes Last response captured

Onboarding

Terminology

Use this distinction consistently:

Internal term User-facing explanation
tenantID Internal plugin config field; do not surface this to users unless editing config
SPACE_ID env var A local variable holding the user's mem9 space ID
token Treat as the same value as the mem9 space ID unless the user clearly means something else
"recovery key" Avoid this term; say "space ID" instead

Short rule: space ID, tenantID, and token may refer to the same mem9 identifier. Prefer saying space ID to users, and use tenantID only in config examples.

If the user asks "What is this for?" answer plainly:

This ID tells mem9 which cloud memory space to use. OpenClaw stores and reads memories under this ID.

If the user asks "What is the relationship between tenantID and key?" answer plainly:

You only need the space ID. That is the value you save and reuse later to reconnect to the same cloud memory. tenantID is just the internal plugin config field name for that value.

Step 0 — Check for existing space

[AGENT] Ask the user before doing anything else:

Do you already have a mem9 space ID from a previous install or another machine?

If yes — ask the user to paste the ID, save it as SPACE_ID, then skip to Step 2.

SPACE_ID=""

When the user provides an existing ID, verify it is reachable before continuing:

curl -sf "https://api.mem9.ai/v1alpha1/mem9s/$SPACE_ID/memories?limit=1" r
  && echo "OK" || echo "UNREACHABLE"

If the check returns OK, say:

Connected to your existing cloud memory space. Continuing setup with your space ID.

If the check fails, say:

That ID did not respond. Double-check the value and try again, or create a new space instead.

If no — proceed to Step 1 to provision a new space.


Step 1 — Provision tenant

Skip this step if the user provided an existing space ID in Step 0.

[AGENT]

curl -sX POST https://api.mem9.ai/v1alpha1/mem9s | jq .

Response:

{
  "id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

Save id as SPACE_ID.

When explaining it to the user, say:

mem9 created a new cloud memory space for you. This ID is how this machine, or a future machine, reconnects to the same memory.

Step 2 — Install plugin

[AGENT]

openclaw plugins install @mem9/mem9

Step 3 — Detect OpenClaw version

[AGENT] Check the installed OpenClaw version before editing config:

openclaw --version

Routing rule:

  • If the reported version is >= 2.2.0, use the config path in Step 4A.
  • If the reported version is < 2.2.0, use the config path in Step 4B.
  • If the version command is unavailable or unclear, tell the user you could not determine the OpenClaw version and ask them which version they are using before editing openclaw.json.

Step 4 — Configure openclaw.json

OpenClaw ≥2.2.0

[AGENT] Patch existing config (merge-safe, preserves other keys):

jq --arg sid "$SPACE_ID" '
  .plugins.slots.memory = "mem9" |
  .plugins.entries.mem9 = {
    enabled: true,
    config: { apiUrl: "https://api.mem9.ai", tenantID: $sid }
  } |
  .plugins.allow = ((.plugins.allow // []) + ["mem9"] | unique)
' openclaw.json > tmp.json && mv tmp.json openclaw.json

Note: The allow array is additive—existing entries are preserved, mem9 is appended (deduplicated).

Or if no openclaw.json exists, create:

{
  "plugins": {
    "slots": { "memory": "mem9" },
    "entries": {
      "mem9": {
        "enabled": true,
        "config": {
          "apiUrl": "https://api.mem9.ai",
          "tenantID": ""
        }
      }
    },
    "allow": ["mem9"]
  }
}

OpenClaw <2.2.0

[AGENT] No allow array needed:

jq --arg sid "$SPACE_ID" '
  .plugins.slots.memory = "mem9" |
  .plugins.entries.mem9 = {
    enabled: true,
    config: { apiUrl: "https://api.mem9.ai", tenantID: $sid }
  }
' openclaw.json > tmp.json && mv tmp.json openclaw.json

Or if no openclaw.json exists, create:

{
  "plugins": {
    "slots": { "memory": "mem9" },
    "entries": {
      "mem9": {
        "enabled": true,
        "config": {
          "apiUrl": "https://api.mem9.ai",
          "tenantID": ""
        }
      }
    }
  }
}

If result returns stored memory → setup successful.

Step 5 — What's Next

[AGENT] Print the following to the user:

? mem9 installed!

?? NEXT RECOMMENDED STEP
   Import your existing local memories first, so your cloud memory starts with your real history.

   Say: "import memories to mem9"
   I will scan and upload supported local files automatically.
   Supported: memory.json, memories/*.json, sessions/*.json

?? YOUR MEM9 SPACE ID

   SPACE_ID: 

   This is not a display name. It is the ID that points OpenClaw to your cloud memory space.
   Save it somewhere safe so you can reconnect to the same cloud memory later.

?? RECOVERY

   New machine / re-install:
   1. Install mem9 plugin again
   2. Put this same ID back into Step 4 config
   3. Your cloud memories reconnect immediately

?? BACKUP PLAN

   Local backup:
   Keep your original local memory/session files before import.

   Offsite recovery:
   Save the ID in your password manager,
   team vault, or another secure offsite location.

Do not default to offering a synthetic write/read demo as the next step.

Preferred next-step order:

  1. Guide the user to import historical memories
  2. Explain the recovery path for a new machine or accidental local loss
  3. Explain local backup plus offsite backup
  4. Only offer a live write/read verification if the user explicitly asks for a test or if import/recovery is already clear

API Reference

Base: https://api.mem9.ai
Routes: /v1alpha1/mem9s/{tenantID}/...
Header: X-Mnemo-Agent-Id: (optional)

Method Path Description
POST /v1alpha1/mem9s Provision tenant
GET /healthz Health check
POST /{tid}/memories Create memory
GET /{tid}/memories Search (?q=, ?tags=, ?source=, ?limit=)
GET /{tid}/memories/{id} Get by ID
PUT /{tid}/memories/{id} Update
DELETE /{tid}/memories/{id} Delete
POST /{tid}/imports Upload file (multipart)
GET /{tid}/imports List import tasks
GET /{tid}/imports/{id} Task status

Examples

export SPACE_ID="your-space-id"
export API="https://api.mem9.ai/v1alpha1/mem9s/$SPACE_ID"

Store:

curl -sX POST "$API/memories" -H "Content-Type: application/json" r
  -d '{"content":"Project uses PostgreSQL 15","tags":["tech"],"source":"agent-1"}'

Search:

curl -s "$API/memories?q=postgres&limit=5"
curl -s "$API/memories?tags=tech&source=agent-1"

Get/Update/Delete:

curl -s "$API/memories/{id}"
curl -sX PUT "$API/memories/{id}" -H "Content-Type: application/json" -d '{"content":"updated"}'
curl -sX DELETE "$API/memories/{id}"

Import files:

# Memory file
curl -sX POST "$API/imports" -F "file=@memory.json" -F "agent_id=agent-1" -F "file_type=memory"

# Session file
curl -sX POST "$API/imports" -F "file=@session.json" -F "agent_id=agent-1" -F "file_type=session" -F "session_id=ses-001"

# Check status
curl -s "$API/imports"

Communication Style

When presenting onboarding or recovery instructions:

  • Use plain product language, not backend vocabulary
  • Prefer "space ID" or "memory space ID"
  • Do not introduce extra credential terminology if the user only needs the memory space meaning
  • If the user sounds worried about recovery, lead with backup/import/reconnect steps instead of API demos

Suggested English wording:

This SPACE_ID is not a nickname.
It is the unique ID for your mem9 cloud memory space. Once OpenClaw is configured with it, it knows which cloud memory space to read from and write to.
Save this ID somewhere safe because you will use the same value later if you want to reconnect to this cloud memory on another machine.

The recommended next step is to upload your existing historical memories rather than run a demo test first.
I can scan local files such as memory.json, memories/*.json, and sessions/*.json and import them into mem9.

Recovery plan:
1. Local backup: keep the original memory/session files even after import
2. Offsite recovery: save the SPACE_ID in a password manager, team vault, or another secure offsite location
3. New machine recovery: reinstall the plugin and configure the same SPACE_ID in openclaw.json to reconnect to the same cloud memory

Default Import Behavior

When user says "import memories to mem9" without specifying files:

  1. Scan agent workspace for memory/session files
  2. Upload 15 most recent (by mtime)
  3. Upload in parallel for speed Paths to scan:
./memory.json         → file_type=memory
./memories.json       → file_type=memory
./memories/*.json     → file_type=memory
./sessions/*.json     → file_type=session (session_id = filename)
./session/*.json      → file_type=session (session_id = filename)

Troubleshooting

Symptom Fix
Plugin not loading Check slots.memory = "mem9" and entries.mem9.enabled = true
404 on API call Verify the saved space ID was written into the plugin config; run curl https://api.mem9.ai/healthz
Existing space ID unreachable Re-check the value for typos; confirm network access to api.mem9.ai; if ID is lost, provision a new space via Step 1

Next Steps

After first read, do this immediately:

  1. Import history first — Offer to scan and upload existing memory/session files before any demo.
  2. Explain recovery — Tell the user that reusing the same SPACE_ID reconnects the same cloud memory on a new machine.
  3. Explain backup — Recommend keeping original local files and saving the ID in a secure offsite location.
  4. Explorecurl -s "https://api.mem9.ai/v1alpha1/mem9s/$SPACE_ID/memories?limit=10" | jq .
  5. Verify only if useful — Offer a live memory_store / memory_search test only after import and recovery guidance are clear, or if the user explicitly asks for validation.

Update

Do not set up automatic daily self-updates for this skill.

Only update the local skill file when the user or maintainer explicitly asks for a refresh from a reviewed source.


????????????????????????????????????????????????????????????????
?  stateless agents · cloud memory · zero amnesia              ?
????????????????????????????????????????????????????????????????

相关推荐