Adaptive Brain
A self-improving agent system that doesn't just log — it learns, adapts, and evolves.
Core Philosophy
The existing self-improving-agent skill logs to markdown. That's a diary. This is an immune system — it detects patterns, builds antibodies, prevents recurring failures, and gets smarter with every interaction.
Quick Start
CODEBLOCK0
What Makes This Different
| Feature | Basic Logger | Adaptive Brain |
|---|
| Log entries | ✅ | ✅ |
| Pattern detection |
❌ | ✅ Recurring error clustering |
| Confidence scoring | ❌ | ✅ Weighted by success rate |
| Auto-adaptation | ❌ | ✅ Changes behavior automatically |
| Failure prediction | ❌ | ✅ Risk scoring before tasks |
| Skill evolution | ❌ | ✅ Rewrites SKILL.md based on learnings |
| Rollback | ❌ | ✅ Reverts bad adaptations |
| Performance metrics | ❌ | ✅ Tracks improvement over time |
| Cross-pattern links | ❌ | ✅ Connects related errors |
| Behavioral DNA | ❌ | ✅ Encodes successful patterns |
| Outcome tracking | ❌ | ✅ Tracks prediction accuracy |
| Skill mutation | ❌ | ✅ Auto-generates prevention rules |
| Context awareness | ❌ | ✅ Weighs learnings by recency & area |
| Feedback loop | ❌ | ✅ Confirms/contradicts based on outcomes |
Architecture
CODEBLOCK1
Commands
learn — Log a learning with auto-classification
CODEBLOCK2
error — Log an error with pattern detection
CODEBLOCK3
The brain automatically checks for similar past errors and links them.
adapt — Run adaptation cycle
Scans recent learnings and errors, then:
- 1. Detects recurring patterns (same error 3+ times)
- Updates behavioral DNA
- Generates prevention rules
- Optionally promotes to workspace files
predict — Predict failure risk before a task
CODEBLOCK4
Returns risk score based on:
- - Past errors in similar tasks
- Confidence level in relevant skills
- Historical success rate for task type
evolve — Auto-evolve based on accumulated learnings
CODEBLOCK5
The brain reviews all learnings and:
- 1. Identifies patterns that should become permanent rules
- Generates optimized SKILL.md patches
- Creates behavioral DNA mutations
- Tracks evolution history (for rollback)
dashboard — Learning metrics
Shows:
- - Total learnings by category
- Error recurrence rate
- Adaptation success rate
- Improvement trend (getting better or worse?)
- Top patterns
- Confidence score over time
rollback — Undo a bad adaptation
CODEBLOCK6
Reverts to a previous evolution state.
Behavioral DNA
The brain maintains a "DNA" string encoding successful behavioral patterns:
CODEBLOCK7
Each gene is backed by learnings. When a gene's backing learnings are resolved, it can be retired.
Pattern Detection
The brain clusters errors and learnings into patterns:
CODEBLOCK8
Integration with OpenClaw
The brain reads and writes to workspace files:
| Brain Action | Target File | When |
|---|
| Behavioral rule | SOUL.md | Confidence > 0.9, seen 3+ times |
| Tool gotcha |
TOOLS.md | Error pattern for specific tool |
| Workflow | AGENTS.md | Process improvement confirmed |
| Long-term | MEMORY.md | Major insight or decision |
Learning Confidence
Every learning has a confidence score (0-1) that changes over time:
- - New learning: 0.5 (neutral)
- Confirmed correct: +0.2 per successful application
- Contradicted: -0.3
- Resolves error: +0.1
- Older than 30 days: decays by 0.1
Only high-confidence learnings (>0.8) get promoted to workspace files.
Automatic Triggers
After each session, the brain should run:
CODEBLOCK9
Or set up a cron job:
CODEBLOCK10
See Also
For basic markdown logging (complementary to this skill), see the self-improving-agent skill. This skill is an enhanced superset with adaptation, prediction, and evolution capabilities.
自适应大脑
一个自我改进的代理系统,它不仅仅是记录——它能够学习、适应和进化。
核心理念
现有的自我改进代理技能只是将内容记录到markdown文件中。那是一本日记。而这是一个免疫系统——它能检测模式、构建抗体、防止重复失败,并在每次交互中变得更智能。
快速开始
bash
python3 scripts/brain.py init # 初始化大脑系统
python3 scripts/brain.py learn # 记录一次学习
python3 scripts/brain.py error # 记录一个错误
python3 scripts/brain.py adapt # 运行适应周期
python3 scripts/brain.py dashboard # 显示改进指标
python3 scripts/brain.py predict 任务描述 # 预测失败风险
python3 scripts/brain.py evolve # 自动进化技能配置
独特之处
❌ | ✅ 重复错误聚类 |
| 置信度评分 | ❌ | ✅ 按成功率加权 |
| 自动适应 | ❌ | ✅ 自动改变行为 |
| 失败预测 | ❌ | ✅ 任务前风险评分 |
| 技能进化 | ❌ | ✅ 基于学习重写SKILL.md |
| 回滚 | ❌ | ✅ 撤销不良适应 |
| 性能指标 | ❌ | ✅ 追踪随时间改进情况 |
| 跨模式链接 | ❌ | ✅ 连接相关错误 |
| 行为DNA | ❌ | ✅ 编码成功模式 |
| 结果追踪 | ❌ | ✅ 追踪预测准确性 |
| 技能变异 | ❌ | ✅ 自动生成预防规则 |
| 上下文感知 | ❌ | ✅ 按时效性和领域加权学习 |
| 反馈循环 | ❌ | ✅ 基于结果确认/反驳 |
架构
~/.adaptive-brain/
├── brain.json # 核心状态:DNA、置信度、指标
├── learnings.json # 所有学习记录及其评分和链接
├── patterns.json # 检测到的重复模式
├── evolution.json # 适应和回滚历史
├── metrics.json # 随时间变化的性能追踪
└── predictions.json # 失败预测及其结果
命令
learn — 记录学习并自动分类
bash
python3 scripts/brain.py learn \
--type correction \
--summary 用户修正:天气默认显示UTC而非本地时间 \
--area config \
--context 询问达卡天气时,返回了UTC时间 \
--fix 报告天气前始终检查USER.md中的时区设置
error — 记录错误并检测模式
bash
python3 scripts/brain.py error \
--command pip install pandas \
--error externally-managed-environment \
--fix 使用venv或--break-system-packages \
--files signal_engine.py
大脑会自动检查相似的历史错误并进行关联。
adapt — 运行适应周期
扫描最近的学习记录和错误,然后:
- 1. 检测重复模式(同一错误出现3次以上)
- 更新行为DNA
- 生成预防规则
- 可选地提升到工作区文件
predict — 在任务前预测失败风险
bash
python3 scripts/brain.py predict 部署到生产环境
基于以下因素返回风险评分:
- - 类似任务的历史错误
- 相关技能的置信度水平
- 任务类型的历史成功率
evolve — 基于累积学习自动进化
bash
python3 scripts/brain.py evolve
大脑审查所有学习记录并:
- 1. 识别应成为永久规则的模式
- 生成优化的SKILL.md补丁
- 创建行为DNA变异
- 追踪进化历史(用于回滚)
dashboard — 学习指标
显示:
- - 按类别统计的学习总数
- 错误重复率
- 适应成功率
- 改进趋势(变好还是变差?)
- 主要模式
- 随时间变化的置信度评分
rollback — 撤销不良适应
bash
python3 scripts/brain.py rollback --to 3
恢复到之前的进化状态。
行为DNA
大脑维护一个编码成功行为模式的DNA字符串:
json
{
dna: {
alwaysusevenv: true,
checkpricesbefore_trade: true,
writefilesthen_execute: true,
testbeforepublish: true,
default_timezone: UTC
},
mutations: [
{timestamp: ..., gene: alwaysusevenv, reason: 连续3次pip错误}
]
}
每个基因都有学习记录作为支撑。当支撑某个基因的学习记录被解决后,该基因可以被淘汰。
模式检测
大脑将错误和学习记录聚类成模式:
json
{
patterns: [
{
id: P001,
name: 包安装失败,
keywords: [pip, externally-managed, venv],
count: 4,
first_seen: 2026-03-30,
last_seen: 2026-03-31,
prevention: 始终使用venv或--break-system-packages,
confidence: 0.95
}
]
}
与OpenClaw的集成
大脑读取并写入工作区文件:
| 大脑操作 | 目标文件 | 触发条件 |
|---|
| 行为规则 | SOUL.md | 置信度 > 0.9,出现3次以上 |
| 工具陷阱 |
TOOLS.md | 特定工具的错误模式 |
| 工作流程 | AGENTS.md | 流程改进已确认 |
| 长期记忆 | MEMORY.md | 重大见解或决策 |
学习置信度
每个学习记录都有一个随时间变化的置信度评分(0-1):
- - 新学习记录:0.5(中性)
- 确认正确:每次成功应用+0.2
- 被反驳:-0.3
- 解决错误:+0.1
- 超过30天:衰减0.1
只有高置信度的学习记录(>0.8)才会被提升到工作区文件。
自动触发
每次会话结束后,大脑应运行:
bash
python3 scripts/brain.py adapt
或设置一个定时任务:
计划:每天23:00
命令:python3 scripts/brain.py adapt
另请参阅
关于基础的markdown日志记录(作为本技能的补充),请参见self-improving-agent技能。本技能是一个增强的超集,具备适应、预测和进化能力。