Anterior Cingulate Memory ⚡
Conflict detection and error monitoring for AI agents. Part of the AI Brain series.
The anterior cingulate cortex (ACC) monitors for errors and conflicts. This skill gives your AI agent the ability to learn from mistakes — tracking error patterns over time and becoming more careful in contexts where it historically fails.
The Problem
AI agents make mistakes:
- - Misunderstand user intent
- Give wrong information
- Use the wrong tone
- Miss context from earlier in conversation
Without tracking, the same mistakes repeat. The ACC detects and logs these errors, building awareness that persists across sessions.
The Solution
Track error patterns with:
- - Pattern detection — recurring error types get escalated
- Severity levels — normal (1x), warning (2x), critical (3+)
- Resolution tracking — patterns clear after 30+ days
- Watermark system — incremental processing, no re-analysis
Configuration
ACC_MODELS (Model Agnostic)
The LLM screening and calibration scripts are model-agnostic. Set ACC_MODELS to use any CLI-accessible model:
CODEBLOCK0
Format: Comma-separated CLI commands. Each command is invoked with the prompt appended as the final argument. Models are tried in order — if the first fails/times out (45s), the next is used as fallback.
Scripts that use ACC_MODELS:
- -
haiku-screen.sh — LLM confirmation of regex-filtered error candidates - INLINECODE2 — Pattern calibration via LLM classification
Quick Start
1. Install
CODEBLOCK1
This will:
- - Create
memory/acc-state.json with empty patterns - Generate
ACC_STATE.md for session context - Set up cron for analysis 3x daily (4 AM, 12 PM, 8 PM)
2. Check current state
CODEBLOCK2
3. Manual error logging
CODEBLOCK3
4. Check for resolved patterns
CODEBLOCK4
Scripts
| Script | Purpose |
|---|
| INLINECODE5 | Extract user+assistant exchanges since watermark |
| INLINECODE6 |
Run full preprocessing pipeline |
|
log-error.sh | Log an error with pattern, context, mitigation |
|
load-state.sh | Human-readable state for session context |
|
resolve-check.sh | Check for patterns ready to resolve (30+ days) |
|
update-watermark.sh | Update processing watermark |
|
sync-state.sh | Generate ACC_STATE.md from acc-state.json |
|
log-event.sh | Log events for brain analytics |
How It Works
1. Preprocessing Pipeline
The encode-pipeline.sh extracts exchanges from session transcripts:
CODEBLOCK5
Output: pending-errors.json with user+assistant pairs:
CODEBLOCK6
2. Error Analysis (via Cron Agent)
An LLM (configured via ACC_MODELS) analyzes each exchange for:
- - Direct corrections ("no", "wrong", "that's not right")
- Implicit corrections ("actually...", "I meant...")
- Frustration signals ("you're not understanding")
- User confusion caused by the agent
3. Pattern Tracking
Errors are logged with pattern names:
CODEBLOCK7
Patterns escalate with repetition:
- - 1x → normal (noted)
- 2x → warning (watch for this)
- 3+ → critical (actively avoid!)
4. Resolution
Patterns not seen for 30+ days move to resolved:
CODEBLOCK8
Cron Schedule
Default: 3x daily for faster feedback loop
CODEBLOCK9
State File Format
CODEBLOCK10
Event Logging
Track ACC activity over time:
CODEBLOCK11
Events append to ~/.openclaw/workspace/memory/brain-events.jsonl:
CODEBLOCK12
Integration with OpenClaw
Add to session startup (AGENTS.md)
CODEBLOCK13
Behavior Guidelines
When you see patterns in ACC state:
- - 🔴 Critical (3+) — actively verify before responding in this area
- ⚠️ Warning (2x) — be extra careful
- ✅ Resolved — lesson learned, don't repeat
Future: Amygdala Integration
Planned: Connect ACC to amygdala so errors affect emotional state:
- - Errors → lower valence, higher alertness
- Clean runs → maintain positive state
- Pattern resolution → sense of accomplishment
AI Brain Series
Emotional processing | ✅ Live |
|
vta-memory | Reward and motivation | ✅ Live |
|
anterior-cingulate-memory | Conflict detection, error monitoring | ✅ Live |
|
basal-ganglia-memory | Habit formation | 🚧 Development |
|
insula-memory | Internal state awareness | 🚧 Development |
Philosophy
The ACC in the human brain creates that "something's off" feeling — the pre-conscious awareness that you've made an error. This skill gives AI agents a similar capability: persistent awareness of mistake patterns that influences future behavior.
Mistakes aren't failures. They're data. The ACC turns that data into learning.
Built with ⚡ by the OpenClaw community
前扣带回记忆 ⚡
面向AI智能体的冲突检测与错误监控。 属于AI大脑系列。
前扣带回皮层(ACC)负责监控错误与冲突。该技能赋予AI智能体从错误中学习的能力——随时间追踪错误模式,并在历史上曾失败的情境中变得更加谨慎。
问题所在
AI智能体会犯错:
- - 误解用户意图
- 提供错误信息
- 使用不当语气
- 遗漏对话前文背景
若不加以追踪,同样的错误会反复出现。ACC检测并记录这些错误,构建跨会话持续存在的认知意识。
解决方案
通过以下方式追踪错误模式:
- - 模式检测 —— 重复出现的错误类型会被升级处理
- 严重级别 —— 正常(1次)、警告(2次)、严重(3次及以上)
- 解决追踪 —— 模式在30天后自动清除
- 水印系统 —— 增量处理,无需重新分析
配置
ACC_MODELS(模型无关)
LLM筛选与校准脚本与模型无关。设置ACC_MODELS可使用任何可通过CLI访问的模型:
bash
默认(通过CLI使用Anthropic Claude)
export ACC_MODELS=claude --model haiku -p,claude --model sonnet -p
Ollama(本地)
export ACC_MODELS=ollama run llama3,ollama run mistral
OpenAI
export ACC_MODELS=openai chat -m gpt-4o-mini,openai chat -m gpt-4o
单一模型(无备用)
export ACC_MODELS=claude --model haiku -p
格式: 逗号分隔的CLI命令。每个命令调用时,提示词作为最后一个参数附加。模型按顺序尝试——若第一个失败/超时(45秒),则使用下一个作为备用。
使用ACC_MODELS的脚本:
- - haiku-screen.sh —— 对正则过滤后的错误候选进行LLM确认
- calibrate-patterns.sh —— 通过LLM分类进行模式校准
快速开始
1. 安装
bash
cd ~/.openclaw/workspace/skills/anterior-cingulate-memory
./install.sh --with-cron
这将:
- - 创建包含空模式的memory/acc-state.json
- 为会话上下文生成ACC_STATE.md
- 设置每日3次分析定时任务(凌晨4点、中午12点、晚上8点)
2. 检查当前状态
bash
./scripts/load-state.sh
⚡ ACC状态已加载:
活跃模式:2个
- tone_mismatch:2次(警告)
- missed_context:1次(正常)
3. 手动记录错误
bash
./scripts/log-error.sh \
--pattern factual_error \
--context 声称Python 3.9是最新版本,实际已是3.12 \
--mitigation 始终通过网络搜索验证版本号
4. 检查已解决模式
bash
./scripts/resolve-check.sh
检查30天内未出现的模式
脚本
| 脚本 | 用途 |
|---|
| preprocess-errors.sh | 提取自水印以来的用户+助手对话轮次 |
| encode-pipeline.sh |
运行完整预处理流水线 |
| log-error.sh | 记录包含模式、上下文、缓解措施的错误 |
| load-state.sh | 为会话上下文提供人类可读的状态 |
| resolve-check.sh | 检查可解决的模式(30天以上) |
| update-watermark.sh | 更新处理水印 |
| sync-state.sh | 从acc-state.json生成ACC_STATE.md |
| log-event.sh | 记录事件供大脑分析使用 |
工作原理
1. 预处理流水线
encode-pipeline.sh从会话记录中提取对话轮次:
bash
./scripts/encode-pipeline.sh --no-spawn
⚡ ACC编码流水线
步骤1:提取对话轮次...
发现47个待分析对话轮次
输出:包含用户+助手配对的pending-errors.json:
json
[
{
assistant_text: 最新的Python版本是3.9,
user_text: 实际上现在已经是3.12了,
timestamp: 2026-02-11T10:00:00Z
}
]
2. 错误分析(通过定时任务代理)
LLM(通过ACC_MODELS配置)分析每个对话轮次,检查:
- - 直接纠正(不对、错了、不是这样)
- 隐含纠正(实际上……、我的意思是……)
- 挫败信号(你根本没理解)
- 由智能体引起的用户困惑
3. 模式追踪
错误以模式名称记录:
bash
./scripts/log-error.sh --pattern factual_error --context ... --mitigation ...
模式随重复次数升级:
- - 1次 → 正常(已记录)
- 2次 → 警告(需留意)
- 3次及以上 → 严重(主动避免!)
4. 解决
30天内未出现的模式移至已解决状态:
bash
./scripts/resolve-check.sh
✓ 已解决:version_numbers(已清除32天)
定时任务计划
默认:每日3次,实现更快的反馈循环
bash
添加到cron
openclaw cron add --name acc-analysis \
--cron 0 4,12,20
* \
--session isolated \
--agent-turn 运行ACC分析流水线...
状态文件格式
json
{
version: 2.0,
lastUpdated: 2026-02-11T12:00:00Z,
activePatterns: {
factual_error: {
count: 3,
severity: critical,
firstSeen: 2026-02-01T10:00:00Z,
lastSeen: 2026-02-10T15:00:00Z,
context: 提供了过时的版本号,
mitigation: 始终通过网络搜索验证版本
}
},
resolved: {
tone_mismatch: {
count: 2,
resolvedAt: 2026-02-11T04:00:00Z,
daysClear: 32
}
},
stats: {
totalErrorsLogged: 15
}
}
事件记录
追踪ACC活动随时间的变化:
bash
./scripts/log-event.sh analysis errorsfound=2 patternsactive=3 patterns_resolved=1
事件追加到~/.openclaw/workspace/memory/brain-events.jsonl:
json
{ts:2026-02-11T12:00:00Z,type:acc,event:analysis,errorsfound:2,patternsactive:3}
与OpenClaw集成
添加到会话启动(AGENTS.md)
markdown
每次会话
- 1. 加载海马体:./scripts/load-core.sh
- 加载情绪状态:./scripts/load-emotion.sh
- 加载错误模式: ~/.openclaw/workspace/skills/anterior-cingulate-memory/scripts/load-state.sh
行为指南
当在ACC状态中看到模式时:
- - 🔴 严重(3次及以上) —— 在该领域主动验证后再回应
- ⚠️ 警告(2次) —— 格外小心
- ✅ 已解决 —— 吸取教训,不再重复
未来:杏仁核集成
计划中: 将ACC与杏仁核连接,使错误影响情绪状态:
- - 错误 → 降低效价,提高警觉
- 干净运行 → 保持积极状态
- 模式解决 → 成就感
AI大脑系列
情绪处理 | ✅ 已上线 |
|
腹侧被盖区记忆 | 奖励与动机 | ✅ 已上线 |
|
前扣带回记忆 | 冲突检测、错误监控 | ✅ 已上线 |
|
基底节记忆 | 习惯形成 | 🚧 开发中 |
| [岛叶记忆](https://www.clawhub.ai/skills