agentmemory Integration for OpenClaw
Status: ✅ Verified working with OpenClaw v2026.5.4 Version: agentmemory v0.9.9 (iii-engine v0.11.6) MCP Tools: 107 REST + 51 MCP tools available
Persistent memory server giving OpenClaw agents 95.2% R@5 semantic recall across sessions via BM25+Vector+Graph RRF hybrid search.
Architecture
OpenClaw Agent ←→ Gateway (MCP) ←→ agentmemory MCP Server (localhost:3111)
↓
SQLite/KV Store
↓
Viewer (localhost:3113)
Quick Start (MCP Mode — 5 minutes)
Step 1: Install and start memory server
# Server runs on localhost:3111, viewer at localhost:3113
npx @agentmemory/agentmemory
Step 2: Configure OpenClaw MCP
Add to ~/.openclaw/openclaw.json under mcp.servers:
{
"mcp": {
"servers": {
"agentmemory": {
"command": "npx",
"args": ["-y", "@agentmemory/mcp"]
}
}
}
}
Step 3: Restart Gateway
openclaw gateway restart
Step 4: Verify
curl http://localhost:3111/agentmemory/health
# → {"status":"healthy","version":"0.9.9"}
# View memory dashboard
open http://localhost:3113
MCP Tools (Key ones for OpenClaw)
| Tool | Purpose |
|---|---|
memory_recall | Semantic search across all memories |
memory_save | Store new memories with type/tags |
memory_smart_search | Hybrid BM25+vector search |
memory_timeline | View memories chronologically |
memory_profile | Agent's memory usage stats |
memory_snapshot | Full memory export as JSON |
memory_forget | Delete specific memories |
memory_context | Get context for current session |
See references/mcp-tools.md for full list of 51 tools.
systemd Service (Production)
For auto-start and reliable background operation:
Install service
mkdir -p ~/.config/systemd/user
cp /home/lufei/.openclaw/workspace/skills/agentmemory/scripts/agentmemory.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable agentmemory
systemctl --user start agentmemory
# Enable linger (boot without login)
loginctl enable-linger $(whoami)
Service commands
systemctl --user status agentmemory # Check status
journalctl --user -u agentmemory -f # View logs
systemctl --user restart agentmemory # Restart
Integration with MEMORY.md
agentmemory and MEMORY.md serve different purposes — they coexist:
| Layer | System | Purpose | Management |
|---|---|---|---|
| Experience | agentmemory | Automatic capture, semantic recall, cross-agent | MCP |
| Knowledge | MEMORY.md | Curated decisions, preferences, rules | Manual |
Coordination rules
- Before major tasks: Call
memory_recallto retrieve relevant experiences - After important decisions: Call
memory_savewith result - Curated knowledge: Stays in MEMORY.md (survives compaction)
- Session start: Both systems loaded; no conflicts
Optional migration
If MEMORY.md has valuable content:
npx @agentmemory/agentmemory migrate --from-file ~/.openclaw/workspace/MEMORY.md
Verification
Run the verification script:
bash /home/lufei/.openclaw/workspace/skills/agentmemory/scripts/verify.sh
Expected output:
- ✅ Memory server on port 3111
- ✅ Health endpoint responding
- ✅ Viewer available on port 3113
- ✅ OpenClaw MCP configured
- ✅ systemd service active
Uninstall
MCP mode removal
- Remove from
openclaw.jsonmcp.servers section openclaw gateway restart
Full removal
systemctl --user stop agentmemory
systemctl --user disable agentmemory
rm ~/.config/systemd/user/agentmemory.service
pkill -f "agentmemory"
Troubleshooting
"Connection refused on port 3111"
Memory server not running. Start it:
systemctl --user start agentmemory
# Or manually: npx @agentmemory/agentmemory
"Config invalid" after editing openclaw.json
Ensure mcp.servers path (not mcpServers). Run:
openclaw status # Should show "Config valid"
View real-time logs
journalctl --user -u agentmemory -f --since "1 hour ago"
中文版 Chinese Version
agentmemory × OpenClaw 集成
状态: ✅ 已验证兼容 OpenClaw v2026.5.4 版本: agentmemory v0.9.9(引擎 iii v0.11.6) MCP 工具: 107 个 REST + 51 个 MCP 工具
持久化记忆服务,为 OpenClaw Agent 提供跨会话语义召回能力(R@5 95.2%),基于 BM25+向量+图谱混合搜索。
系统架构
OpenClaw Agent ←→ Gateway (MCP) ←→ agentmemory MCP 服务器 (localhost:3111)
↓
SQLite/KV 存储
↓
浏览器仪表板 (localhost:3113)
快速开始(MCP 模式 — 5 分钟)
第一步:启动记忆服务器
npx @agentmemory/agentmemory
# 服务器端口:3111(API)、3113(浏览器仪表板)
第二步:配置 OpenClaw MCP
在 ~/.openclaw/openclaw.json 中加入:
{
"mcp": {
"servers": {
"agentmemory": {
"command": "npx",
"args": ["-y", "@agentmemory/mcp"]
}
}
}
}
第三步:重启 Gateway
openclaw gateway restart
第四步:验证
curl http://localhost:3111/agentmemory/health
# → {"status":"healthy","version":"0.9.9"}
# 打开记忆仪表板
open http://localhost:3113
核心 MCP 工具
| 工具 | 用途 |
|---|---|
memory_recall | 跨所有记忆的语义搜索 |
memory_save | 以类型/标签存储新记忆 |
memory_smart_search | BM25+向量混合搜索 |
memory_timeline | 按时间线查看记忆 |
memory_profile | Agent 记忆使用统计 |
memory_snapshot | 完整记忆导出 JSON |
memory_forget | 删除指定记忆 |
memory_context | 获取当前会话上下文 |
完整 51 个工具列表见 references/mcp-tools.md。
systemd 服务(生产环境推荐)
安装服务:
mkdir -p ~/.config/systemd/user
cp /home/lufei/.openclaw/workspace/skills/agentmemory/scripts/agentmemory.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable agentmemory
systemctl --user start agentmemory
# 启用 linger(开机免登录自动启动)
loginctl enable-linger $(whoami)
常用命令:
systemctl --user status agentmemory # 查看状态
journalctl --user -u agentmemory -f # 实时日志
systemctl --user restart agentmemory # 重启
与 MEMORY.md 的协同
两个系统分工不同,共存互补:
| 层级 | 系统 | 用途 | 管理方式 |
|---|---|---|---|
| 经验层 | agentmemory | 自动捕获、语义召回、跨 Agent 共享 | MCP 自动 |
| 知识层 | MEMORY.md | 精心整理的决策、偏好、规则 | 手工维护 |
协调规则:
- 任务开始前 → 调用
memory_recall检索相关经验 - 重要决策后 → 调用
memory_save保存结果 - 精选知识 → 留在 MEMORY.md(不受会话压缩影响)
- 会话启动时 → 两个系统同时加载,无冲突
可选迁移:
npx @agentmemory/agentmemory migrate --from-file ~/.openclaw/workspace/MEMORY.md
验证
bash /home/lufei/.openclaw/workspace/skills/agentmemory/scripts/verify.sh
预期结果:
- ✅ 记忆服务器在 3111 端口运行
- ✅ Health 端点正常响应
- ✅ 仪表板在 3113 端口可访问
- ✅ OpenClaw MCP 已配置
- ✅ systemd 服务已激活
卸载
仅移除 MCP 模式:
- 从
openclaw.json的mcp.servers中删除 agentmemory 条目 - 执行
openclaw gateway restart
完全移除:
systemctl --user stop agentmemory
systemctl --user disable agentmemory
rm ~/.config/systemd/user/agentmemory.service
pkill -f "agentmemory"
故障排查
"Connection refused on port 3111" 服务器未启动,启动它:
systemctl --user start agentmemory
# 或手动:npx @agentmemory/agentmemory
修改 openclaw.json 后提示 "Config invalid"
确保路径是 mcp.servers(不是 mcpServers):
openclaw status # 应显示 "Config valid"
查看实时日志:
journalctl --user -u agentmemory -f --since "1 hour ago"
实际带来的好处
| 场景 | 没有 agentmemory | 有 agentmemory |
|---|---|---|
| 会话丢失上下文 | 每次重新解释背景 | 自动从历史记忆捞取 |
| 跨会话决策追溯 | 靠 MEMORY.md 手工记录 | memory_recall 语义搜索自动找 |
| 重复踩同一个坑 | 不同 session 反复犯错 | 学到的教训自动积累+衰减 |
| 新项目上手 | 要翻很久聊天记录 | 语义搜索项目背景即得 |
| 记忆体检索 | 关键词匹配漏检率高 | BM25+Vector+Graph RRF,R@5=95.2% |
| 自动化记忆捕捉 | 全靠手工写 MEMORY.md | MCP hooks 自动捕获 session 事件 |
🦞 Skill by 龙虾 — agentmemory-mcp on ClawHub: https://clawhub.ai/lufei4/agentmemory-mcp