NeuralMemory — Associative Memory for AI Agents
A biologically-inspired memory system that uses spreading activation instead of keyword/vector search. Memories form a neural graph where neurons connect via 20 typed synapses. Frequently co-accessed memories strengthen their connections (Hebbian learning). Stale memories decay naturally. Contradictions are auto-detected.
Why not just vector search? Vector search finds documents similar to your query. NeuralMemory finds conceptually related memories through graph traversal — even when there's no keyword or embedding overlap. "What decision did we make about auth?" activates time + entity + concept neurons simultaneously and finds the intersection.
Setup
1. Install NeuralMemory
CODEBLOCK0
The brain and config at ~/.neuralmemory/ are auto-created on first use.
2. Install the OpenClaw Plugin (Recommended)
The plugin occupies the exclusive memory slot — auto-injects context before each agent run and auto-captures memories after.
CODEBLOCK1
Add to ~/.openclaw/openclaw.json:
CODEBLOCK2
Plugin features:
- - 6 tools registered automatically (nmemremember, nmemrecall, nmemcontext, nmemtodo, nmemstats, nmemhealth)
- INLINECODE2 hook: injects tool instructions + relevant memories as context (persists across
/new) - INLINECODE4 hook: auto-extracts facts, decisions, and TODOs from the conversation
- Configurable:
contextDepth (0-3), maxContextTokens (100-10000)
After installing, build the plugin:
CODEBLOCK3
This compiles TypeScript to JavaScript in dist/. The plugin entry point is dist/index.js.
Windows Installation
On Windows, use forward slashes or escaped backslashes in openclaw.json paths:
CODEBLOCK4
To find the installed path:
CODEBLOCK5
If openclaw plugins list doesn't show the plugin:
- 1. Verify the path in
openclaw.json points to the package root (where package.json is) - Ensure
npm run build was run (the dist/ folder must exist with compiled .js files) - Use
python instead of python3 in the plugin config (Windows default)
Alternative: MCP Configuration (Manual)
If you prefer MCP over the plugin, add to ~/.openclaw/mcp.json:
CODEBLOCK6
On Windows, use "python" (not "python3"). This gives you all 56 MCP tools but without the auto-context/auto-capture hooks.
3. Verify
CODEBLOCK7
You should see brain statistics (neurons, synapses, fibers).
Troubleshooting
| Symptom | Cause | Fix |
|---|
| INLINECODE21 doesn't show plugin | Plugin path wrong or not built | Run npm run build, verify path in INLINECODE23 |
Agent runs nmem remember in terminal |
Agent confused CLI vs tool | Plugin now auto-injects tool instructions via
systemPrompt |
| Agent forgets tools after
/new | No tool instructions in new session | Plugin now injects
systemPrompt on every
before_agent_start |
|
python3 not found (Windows) | Windows uses
python not
python3 | Set
pythonPath: "python" in plugin config |
| Timeout errors | Slow machine or large brain | Increase
timeout in plugin config (max 120000ms) |
Tools Reference
Core Memory Tools
| Tool | Purpose | When to Use |
|---|
| INLINECODE34 | Store a memory | After decisions, errors, facts, insights, user preferences |
| INLINECODE35 |
Query memories | Before tasks, when user references past context, "do you remember..." |
|
nmem_context | Get recent memories | At session start, inject fresh context |
|
nmem_todo | Quick TODO with 30-day expiry | Task tracking |
Intelligence Tools
| Tool | Purpose | When to Use |
|---|
| INLINECODE38 | Auto-extract memories from text | After important conversations — captures decisions, errors, TODOs automatically |
| INLINECODE39 (depth=3) |
Deep associative recall | Complex questions requiring cross-domain connections |
|
nmem_habits | Workflow pattern suggestions | When user repeats similar action sequences |
Management Tools
| Tool | Purpose | When to Use |
|---|
| INLINECODE41 | Brain health diagnostics | Periodic checkup, before sharing brain |
| INLINECODE42 |
Brain statistics | Quick overview of memory counts |
|
nmem_version | Brain snapshots and rollback | Before risky operations, version checkpoints |
|
nmem_transplant | Transfer memories between brains | Cross-project knowledge sharing |
Workflow
At Session Start
- 1. Call
nmem_context to inject recent memories into your awareness - If user mentions a specific topic, call
nmem_recall with that topic
During Conversation
- 3. When a decision is made:
nmem_remember with type="decision" - When an error occurs:
nmem_remember with type="error" - When user states a preference:
nmem_remember with type="preference" - When asked about past events:
nmem_recall with appropriate depth
At Session End
- 7. Call
nmem_auto with action="process" on important conversation segments - This auto-extracts facts, decisions, errors, and TODOs
Examples
Remember a decision
CODEBLOCK8
Recall with spreading activation
nmem_recall(
query="database configuration for production",
depth=1,
max_tokens=500
)
Returns memories found via graph traversal, not keyword matching. Related memories (e.g., "deploy uses Docker with pg_dump backups") surface even without shared keywords.
Trace causal chains
nmem_recall(
query="why did the deployment fail last week?",
depth=2
)
Follows CAUSED
BY and LEADSTO synapses to trace cause-and-effect chains.
Auto-capture from conversation
nmem_auto(
action="process",
text="We decided to switch from REST to GraphQL because the frontend needs flexible queries. The migration will take 2 sprints. TODO: update API docs."
)
Automatically extracts: 1 decision, 1 fact, 1 TODO.
Key Features
- - Zero LLM dependency — Pure algorithmic: regex, graph traversal, Hebbian learning
- Spreading activation — Associative recall through neural graph, not keyword/vector search
- 20 synapse types — Temporal (BEFORE/AFTER), causal (CAUSEDBY/LEADSTO), semantic (ISA/HASPROPERTY), emotional (FELT/EVOKES), conflict (CONTRADICTS)
- Memory lifecycle — Short-term → Working → Episodic → Semantic with Ebbinghaus decay
- Contradiction detection — Auto-detects conflicting memories, deprioritizes outdated ones
- Hebbian learning — "Neurons that fire together wire together" — memory improves with use
- Temporal reasoning — Causal chain traversal, event sequences, temporal range queries
- Brain versioning — Snapshot, rollback, diff brain state
- Brain transplant — Transfer filtered knowledge between brains
- Vietnamese + English — Full bilingual support for extraction and sentiment
Depth Levels
| Depth | Name | Speed | Use Case |
|---|
| 0 | Instant | <10ms | Quick facts, recent context |
| 1 |
Context | ~50ms | Standard recall (default) |
| 2 | Habit | ~200ms | Pattern matching, workflow suggestions |
| 3 | Deep | ~500ms | Cross-domain associations, causal chains |
Notes
- - Memories are stored locally in SQLite at INLINECODE52
- No data is sent to external services (unless optional embedding provider is configured)
- Brain isolation: each brain is independent, no cross-contamination
- INLINECODE53 returns fiber_id for reference tracking
- Priority scale: 0 (trivial) to 10 (critical), default 5
- Memory types: fact, decision, preference, todo, insight, context, instruction, error, workflow, reference
NeuralMemory — AI智能体的联想记忆系统
一种受生物启发的记忆系统,使用扩散激活而非关键词/向量搜索。记忆形成神经图,其中神经元通过20种类型化的突触连接。频繁共同访问的记忆会加强其连接(赫布学习)。陈旧的记忆自然衰减。矛盾自动检测。
为什么不用向量搜索? 向量搜索找到与查询相似的文档。NeuralMemory通过图遍历找到概念相关的记忆——即使没有关键词或嵌入重叠。我们关于认证做了什么决定?会同时激活时间+实体+概念神经元并找到交集。
安装
1. 安装NeuralMemory
bash
pip install neural-memory
首次使用时,~/.neuralmemory/下的大脑和配置会自动创建。
2. 安装OpenClaw插件(推荐)
该插件占用专属的记忆槽位——在每次智能体运行前自动注入上下文,并在运行后自动捕获记忆。
bash
从npm安装
npm install -g neuralmemory
添加到~/.openclaw/openclaw.json:
json
{
plugins: {
load: {
paths: [<插件安装路径>]
},
entries: {
neuralmemory: {
enabled: true,
config: {
pythonPath: python,
brain: default,
autoContext: true,
autoCapture: true
}
}
},
slots: {
memory: neuralmemory
}
}
}
插件特性:
- - 自动注册6个工具(nmemremember、nmemrecall、nmemcontext、nmemtodo、nmemstats、nmemhealth)
- beforeagentstart钩子:注入工具指令+相关记忆作为上下文(跨/new持久化)
- agent_end钩子:自动从对话中提取事实、决策和待办事项
- 可配置:contextDepth(0-3)、maxContextTokens(100-10000)
安装后,构建插件:
bash
cd <插件安装路径>
npm run build
这会将TypeScript编译为dist/中的JavaScript。插件入口点为dist/index.js。
Windows安装
在Windows上,使用正斜杠或转义反斜杠作为openclaw.json中的路径:
json
{
plugins: {
load: {
paths: [C:/Users/<你>/AppData/Roaming/npm/node_modules/neuralmemory]
}
}
}
查找安装路径:
powershell
npm list -g neuralmemory --parseable
如果openclaw plugins list没有显示插件:
- 1. 验证openclaw.json中的路径指向包根目录(package.json所在位置)
- 确保已运行npm run build(dist/文件夹必须存在且包含编译后的.js文件)
- 在插件配置中使用python而非python3(Windows默认)
替代方案:MCP配置(手动)
如果你更喜欢MCP而非插件,添加到~/.openclaw/mcp.json:
json
{
mcpServers: {
neural-memory: {
command: python,
args: [-m, neural_memory.mcp],
env: {
NEURALMEMORY_BRAIN: default
}
}
}
}
在Windows上,使用python(而非python3)。这会提供所有56个MCP工具,但没有自动上下文/自动捕获钩子。
3. 验证
bash
nmem stats
你应该能看到大脑统计信息(神经元、突触、纤维)。
故障排除
| 症状 | 原因 | 修复 |
|---|
| openclaw plugins list不显示插件 | 插件路径错误或未构建 | 运行npm run build,验证openclaw.json中的路径 |
| 智能体在终端中运行nmem remember |
智能体混淆了CLI和工具 | 插件现在通过systemPrompt自动注入工具指令 |
| 智能体在/new后忘记工具 | 新会话中没有工具指令 | 插件现在在每次before
agentstart时注入systemPrompt |
| python3 not found(Windows) | Windows使用python而非python3 | 在插件配置中设置pythonPath: python |
| 超时错误 | 机器慢或大脑大 | 增加插件配置中的timeout(最大120000ms) |
工具参考
核心记忆工具
| 工具 | 用途 | 使用时机 |
|---|
| nmemremember | 存储记忆 | 在决策、错误、事实、洞察、用户偏好之后 |
| nmemrecall |
查询记忆 | 在任务前、用户引用过去上下文时、你还记得... |
| nmem_context | 获取最近记忆 | 在会话开始时,注入新鲜上下文 |
| nmem_todo | 快速待办事项(30天过期) | 任务跟踪 |
智能工具
| 工具 | 用途 | 使用时机 |
|---|
| nmemauto | 从文本自动提取记忆 | 在重要对话后——自动捕获决策、错误、待办事项 |
| nmemrecall(深度=3) |
深度联想回忆 | 需要跨领域连接的复杂问题 |
| nmem_habits | 工作流模式建议 | 当用户重复类似操作序列时 |
管理工具
| 工具 | 用途 | 使用时机 |
|---|
| nmemhealth | 大脑健康诊断 | 定期检查,分享大脑前 |
| nmemstats |
大脑统计信息 | 快速查看记忆数量 |
| nmem_version | 大脑快照和回滚 | 在风险操作前,版本检查点 |
| nmem_transplant | 在大脑间转移记忆 | 跨项目知识共享 |
工作流
会话开始时
- 1. 调用nmemcontext将最近记忆注入你的意识
- 如果用户提到特定主题,调用nmemrecall并传入该主题
对话期间
- 3. 做出决策时:nmemremember,类型为decision
- 发生错误时:nmemremember,类型为error
- 用户陈述偏好时:nmemremember,类型为preference
- 被问及过去事件时:nmemrecall,使用适当深度
会话结束时
- 7. 对重要对话片段调用nmem_auto,操作为process
- 这会自动提取事实、决策、错误和待办事项
示例
记住一个决策
nmem_remember(
content=生产环境使用PostgreSQL,开发环境使用SQLite,
type=decision,
tags=[database, infrastructure],
priority=8
)
使用扩散激活回忆
nmem_recall(
query=生产环境的数据库配置,
depth=1,
max_tokens=500
)
返回通过图遍历找到的记忆,而非关键词匹配。即使没有共享关键词,相关记忆(例如部署使用带pg_dump备份的Docker)也会浮现。
追踪因果链
nmem_recall(
query=为什么上周部署失败了?,
depth=2
)
沿着CAUSEDBY和LEADSTO突触追踪因果链。
从对话自动捕获
nmem_auto(
action=process,
text=我们决定从REST切换到GraphQL,因为前端需要灵活的查询。迁移需要2个冲刺。待办事项:更新API文档。
)
自动提取:1个决策、1个事实、1个待办事项。
关键特性
- - 零LLM依赖 — 纯算法:正则表达式、图遍历、赫布学习
- 扩散激活 — 通过神经图进行联想回忆,而非关键词/向量搜索
- 20种突触类型 — 时间(BEFORE/AFTER)、因果(CAUSEDBY/LEADSTO)、语义(ISA/HASPROPERTY)、情感(FELT/EVOKES)、冲突(CONTRADICTS)
- 记忆生命周期 — 短期→工作→情景→语义,带艾宾浩斯衰减
- 矛盾检测 — 自动检测冲突记忆,降低过时记忆的优先级
- 赫布学习 — 一起放电的神经元连接在一起——记忆随使用而增强
- 时间推理 — 因果链遍历、事件序列、时间范围查询
- 大脑版本控制 — 快照、回滚、比较大脑状态
- 大脑移植 —