🚀 MoltBrain - 為OpenClaw、MoltBook和Claude Code提供長期記憶層
MoltBrain是一款強大的長期記憶層工具,專為OpenClaw、MoltBook和Claude Code設計。它能夠自動學習並回憶你的項目上下文,為你提供更智能、更高效的使用體驗。
🚀 快速開始
快速安裝
╔══════════════════════════════════════════════════════════════════════╗
║ ║
║ Step 1 /plugin marketplace add nhevers/moltbrain ║
║ Step 2 /plugin install moltbrain ║
║ ║
╚══════════════════════════════════════════════════════════════════════╝
安裝完成後,MoltBrain將自動開始工作。
✨ 主要特性
| 特性分類 |
詳情 |
| 觀察功能(OBSERVATIONS) |
自動捕獲發現、決策和代碼信息 |
| 智能搜索(SMART SEARCH) |
通過MCP工具進行語義搜索,查找相關上下文 |
| 網頁查看器(WEB VIEWER) |
可在本地主機 :37777 瀏覽歷史記錄 |
| 分析功能(ANALYTICS) |
跟蹤令牌、會話和概念趨勢 |
| 標籤與過濾(TAGS & FILTERS) |
使用自定義標籤和智能過濾器進行組織 |
| 收藏夾(FAVORITES) |
為最重要的觀察結果添加書籤 |
| 導出功能(EXPORT) |
支持以JSON、CSV或Markdown格式導出,可使用自定義模板 |
| 主題設置(THEMES) |
提供黑暗和明亮模式,支持自定義主題 |
| 快捷鍵操作(SHORTCUTS) |
在網頁查看器中支持全鍵盤導航 |
🔧 技術細節
工作原理
╔═══════════════════════════════════╗
║ CLAUDE CODE SESSION ║
╚═══════════════╤═══════════════════╝
│
┌────────────────────┼────────────────────┐
│ │ │
▼ ▼ ▼
╔════════════════╗ ╔════════════════╗ ╔════════════════╗
║ SessionStart ║ ║ PostToolUse ║ ║ Stop ║
║────────────────║ ║────────────────║ ║────────────────║
║ Inject context ║ ║ Capture output ║ ║ Generate ║
║ from memory ║ ║ extract facts ║ ║ summary ║
╚═══════╤════════╝ ╚═══════╤════════╝ ╚═══════╤════════╝
│ │ │
└────────────────────┼────────────────────┘
│
╔══════════════╧══════════════╗
║ WORKER SERVICE ║
║ http://localhost:37777 ║
╚══════════════╤══════════════╝
│
┌─────────────────────────┼─────────────────────────┐
│ │ │
▼ ▼ ▼
╔════════════════╗ ╔════════════════╗ ╔════════════════╗
║ SQLite ║ ║ ChromaDB ║ ║ Web Viewer ║
║ Database ║ ║ Vector Search ║ ║ UI ║
║────────────────║ ║────────────────║ ║────────────────║
║ Observations ║ ║ Semantic ║ ║ Timeline ║
║ Summaries ║ ║ similarity ║ ║ Search ║
║ Sessions ║ ║ matching ║ ║ Analytics ║
╚════════════════╝ ╚════════════════╝ ╚════════════════╝
配置說明
設置信息存儲在 ~/.moltbrain/settings.json 中:
| 設置項 |
默認值 |
描述 |
| MOLTBRAIN_WORKER_PORT |
37777 |
工作服務端口 |
| MOLTBRAIN_CONTEXT_OBSERVATIONS |
50 |
最大注入觀察數 |
| MOLTBRAIN_PROVIDER |
claude |
用於摘要的AI提供商 |
| MOLTBRAIN_PRUNE_DAYS |
0 |
自動清理(0 = 禁用) |
| MOLTBRAIN_THEME |
system |
UI主題(dark/light/sys) |
| MOLTBRAIN_LOG_LEVEL |
info |
日誌詳細程度 |
💻 使用示例
CLI命令示例
moltbrain stats
moltbrain export
moltbrain tag <id> <t>
moltbrain prune
moltbrain search <q>
API使用示例
工作服務在 http://localhost:37777 上暴露了REST API:
curl http://localhost:37777/health
curl "http://localhost:37777/api/search?q=authentication"
curl "http://localhost:37777/api/timeline?project=my-app&days=7"
curl "http://localhost:37777/api/export?format=json" > backup.json
curl "http://localhost:37777/api/stats"
存儲Dapp使用示例
curl -X POST https://app.moltbrain.dev/api/x402/store \
-H "X-PAYMENT: <x402_header>" \
-d '{"data": {"key": "value"}, "label": "my_agent"}'
curl https://app.moltbrain.dev/api/x402/list/blobs \
-H "X-PAYMENT: <x402_header>"
curl https://app.moltbrain.dev/api/x402/catalog
Virtuals協議集成示例
npm install @moltbrain/game-plugin
import { GameAgent } from "@virtuals-protocol/game";
import { MoltBrainPlugin } from "@moltbrain/game-plugin";
const moltbrain = new MoltBrainPlugin({
privateKey: process.env.AGENT_PRIVATE_KEY!,
});
const agent = new GameAgent(process.env.GAME_API_KEY!, {
name: "My Agent",
goal: "Remember everything across sessions",
description: "An agent with persistent memory via MoltBrain",
workers: [moltbrain.getWorker()],
});
await agent.init();
await agent.step({ verbose: true });
OpenClaw集成示例
cd ~/.openclaw/extensions
git clone https://github.com/nhevers/moltbrain.git moltbrain
cd moltbrain/integrations/openclaw
npm install && npm run build
pnpm openclaw plugins enable moltbrain
npm run mcp:start
MoltBook集成示例
npm install --save @moltbrain/moltbook-mcp
{
"MOLTBRAIN_MOLTBOOK_ENABLED": true,
"MOLTBRAIN_MOLTBOOK_API_URL": "https://moltbook.com"
}
Claude Code集成示例
/plugin marketplace add nhevers/moltbrain
/plugin install moltbrain
📁 項目結構
moltbrain/
│
├── 📊 benchmarks/ 性能測試
├── 🎨 contrib/ 社區模式和主題
├── 📚 docs/ 文檔
├── 📖 examples/ 使用示例和指南
│
├── 🔌 extension/
│ ├── profiles/ 觀察模式
│ ├── runtime/ 工作腳本
│ ├── themes/ UI主題(黑暗/明亮)
│ ├── snippets/ 代碼片段
│ └── templates/ 摘要模板
│
├── 🌍 locales/ 國際化(en, es, fr)
├── 🗄️ migrations/ 數據庫遷移
├── 📋 schemas/ JSON驗證模式
├── 🛠️ scripts/ 構建和實用腳本
│
├── 💻 src/
│ ├── analytics/ 令牌和會話跟蹤
│ ├── cache/ 查詢和上下文緩存
│ ├── core/ 核心引擎
│ ├── export/ JSON/CSV/MD導出器
│ ├── favorites/ 書籤系統
│ ├── filters/ 日期/類型/項目過濾器
│ ├── formatters/ 輸出格式化器
│ ├── mcp/ 用於OpenClaw和MoltBook的MCP服務器
│ ├── shortcuts/ 鍵盤快捷鍵
│ ├── themes/ 主題系統
│ └── validators/ 輸入驗證
│
├── 🦞 integrations/
│ └── clawd/ Clawd擴展和技能
│
├── 📝 templates/ 導出模板
├── 🧪 tests/ 測試套件
└── 🔧 tools/ CLI實用工具
🗄️ 存儲Dapp
MoltBrain提供了一個基於Postgres的持久化存儲Dapp,可用於代理和應用程序。你可以訪問 app.moltbrain.dev/storage 使用該服務。
+-----------------------------------------------------------------------------+
| |
| BLOB存儲 通過SHA-256進行內容尋址的JSON Blob存儲 |
| ---------- 可通過哈希存儲和檢索數據,每次請求收費0.01美元。 |
| |
| 內存插槽 用於代理狀態的命名鍵值插槽 |
| ---------- 支持分配、寫入和讀取操作,會話間持久化。 |
| |
| 代理保險庫 基於錢包範圍的標籤徽章管理 |
| ---------- 連接代理使用的相同錢包,可瀏覽、查看和刪除存儲的數據。 |
| |
+-----------------------------------------------------------------------------+
所有端點都通過 x402 微支付(Base上的0.01 USDC)付費。數據按錢包範圍劃分,由Postgres支持,並且在重新部署後仍然保留。
🎮 Virtuals協議集成
MoltBrain提供了一個GAME SDK插件,可讓任何 Virtuals Protocol AI代理通過MoltBrain獲得持久化內存和存儲功能。
npm install @moltbrain/game-plugin
該插件提供了9個可用函數:moltbrain_chat、moltbrain_search、moltbrain_store、moltbrain_retrieve、moltbrain_allocate_slot、moltbrain_write_slot、moltbrain_read_slot、moltbrain_stats、moltbrain_capacity。
代理存儲的所有數據都將顯示在 app.moltbrain.dev/storage 的保險庫Dapp中。連接相同的錢包即可瀏覽這些數據。
完整的插件倉庫請查看 github.com/nhevers/Moltbrain-virtuals。
🦞 OpenClaw集成
MoltBrain可與 OpenClaw(超過116k顆星)集成,這是一款流行的個人AI助手。
+-----------------------------------------------------------------------------+
| |
| 擴展功能 添加到OpenClaw的extensions/文件夾中 |
| ---------- 支持完整的生命週期鉤子集成 |
| |
| 技能功能 作為OpenClaw技能安裝 |
| ---------- 提供recall_context、search_memories、save_memory工具 |
| |
| MCP服務器 基於協議的集成 |
| ---------- 可與任何MCP兼容的客戶端一起使用 |
| |
+-----------------------------------------------------------------------------+
快速設置
cd ~/.openclaw/extensions
git clone https://github.com/nhevers/moltbrain.git moltbrain
cd moltbrain/integrations/openclaw
npm install && npm run build
pnpm openclaw plugins enable moltbrain
npm run mcp:start
注意:如果作為捆綁擴展安裝(在OpenClaw的 extensions/ 目錄中),必須顯式啟用它:pnpm openclaw plugins enable moltbrain。
完整的設置指南請查看 integrations/openclaw/README.md。
📚 MoltBook集成
MoltBrain可與 MoltBook 集成,這是一個AI代理社交網絡。通過集成,你可以共享記憶、向其他代理學習並構建集體知識。
快速設置
npm install --save @moltbrain/moltbook-mcp
{
"MOLTBRAIN_MOLTBOOK_ENABLED": true,
"MOLTBRAIN_MOLTBOOK_API_URL": "https://moltbook.com"
}
完整的設置指南請查看 integrations/moltbook/README.md。
💻 Claude Code集成
MoltBrain可通過插件市場與Claude Code集成:
/plugin marketplace add nhevers/moltbrain
/plugin install moltbrain
📋 要求
╔══════════════════════════════════════╗
║ ║
║ • Node.js 18+ 或 Bun 1.0+ ║
║ • OpenClaw、MoltBook或Claude Code ║
║ ║
╚══════════════════════════════════════╝
📄 許可證
本項目採用AGPL-3.0許可證。