brainmd
File-based nervous system for AI agents. Behaviors that work get stronger. Behaviors that fail get weaker. Unused patterns decay. Mistakes leave scars.
What It Is
brainmd gives your agent a persistent behavioral memory that survives session restarts. It's not a knowledge base — it's muscle memory. It tracks how the agent behaves, not what it knows.
Three layers complement each other:
| Layer | File | Purpose |
|---|
| brainmd | INLINECODE0 | Behavioral reinforcement — what works, what doesn't |
| Long-term memory |
MEMORY.md | Semantic facts — decisions, people, context |
|
Daily log |
memory/YYYY-MM-DD.md | Episodic notes — what happened today |
brainmd is the only layer that self-modifies. The others are written by the agent, not evolved by it.
Installation
CODEBLOCK0
Then initialize the brain in your workspace:
CODEBLOCK1
This creates:
CODEBLOCK2
Wiring Into OpenClaw
Step 1 — AGENTS.md
Add a startup check so the agent reads its neural state at session start:
CODEBLOCK3 bash
node ~/.openclaw/workspace/brain/cortex/review.js status
Before acting on anything non-trivial, scan for relevant pathways:
- Weak pathways (< 0.5) = you've failed here before. Be careful, double-check.
- Strong pathways (> 0.8) = proven patterns. Trust them, act fast.
- Dying pathways (decaying) = you're forgetting something. Re-evaluate.
After notable outcomes, record them:
bash
node brain/cortex/review.js record "pathway-name" true/false "what happened"
CODEBLOCK5
Step 2 — HEARTBEAT.md
Wire the review cycle into your heartbeat so it runs automatically:
CODEBLOCK6 bash
node ~/.openclaw/workspace/brain/cortex/review.js review
node ~/.openclaw/workspace/brain/cortex/review.js status
CODEBLOCK7
Step 3 — Seed Initial Pathways
Don't hypothesize — seed from real behavior. Run a few sessions first, then record what you observed:
CODEBLOCK8
Start with 5–10 pathways. Let the system grow from there.
Daily Usage
Check neural state
CODEBLOCK9
Output shows all pathways with visual weight bars, success rate, fire count, and last outcome. Use this to calibrate confidence before non-trivial actions.
Record an outcome
CODEBLOCK10
New pathways are auto-created at weight 0.30 (neurogenesis). Existing pathways update their stats.
Run the review cycle
CODEBLOCK11
The cortex examines all pathways and applies reinforcement rules:
- - Strengthen (+0.05): ≥3 fires, ≥80% success rate
- Weaken (−0.10): ≥3 fires, <50% success rate
- Decay (−0.02): unused for 7+ days
- Prune: weight hits 0 (pathway removed)
All changes are logged to mutations/ with timestamp and reason.
Pathway Naming Conventions
CODEBLOCK12
Reading pathway weights
| Weight | Meaning | How to use |
|---|
| 0.8–1.0 | Proven, trusted | Act confidently, don't second-guess |
| 0.5–0.8 |
Developing | Use but verify |
| 0.3–0.5 | Weak / new | Proceed carefully, double-check |
| < 0.3 | Failing / dying | Investigate before using; may need rethinking |
Tuning the Learning Rate
Edit thresholds in brain/cortex/review.js:
CODEBLOCK13
Floor weights (prevent over-pruning)
INLINECODE5 pathways should have a minimum weight floor so they can't be trained away:
CODEBLOCK14
Add a floor field to pathways in pathways.json to protect them from decay.
Architecture Notes
pathways.json — the core state
CODEBLOCK15
mutations/ — the audit log
Every self-modification writes a timestamped JSON file. Never delete these. They're how you trace why the agent's behavior changed over time.
CODEBLOCK16
Integration With Auto-Dream
If you're using scripts/dream.js for memory consolidation, the two systems complement each other:
- - brainmd answers: how should I behave?
- dream.js answers: what do I know?
Neither replaces the other. Wire both into HEARTBEAT.md for full coverage.
Bootstrapping Checklist
- - [ ] Run
init-brain.sh to create directory structure - [ ] Add brainmd status check to AGENTS.md startup routine
- [ ] Add heartbeat entry to HEARTBEAT.md
- [ ] Seed 5–10 pathways from real observed behavior (not theory)
- [ ] Run one manual
review to verify reinforcement logic works - [ ] Check
mutations/ after first review to confirm logging - [ ] Set
floor weights on any instinct:* pathways
Design Principles
- 1. Everything is mutable — no file is sacred except the mutation log
- Use strengthens, disuse weakens — pathways that fire together wire together
- Outcomes matter — track what worked, what didn't; guesses don't count
- Failures leave scars — the most valuable pathways come from mistakes
- Seed from reality — observe first, codify second
- Small and composable — one pathway per behavior pattern
- The schedule forces honesty — if it's not in HEARTBEAT.md, you'll skip it
brainmd
基于文件的AI智能体神经系统。有效的行为会增强,失败的行为会减弱,未使用的模式会衰退,错误会留下痕迹。
概述
brainmd为你的智能体提供持久的行为记忆,即使在会话重启后也能保留。它不是知识库——而是肌肉记忆。它追踪的是智能体如何行为,而非知道什么。
三个层次相互补充:
| 层次 | 文件 | 用途 |
|---|
| brainmd | brain/weights/pathways.json | 行为强化——什么有效,什么无效 |
| 长期记忆 |
MEMORY.md | 语义事实——决策、人物、上下文 |
|
每日日志 | memory/YYYY-MM-DD.md | 情景记录——今天发生了什么 |
brainmd是唯一能够自我修改的层次。其他层次由智能体编写,而非通过进化产生。
安装
bash
clawhub install brainmd
然后在工作区中初始化大脑:
bash
cd ~/.openclaw/workspace
./skills/brainmd/scripts/init-brain.sh brain/
这将创建:
brain/
├── reflexes/ # 快速路径决策脚本
├── habits/
│ └── preferences.json
├── weights/
│ └── pathways.json # ← 核心状态文件
├── cortex/
│ └── review.js # ← 自我审查引擎
└── mutations/ # 不可变的审计日志
接入OpenClaw
步骤1 — AGENTS.md
添加启动检查,使智能体在会话开始时读取其神经状态:
markdown
🧠 brainmd — 咨询你的大脑
读取记忆文件后,检查你的神经状态:
bash
node ~/.openclaw/workspace/brain/cortex/review.js status
在执行任何重要操作之前,扫描相关路径:
- - 弱路径(< 0.5)= 你之前在这里失败过。小心行事,双重检查。
- 强路径(> 0.8)= 经过验证的模式。信任它们,快速行动。
- 衰退路径(正在衰减)= 你正在遗忘某些东西。重新评估。
在取得显著结果后,记录它们:
bash
node brain/cortex/review.js record 路径名称 true/false 发生了什么
步骤2 — HEARTBEAT.md
将审查周期接入你的心跳机制,使其自动运行:
markdown
🧠 brainmd 自我检查(每次心跳)
bash
node ~/.openclaw/workspace/brain/cortex/review.js review
node ~/.openclaw/workspace/brain/cortex/review.js status
每次心跳时,问自己:
- 1. 自上次检查以来我是否犯了错误?→ record <路径> false 发生了什么
- 是否有事情运行良好?→ record <路径> true 什么有效
- 是否出现了新模式?→ 让神经发生创建它
步骤3 — 播种初始路径
不要假设——从真实行为中播种。先运行几个会话,然后记录你观察到的内容:
bash
node brain/cortex/review.js record reflex:morning-briefing true 补充提醒已发送,用户已确认
node brain/cortex/review.js record habit:check-files-before-search true 在谷歌搜索公寓之前读取了apartment-search.md
node brain/cortex/review.js record reflex:safe-file-deletion false 使用了带有错误grep的xargs rm,删除了工作区文件
从5-10条路径开始。让系统从那里成长。
日常使用
检查神经状态
bash
node brain/cortex/review.js status
输出显示所有路径及其可视化权重条、成功率、触发次数和上次结果。在重要操作前使用此功能校准信心。
记录结果
bash
某件事有效
node brain/cortex/review.js record habit:remote-service-recovery true 修复了损坏的systemd服务,使用journalctl进行诊断
某件事失败
node brain/cortex/review.js record habit:bulk-subagent-spawning false 同时生成了2个Opus智能体,导致所有3个模型被限速
新路径以0.30的权重自动创建(神经发生)。现有路径更新其统计数据。
运行审查周期
bash
node brain/cortex/review.js review
皮层检查所有路径并应用强化规则:
- - 增强(+0.05):触发≥3次,成功率≥80%
- 减弱(−0.10):触发≥3次,成功率<50%
- 衰退(−0.02):7天以上未使用
- 修剪:权重降至0(路径被移除)
所有更改都会记录到mutations/中,包含时间戳和原因。
路径命名规范
reflex:timing # 自动的快速路径行为
habit:check-files # 从重复交互中学习到的模式
skill:osint-workflow # 获得的能力
instinct:safe-delete # 安全行为(从高权重开始,最低0.8)
解读路径权重
| 权重 | 含义 | 如何使用 |
|---|
| 0.8–1.0 | 经过验证,可信赖 | 自信行动,不要自我怀疑 |
| 0.5–0.8 |
发展中 | 使用但需验证 |
| 0.3–0.5 | 弱/新 | 谨慎行事,双重检查 |
| < 0.3 | 失败/衰退 | 使用前进行调查;可能需要重新思考 |
调整学习率
编辑brain/cortex/review.js中的阈值:
js
// 当成功率 >= 此值时增强
const STRENGTHEN_THRESHOLD = 0.8;
// 当成功率 < 此值时减弱
const WEAKEN_THRESHOLD = 0.5;
// 开始衰退前的非活动天数
const DECAYONSETDAYS = 7;
// 每个审查周期的权重变化
const DECAY_RATE = 0.02;
const STRENGTHEN_DELTA = 0.05;
const WEAKEN_DELTA = 0.10;
最低权重(防止过度修剪)
instinct:*路径应设置最低权重下限,以防止被训练消除:
json
{
id: instinct:safe-file-deletion,
weight: 0.85,
floor: 0.80,
fires: 1,
successes: 0
}
在pathways.json中为路径添加floor字段,以保护它们免受衰退影响。
架构说明
pathways.json — 核心状态
json
{
version: 42,
pathways: {
habit:check-files-before-search: {
weight: 0.95,
fires: 13,
successes: 11,
lastFired: 2026-03-25T18:00:00.000Z,
lastOutcome: 在推荐衣服前读取了AESTHETIC.md。节省了一次网络搜索。,
created: 2025-11-01T00:00:00.000Z
}
}
}
mutations/ — 审计日志
每次自我修改都会写入一个带时间戳的JSON文件。永远不要删除这些文件。它们是追踪智能体行为为何随时间变化的依据。
json
{
type: strengthen,
target: habit:check-files-before-search,
from: 0.90,
to: 0.95,
reason: 11/13 成功率,
timestamp: 2026-03-26T07:00:00.000Z
}
与Auto-Dream的集成
如果你使用scripts/dream.js进行记忆整合,这两个系统相互补充:
- - brainmd 回答:我应该如何行为?
- dream.js 回答:我知道什么?
两者不可互相替代。将两者都接入HEARTBEAT.md以获得全面覆盖。
引导检查清单
- - [ ] 运行init-brain.sh创建目录结构
- [ ] 将brainmd状态检查添加到AGENTS.md启动例程中
- [ ] 在HEARTBEAT.md中添加心跳条目
- [ ] 从真实观察到的行为(而非理论)中播种5-10条路径
- [ ] 手动运行一次review以验证强化逻辑是否正常工作
- [ ] 首次审查后检查mutations/以确认日志记录
- [ ] 在任何instinct:*路径上设置floor权重
设计原则
- 1. 一切皆可变——除突变日志外,没有文件是神圣不可侵犯的
- 使用则强,不用则弱——共同触发的路径会相互连接