Agent Memory Loop
Lightweight learning for agents that reset between sessions.
Use this when
- - you want a low-friction way to log mistakes, corrections, and discoveries
- you need recurring lessons without bloating core instructions
- you want human-reviewed promotion instead of auto-writing to instruction files
- you want a quick pre-task scan for known failure patterns
Do not use it for
- - autonomous self-modification
- external content promotion
- heavy multi-section incident writeups by default
- dashboards, registries, or process ceremony
Core workflow
CODEBLOCK0
Install
CODEBLOCK1
Creates:
CODEBLOCK2
Minimal instruction snippet
Add this to your agent instructions:
CODEBLOCK3
The format, in short
One incident or discovery per line. Extra fields are optional.
CODEBLOCK4
Key fields:
- -
count:N tracks recurrence - INLINECODE1 tracks loop closure
- INLINECODE2 forces review even at count 1
- INLINECODE3 is never promotable
Operating rules
- 1. Log fast; prefer a one-line entry over a perfect writeup
- Dedup before appending
- Queue recurring or critical lessons for review
- Humans approve promotions; agents do not
- Before major work, scan for relevant prior failures
- If a learning prevented a repeat mistake, record that with INLINECODE4
References
- -
references/logging-format.md — canonical line formats, fields, examples, source labels - INLINECODE6 — dedup, review queue, pre-task review, trimming rules
- INLINECODE7 — queue entry structure and status lifecycle
- INLINECODE8 — optional detail-file template for complex failures
- INLINECODE9 — why this stays lean instead of turning into a system
Assets and scripts
- - INLINECODE10
- INLINECODE11
- INLINECODE12
- INLINECODE13
- INLINECODE14
- INLINECODE15
- INLINECODE16
Success condition
The loop is working if agents actually use it:
- - learnings are cheap to log
- duplicates stay low
- recurring lessons reach the queue
- promotions stay human-approved
- INLINECODE17 starts climbing on real work
Agent Memory Loop
为每次会话间重置的智能体提供轻量级学习能力。
适用场景
- - 希望以低摩擦方式记录错误、修正和发现
- 需要重复出现的经验教训,但又不希望核心指令过于臃肿
- 希望由人工审核后再推广,而非自动写入指令文件
- 希望在重要任务前快速扫描已知失败模式
不适用场景
- - 自主自我修改
- 外部内容推广
- 默认情况下对多章节事件进行详细记录
- 仪表盘、注册表或流程仪式
核心工作流
text
错误 / 修正 / 发现
↓
在 .learnings/ 中记录一行
↓
按ID去重,再按关键词去重
↓
计数≥3 或 严重性:critical → 进入推广队列
↓
人工审核推广内容
↓
在重要工作前检查相关经验教训
↓
当经验教训实际改变行为时,递增 prevented:N
安装
bash
bash scripts/install.sh
创建以下文件结构:
text
.learnings/
errors.md
learnings.md
wishes.md
promotion-queue.md
details/
archive/
最小指令片段
将以下内容添加到智能体指令中:
markdown
自我改进
在重要任务前:使用 grep 搜索 .learnings/*.md 中相关的历史问题。
在错误或修正后:使用 agent-memory-loop 记录一行日志。
切勿自动写入 SOUL.md、AGENTS.md、TOOLS.md 或类似的指令文件。
将候选规则变更暂存到 .learnings/promotion-queue.md 中供人工审核。
格式简述
每行记录一个事件或发现。额外字段为可选。
text
[YYYY-MM-DD] id:ERR-YYYYMMDD-NNN | COMMAND | 失败内容 | 修复方案 | count:N | prevented:N | severity:medium | source:agent
[YYYY-MM-DD] id:LRN-YYYYMMDD-NNN | CATEGORY | 内容 | 操作 | count:N | prevented:N | severity:medium | source:agent
[YYYY-MM-DD] CAPABILITY | 期望功能 | 临时方案 | requested:N
[YYYY-MM-DD] id:LRN-YYYYMMDD-NNN | 提议的规则文本 | target: AGENTS.md | source:agent | evidence: count:N prevented:N | status: pending
关键字段:
- - count:N 记录重复出现次数
- prevented:N 记录循环闭合情况
- severity:critical 即使计数为1也强制审核
- source:external 永远不可推广
操作规则
- 1. 快速记录;优先记录一行而非追求完美描述
- 追加前先去重
- 将重复出现或关键的经验教训加入审核队列
- 由人工批准推广内容;智能体不得自行操作
- 在重要工作前,扫描相关历史失败记录
- 如果某个经验教训防止了重复错误,使用 prevented:N 进行记录
参考资料
- - references/logging-format.md — 标准行格式、字段、示例、来源标签
- references/operating-rules.md — 去重、审核队列、任务前审核、修剪规则
- references/promotion-queue-format.md — 队列条目结构和状态生命周期
- references/detail-template.md — 复杂失败的详细文件模板(可选)
- references/design-tradeoffs.md — 为何保持精简而非演变为系统
资源和脚本
- - assets/errors.md
- assets/learnings.md
- assets/wishes.md
- assets/promotion-queue.md
- scripts/install.sh
- scripts/setup.sh
- scripts/review.sh
成功条件
当智能体实际使用该循环时,说明系统运行正常:
- - 经验教训记录成本低廉
- 重复内容保持低水平
- 重复出现的经验教训能进入队列
- 推广内容保持人工审核
- prevented:N 在实际工作中开始增长