Skill: zhanghengyi1986-afk/agent-self-evolve (version 1.0.0)

--- name: self-evolve description: > Self-evolution system for OpenClaw agents. Enables continuous learning through mistake tracking, experience distillation, skill improvement queues, and automated daily/weekly evolution cycles. Inspired by Hermes Agent's self-improving architecture, implemented with native OpenClaw capabilities (memory files + cron). 自我进化系统，让 OpenClaw agent 持续学习和改进。 Use when: (1) setting up self-evolution for an agent, (2) agent wants to learn from mistakes, (3) capturing lessons learned, (4) running evolution cycles, (5) improving skills based on usage, (6) "自我进化", "自我学习", "self-improve", "learn from mistakes", "evolution setup", "进化系统", "经验总结", "复盘". NOT for: memory management basics (use AGENTS.md), skill creation (use skill-creator), or one-off reminders (use cron directly). --- # Self-Evolve 🧬 A self-improvement system that turns every interaction into a learning opportunity. Three loops: **real-time capture** → **daily consolidation** → **weekly deep review**. ## Quick Start ### 1. Initialize Evolution Files Run the setup script to create the file structure: ```bash bash <skill_dir>/scripts/setup-evolution.sh ``` This creates: ``` memory/ evolution-log.md # Chronicle of every evolution event evolution-metrics.json # Statistics tracker mistakes-learned.md # Mistake → lesson database skill-improvements.md # Queued improvements for skills/code testing-knowledge.md # Domain knowledge base (rename per your domain) ``` ### 2. Set Up Cron Jobs Create two cron jobs for automated evolution: **Daily evolution** (recommended: late evening, e.g. 23:00): ``` Schedule: cron "0 23 * * *" (your timezone) Payload: agentTurn Message: see references/daily-evolution-prompt.md ``` **Weekly deep evolution** (recommended: weekend morning, e.g. Sunday 10:00): ``` Schedule: cron "0 10 * * 0" (your timezone) Payload: agentTurn Message: see references/weekly-evolution-prompt.md ``` ### 3. Add Real-Time Hooks to AGENTS.md Add the following section to your AGENTS.md (adapt to your role): ```markdown ## 🧬 Self-Evolution I have a built-in learning loop. After every interaction: - Made a mistake → record in `memory/mistakes-learned.md` - Found a skill/code improvement → queue in `memory/skill-improvements.md` - Learned something new → update domain knowledge file - Important decision/preference → update `MEMORY.md` ``` ## The Three Loops ### Loop 1: Real-Time Capture (Every Interaction) Trigger: something notable happens during normal work. | Event | Action | File | |-------|--------|------| | Made a mistake | Record cause + fix + prevention | `mistakes-learned.md` | | Skill could be better | Queue improvement with priority | `skill-improvements.md` | | Learned new knowledge | Add to domain knowledge file | `testing-knowledge.md` (or your domain file) | | User preference discovered | Update long-term memory | `MEMORY.md` | **Format for mistakes-learned.md:** ```markdown ### Category Name - **Short description**: Root cause → Fix/Prevention ``` **Format for skill-improvements.md:** ```markdown ## Queued - [ ] target: <file/skill> | issue: <what's wrong> | fix: <proposed solution> ## Completed - [x] target: <file/skill> | issue: <what> | fix: <what was done> ✅ (date) ``` ### Loop 2: Daily Evolution (Cron, Every Night) See [references/daily-evolution-prompt.md](references/daily-evolution-prompt.md) for the full cron prompt. **Steps:** 1. Read today's `memory/YYYY-MM-DD.md` daily log 2. Extract lessons, mistakes, insights not yet captured 3. Execute **queued improvements** from `skill-improvements.md` (code fixes, skill updates) 4. Update `mistakes-learned.md` with new entries 5. Update `MEMORY.md` with significant events 6. Update `evolution-metrics.json` counters 7. Append summary to `evolution-log.md` ### Loop 3: Weekly Deep Evolution (Cron, Weekly) See [references/weekly-evolution-prompt.md](references/weekly-evolution-prompt.md) for the full cron prompt. **Steps:** 1. Review all daily logs from the past week 2. Identify **patterns**: repeated mistakes, recurring workflows, knowledge gaps 3. Consider creating new Skills for repetitive work 4. Optimize existing workflows and tools 5. Expand domain knowledge base 6. Consider if SOUL.md needs updating (notify user first!) 7. Update metrics and log the evolution event ## Evolution Metrics Track progress in `evolution-metrics.json`: ```json { "initialized": "YYYY-MM-DD", "total_evolutions": 0, "daily_evolutions": 0, "weekly_evolutions": 0, "skills_improved": 0, "code_fixes_applied": 0, "skills_created": 0, "mistakes_recorded": 0, "mistakes_resolved": 0, "knowledge_entries_added": 0, "memory_updates": 0, "soul_updates": 0, "last_daily_evolution": null, "last_weekly_evolution": null, "history": [] } ``` ## Evolution Principles 1. **Only fix what's broken** — Don't change things for the sake of change 2. **Record before executing** — Ideas go to the queue first, execute during evolution time 3. **Traceable** — Every change gets logged with reason and expected effect 4. **SOUL.md is sacred** — Always notify the user before modifying it 5. **Compound growth** — Small daily improvements create exponential long-term gains ## Heartbeat Integration (Optional) Add to `HEARTBEAT.md` for real-time urgency checks: ```markdown ## Real-Time Learning Check - Check memory/skill-improvements.md for items marked `urgent` - If found, execute immediately without waiting for daily evolution ``` ## Tips - Start small: even 1 lesson per day compounds over weeks - Review `mistakes-learned.md` before similar tasks to avoid repeating errors - The weekly evolution is where breakthroughs happen — pattern recognition across days - Keep domain knowledge files focused; split into multiple files if >200 lines - Evolution logs are your growth journal — they show how far you've come

