Self-Evolution Engine
Autonomous learning and improvement system that continuously evolves agent behavior based on interaction patterns, feedback, and outcomes.
Core Concepts
Evolution Cycle
CODEBLOCK0
Key Components
| Component | Purpose | Frequency |
|---|
| Observer | Capture interaction patterns | Continuous |
| Analyzer |
Identify improvement opportunities | Daily |
|
Learner | Extract actionable rules | On trigger |
|
Validator | Test changes in isolation | Before integration |
|
Integrator | Update behavioral files | After validation |
Quick Start
CODEBLOCK1
Evolution Data Flow
1. Experience Collection
Sources of experience data:
- -
.learnings/ - Errors, corrections, feature requests - INLINECODE1 - Daily interaction logs
- INLINECODE2 - Long-term memory updates
- Session transcripts - Actual conversation patterns
- Tool usage patterns - What works, what doesn't
2. Pattern Detection
Identify recurring patterns:
CODEBLOCK2
Pattern categories:
- - errorpatterns - Recurring failures
- successpatterns - Repeatable successes
- inefficiencypatterns - Wasted effort
- preferencepatterns - User preferences
- workflow_patterns - Effective sequences
3. Learning Extraction
Transform patterns into actionable rules:
CODEBLOCK3
Output: Candidate rules for behavioral files
4. Validation
Test proposed changes:
CODEBLOCK4
5. Integration
Apply validated changes:
CODEBLOCK5
Behavioral Evolution Targets
SOUL.md (Personality & Principles)
Evolution triggers:
- - User feedback about tone/style
- Pattern of over-apologizing or being too verbose
- Consistently missing user intent
- Style preferences emerging over time
Example evolutions:
CODEBLOCK6
AGENTS.md (Workflows & Rules)
Evolution triggers:
- - Repeated mistakes in workflows
- More efficient sequences discovered
- New tool integrations
- Environment-specific optimizations
Example evolutions:
CODEBLOCK7
TOOLS.md (Tool Knowledge)
Evolution triggers:
- - Tool gotchas discovered
- Better tool combinations found
- Rate limit patterns learned
- Environment-specific configurations
Example evolutions:
CODEBLOCK8
Pattern Recognition
Error Pattern Detection
CODEBLOCK9
Example pattern:
CODEBLOCK10
Success Pattern Detection
CODEBLOCK11
User Preference Learning
CODEBLOCK12
Evolution Metrics
Track evolution effectiveness:
CODEBLOCK13
| Metric | Description | Target |
|---|
| Error Reduction Rate | % decrease in recurring errors | >50% |
| Rule Adoption Rate |
% of proposed rules integrated | >70% |
| User Satisfaction Trend | Positive feedback ratio | >0.8 |
| Efficiency Gain | Time saved per interaction | Measurable |
| Learning Velocity | New rules per week | Sustainable |
Automated Evolution
Periodic Self-Assessment
Add to heartbeat or cron:
CODEBLOCK14
Integration with Self-Improvement Skill
This skill builds on self-improvement:
- 1.
self-improvement logs individual learnings - INLINECODE5 analyzes patterns across learnings
- INLINECODE6 proposes behavioral changes
- INLINECODE7 tracks the change as a learning
Workflow:
CODEBLOCK15
Evolution Rules
When to Evolve
Trigger evolution when:
| Signal | Threshold | Action |
|---|
| Same error 3+ times | Pattern detected | Create prevention rule |
| User correction pattern |
2+ similar corrections | Update behavior |
| Workflow optimization | 20%+ efficiency gain | Update workflow |
| Tool discovery | New capability found | Update TOOLS.md |
| Preference pattern | Consistent user preference | Update SOUL.md |
What to Evolve
| File | Evolution Type | Frequency |
|---|
| SOUL.md | Personality, principles | Rarely |
| AGENTS.md |
Workflows, rules | Often |
| TOOLS.md | Tool knowledge | As discovered |
| MEMORY.md | Key facts | Continuously |
Evolution Safeguards
Before any evolution:
- 1. Validate - Test in isolation
- Review - Check for conflicts
- Backup - Save current state
- Reversible - Ensure can rollback
- Log - Track all changes
CODEBLOCK16
Reports
Evolution Report
CODEBLOCK17
CODEBLOCK18
Diff Report
CODEBLOCK19
Advanced Usage
Custom Pattern Detectors
Create custom detectors in scripts/detectors/:
CODEBLOCK20
Register:
CODEBLOCK21
Evolution Hooks
Trigger evolution on specific events:
CODEBLOCK22
Integration Points
With longterm-memory skill
CODEBLOCK23
With self-improvement skill
CODEBLOCK24
Best Practices
- 1. Run analysis regularly - Weekly or bi-weekly
- Validate before integrating - Never auto-integrate without validation
- Keep evolution log - Track all changes and reasons
- Measure impact - Track metrics before/after changes
- Human oversight - Significant changes should be reviewed
- Rollback ready - Always maintain ability to revert
- Conservative approach - Better to miss an optimization than break behavior
Notes
- - Evolution is gradual, not revolutionary
- Small, validated changes beat big untested changes
- User feedback is the ultimate validation
- Some patterns are noise, not signal
- Evolution should make behavior more consistent, not less
自我进化引擎
基于交互模式、反馈和结果持续进化智能体行为的自主学习与改进系统。
核心概念
进化循环
经验 → 模式检测 → 学习 → 验证 → 集成
↑ ↓
└──────────────── 反馈循环 ←─────────────────┘
关键组件
识别改进机会 | 每日 |
|
学习器 | 提取可执行规则 | 触发时 |
|
验证器 | 隔离测试变更 | 集成前 |
|
集成器 | 更新行为文件 | 验证后 |
快速开始
bash
分析近期交互
python3 {baseDir}/scripts/evolution.py --analyze --days 7
从记忆文件中提取模式
python3 {baseDir}/scripts/evolution.py --extract-patterns
运行自我评估
python3 {baseDir}/scripts/evolution.py --self-assess
生成进化报告
python3 {baseDir}/scripts/evolution.py --report --output evolution-report.md
进化数据流
1. 经验收集
经验数据来源:
- - .learnings/ - 错误、修正、功能请求
- memory/YYYY-MM-DD.md - 每日交互日志
- MEMORY.md - 长期记忆更新
- 会话记录 - 实际对话模式
- 工具使用模式 - 有效与无效操作
2. 模式检测
识别重复模式:
bash
查找重复错误模式
python3 {baseDir}/scripts/evolution.py --pattern errors --threshold 3
查找成功工作流
python3 {baseDir}/scripts/evolution.py --pattern successes --min-occurrences 5
查找优化机会
python3 {baseDir}/scripts/evolution.py --pattern inefficiencies
模式分类:
- - errorpatterns - 重复失败
- successpatterns - 可重复成功
- inefficiencypatterns - 无效努力
- preferencepatterns - 用户偏好
- workflow_patterns - 有效序列
3. 学习提取
将模式转化为可执行规则:
bash
自动提取学习内容
python3 {baseDir}/scripts/evolution.py --learn --auto
交互式学习会话
python3 {baseDir}/scripts/evolution.py --learn --interactive
输出:行为文件的候选规则
4. 验证
测试提议的变更:
bash
验证提议的变更
python3 {baseDir}/scripts/evolution.py --validate --rule 提交前始终使用git status
模拟行为变更
python3 {baseDir}/scripts/evolution.py --simulate --file SOUL.md --change 更加简洁
5. 集成
应用已验证的变更:
bash
应用到行为文件
python3 {baseDir}/scripts/evolution.py --integrate --target SOUL.md
更新工作流规则
python3 {baseDir}/scripts/evolution.py --integrate --target AGENTS.md
行为进化目标
SOUL.md(个性与原则)
进化触发条件:
- - 用户对语气/风格的反馈
- 过度道歉或过于冗长的模式
- 持续错过用户意图
- 随时间显现的风格偏好
进化示例:
markdown
之前
保持有帮助且全面
之后(进化后)
保持简洁直接。跳过免责声明。行动,而非解释。
AGENTS.md(工作流与规则)
进化触发条件:
- - 工作流中重复错误
- 发现更高效的序列
- 新工具集成
- 环境特定优化
进化示例:
markdown
之前
编辑前检查文件
之后(进化后)
始终先读取文件。确认结构后再使用编辑工具。
对于超过500行的文件,使用偏移量/限制分块读取。
TOOLS.md(工具知识)
进化触发条件:
- - 发现的工具陷阱
- 发现的更好工具组合
- 学习的速率限制模式
- 环境特定配置
进化示例:
markdown
学习后添加
agent-browser
- - 解析时始终使用 --json
- 导航后等待2秒再进行快照
- 每次会话后关闭浏览器以防止内存泄漏
模式识别
错误模式检测
bash
查找重复错误
python3 {baseDir}/scripts/evolution.py \
--analyze errors \
--source .learnings/ERRORS.md \
--threshold 3 \
--output patterns/errors.json
模式示例:
json
{
pattern_id: ERR-PATTERN-001,
description: 使用相对路径时出现文件未找到错误,
occurrences: 5,
first_seen: 2025-01-10,
last_seen: 2025-01-20,
suggested_rule: 始终相对于工作区根目录解析路径,
target_file: AGENTS.md
}
成功模式检测
bash
查找成功工作流
python3 {baseDir}/scripts/evolution.py \
--analyze successes \
--source memory/ \
--min-effectiveness 0.8
用户偏好学习
bash
从修正中提取用户偏好
python3 {baseDir}/scripts/evolution.py \
--analyze preferences \
--source .learnings/LEARNINGS.md \
--category correction
进化指标
追踪进化效果:
bash
生成指标
python3 {baseDir}/scripts/evolution.py --metrics --period 30d
输出
| 指标 | 描述 | 目标 |
|---|
| 错误减少率 | 重复错误减少百分比 | >50% |
| 规则采纳率 |
提议规则集成百分比 | >70% |
| 用户满意度趋势 | 正面反馈比率 | >0.8 |
| 效率提升 | 每次交互节省时间 | 可衡量 |
| 学习速度 | 每周新规则数 | 可持续 |
自动进化
定期自我评估
添加到心跳或cron:
bash
每周自我评估
python3 {baseDir}/scripts/evolution.py --self-assess --auto-evolve
输出到进化日志
python3 {baseDir}/scripts/evolution.py --self-assess --log evolution-log.md
与自我改进技能集成
此技能建立在self-improvement之上:
- 1. self-improvement记录单个学习内容
- self-evolution分析跨学习内容的模式
- self-evolution提出行为变更建议
- self-improvement将变更作为学习内容追踪
工作流:
bash
记录学习内容(self-improvement)
→ .learnings/LEARNINGS.md
模式检测(self-evolution)
python3 {baseDir}/scripts/evolution.py --analyze --source .learnings/
提议变更出现
→ 模式:忘记先读取文件出现5次
验证并集成
python3 {baseDir}/scripts/evolution.py --integrate --approve
→ AGENTS.md已更新
作为学习内容追踪(self-improvement)
→ 推广规则:编辑前始终先读取
进化规则
何时进化
触发进化的条件:
| 信号 | 阈值 | 操作 |
|---|
| 同一错误出现3次以上 | 检测到模式 | 创建预防规则 |
| 用户修正模式 |
2次以上相似修正 | 更新行为 |
| 工作流优化 | 效率提升20%以上 | 更新工作流 |
| 工具发现 | 发现新能力 | 更新TOOLS.md |
| 偏好模式 | 一致的用户偏好 | 更新SOUL.md |
进化什么
| 文件 | 进化类型 | 频率 |
|---|
| SOUL.md | 个性、原则 | 很少 |
| AGENTS.md |
工作流、规则 | 经常 |
| TOOLS.md | 工具知识 | 发现时 |
| MEMORY.md | 关键事实 | 持续 |
进化保障
任何进化前:
- 1. 验证 - 隔离测试
- 审查 - 检查冲突
- 备份 - 保存当前状态
- 可逆 - 确保可以回滚
- 记录 - 追踪所有变更
bash
进化前创建备份
python3 {baseDir}/scripts/evolution.py --backup
需要时回滚
python3 {baseDir}/scripts/evolution.py --rollback --to 2025-01-20
报告
进化报告
bash
生成综合报告
python3 {baseDir}/