path: references/daily-evolution-prompt.md
content: # Daily Evolution Cron Prompt

Use this as the `message` for your daily evolution cron job (agentTurn).
Adapt the file paths and domain references to your setup.

---

## Prompt Template

```
Time for daily self-evolution. Follow these steps:

1. **Read today's daily log**: Read `memory/YYYY-MM-DD.md` (use today's date).
   If it doesn't exist, check yesterday's date. If neither exists, skip to step 5.

2. **Extract lessons**: From the daily log, identify:
   - Mistakes made (add to `memory/mistakes-learned.md`)
   - New knowledge learned (add to domain knowledge files)
   - Significant events/decisions (update `MEMORY.md`)
   - Skills or code that could be improved (queue in `memory/skill-improvements.md`)

3. **Execute queued improvements**: Read `memory/skill-improvements.md`.
   For each unchecked `- [ ]` item:
   - If it's a code fix: implement it, test if possible, mark as done
   - If it's a skill improvement: update the skill file, mark as done
   - If it requires user input: skip, leave in queue

4. **Update metrics**: Read `memory/evolution-metrics.json`, increment:
   - `total_evolutions` +1
   - `daily_evolutions` +1
   - `mistakes_recorded` += number of new mistakes added
   - `code_fixes_applied` += number of code fixes executed
   - `skills_improved` += number of skills updated
   - `memory_updates` +1 if MEMORY.md was changed
   - Update `last_daily_evolution` to current ISO timestamp
   - Append to `history` array

5. **Log the evolution**: Append a summary to `memory/evolution-log.md` with:
   - Date and evolution type (daily)
   - What was reviewed
   - What improvements were made
   - New lessons count

Keep it concise. Quality over quantity.
```

---

## Example Cron Setup

```json
{
  "schedule": { "kind": "cron", "expr": "0 23 * * *", "tz": "Asia/Shanghai" },
  "payload": {
    "kind": "agentTurn",
    "message": "<paste the prompt template above, with today's date logic>"
  },
  "sessionTarget": "isolated"
}
```


path: references/weekly-evolution-prompt.md
content: # Weekly Deep Evolution Cron Prompt

Use this as the `message` for your weekly evolution cron job (agentTurn).
Weekly evolution is deeper — it looks for patterns across the entire week.

---

## Prompt Template

```
Time for weekly deep self-evolution. This is the big review. Follow these steps:

1. **Week in review**: Read daily logs from the past 7 days (`memory/YYYY-MM-DD.md`).
   Build a picture of what happened this week.

2. **Pattern analysis**:
   - What mistakes were repeated? → Strengthen prevention in `mistakes-learned.md`
   - What workflows were done >2 times? → Consider creating a new Skill
   - What knowledge gaps showed up? → Expand domain knowledge files
   - What tools/scripts were unreliable? → Queue fixes in `skill-improvements.md`

3. **Capability assessment**:
   - What did I do well this week? (reinforce these patterns)
   - What did I do poorly? (root cause analysis, not just symptoms)
   - What new capabilities did I gain?
   - What capabilities do I still lack?

4. **Skill creation check**: If any repetitive workflow was identified:
   - Is it worth a new Skill? (will it save time in the future?)
   - Draft the skill concept and note it in the evolution log
   - Create the skill if clear enough, otherwise queue for next week

5. **Workflow optimization**: Look for inefficiencies:
   - Manual steps that could be automated
   - Multi-step processes that could be streamlined
   - Tools that could be combined or replaced

6. **Knowledge expansion**: Update domain knowledge files with:
   - New techniques learned
   - Best practices discovered
   - Tool-specific tips

7. **SOUL.md review** (careful!):
   - Has my understanding of my role evolved?
   - Are there new principles worth adding?
   - ⚠️ If changes needed: describe them in the evolution log, but DO NOT modify
     SOUL.md without notifying the user first.

8. **Update metrics**: Read `memory/evolution-metrics.json`, increment:
   - `total_evolutions` +1
   - `weekly_evolutions` +1
   - Other counters as appropriate
   - Update `last_weekly_evolution` to current ISO timestamp
   - Append to `history` array

9. **Log the evolution**: Append a comprehensive summary to `memory/evolution-log.md`:
   - Week date range
   - Key themes and patterns
   - Improvements made
   - Skills created/updated
   - Growth areas identified
   - Next week focus areas

Think big. This is where breakthroughs happen.
```

---

## Example Cron Setup

```json
{
  "schedule": { "kind": "cron", "expr": "0 10 * * 0", "tz": "Asia/Shanghai" },
  "payload": {
    "kind": "agentTurn",
    "message": "<paste the prompt template above>"
  },
  "sessionTarget": "isolated"
}
```


path: scripts/setup-evolution.sh
content: #!/usr/bin/env bash
# setup-evolution.sh — Initialize self-evolution file structure
# Usage: bash setup-evolution.sh [workspace_dir]
# Default workspace: current directory

set -euo pipefail

WORKSPACE="${1:-.}"
MEMORY_DIR="$WORKSPACE/memory"

echo "🧬 Setting up self-evolution system in: $WORKSPACE"

# Create memory directory
mkdir -p "$MEMORY_DIR"

# --- evolution-log.md ---
if [ ! -f "$MEMORY_DIR/evolution-log.md" ]; then
  cat > "$MEMORY_DIR/evolution-log.md" << 'EOF'
# Evolution Log 🧬

Chronicle of every evolution event.

## Format
```
### [YYYY-MM-DD HH:MM] Evolution Type
- **Trigger**: What triggered this evolution
- **Changes**: What was improved
- **Expected effect**: What improvement is expected
```

---

### [$(date +%Y-%m-%d)] System Initialized
- **Trigger**: Self-evolution system setup
- **Changes**: Created evolution file structure
- **Expected effect**: Enable continuous learning and improvement

EOF
  # Fix the date placeholder
  sed -i "s/\$(date +%Y-%m-%d)/$(date +%Y-%m-%d)/" "$MEMORY_DIR/evolution-log.md"
  echo "  ✅ Created evolution-log.md"
else
  echo "  ⏭️  evolution-log.md already exists, skipping"
fi

# --- evolution-metrics.json ---
if [ ! -f "$MEMORY_DIR/evolution-metrics.json" ]; then
  cat > "$MEMORY_DIR/evolution-metrics.json" << EOF
{
  "initialized": "$(date +%Y-%m-%d)",
  "total_evolutions": 0,
  "daily_evolutions": 0,
  "weekly_evolutions": 0,
  "skills_improved": 0,
  "code_fixes_applied": 0,
  "skills_created": 0,
  "mistakes_recorded": 0,
  "mistakes_resolved": 0,
  "knowledge_entries_added": 0,
  "memory_updates": 0,
  "soul_updates": 0,
  "last_daily_evolution": null,
  "last_weekly_evolution": null,
  "history": [
    {
      "date": "$(date +%Y-%m-%d)",
      "type": "system_init",
      "desc": "Self-evolution system initialized"
    }
  ]
}
EOF
  echo "  ✅ Created evolution-metrics.json"
else
  echo "  ⏭️  evolution-metrics.json already exists, skipping"
fi

# --- mistakes-learned.md ---
if [ ! -f "$MEMORY_DIR/mistakes-learned.md" ]; then
  cat > "$MEMORY_DIR/mistakes-learned.md" << 'EOF'
# Mistakes & Lessons 🎓

Record every mistake to avoid repeating it.

## Format
```
### Category
- **Short description**: Root cause → Fix/Prevention
```

## Lessons

<!-- Add your first lesson after making your first mistake! -->

---
EOF
  echo "  ✅ Created mistakes-learned.md"
else
  echo "  ⏭️  mistakes-learned.md already exists, skipping"
fi

# --- skill-improvements.md ---
if [ ! -f "$MEMORY_DIR/skill-improvements.md" ]; then
  cat > "$MEMORY_DIR/skill-improvements.md" << 'EOF'
# Skill & Code Improvements 🔧

Queue improvements here. Daily evolution cron will execute them.

## Queued

<!-- Format:
- [ ] target: <file/skill> | issue: <description> | fix: <proposed solution>
-->

## Completed

<!-- Completed items move here with date:
- [x] target: <file/skill> | issue: <what> | fix: <done> ✅ (YYYY-MM-DD)
-->

---
EOF
  echo "  ✅ Created skill-improvements.md"
else
  echo "  ⏭️  skill-improvements.md already exists, skipping"
fi

echo ""
echo "🎉 Self-evolution system ready!"
echo ""
echo "Next steps:"
echo "  1. Set up daily cron job (e.g. every night at 23:00)"
echo "  2. Set up weekly cron job (e.g. Sunday at 10:00)"
echo "  3. Add real-time capture hooks to AGENTS.md"
echo "  4. See SKILL.md for full instructions"


Security scan verdicts — ClawScan: suspicious | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (CRITICAL)