Self-reflection + correction logging + tiered memory + WAL protocol + cold-boot recovery + automated daily review cron in one system. No API keys required. File-based. Works with existing OpenClaw memory (MEMORY.md, memory/) without overwriting anything.
init detects non-persistent storage and auto-symlinks to /data/ if available.agent_memory.py dry-run simulates a daily review without modifying files. Test before the cron fires.init automatically injects SOUL.md, AGENTS.md, and HEARTBEAT.md hooks. Creates minimal files if they don't exist. Zero manual steps.agent_memory.py verify checks persistence, directories, hook content, cron, corrections health, and workspace hooks.agent_memory.py cron-prompt outputs the daily review prompt. mark-cron records installation.Two memory systems, complementary — never conflicting:
SystemLocationPurposeOpenClaw nativeMEMORY.md, memory/*.mdFacts, events, decisions, daily logsSelf-improving~/self-improving/Execution quality: corrections, patterns, preferencestext
Workspace (OpenClaw native — skill never overwrites these):
├── MEMORY.md # Long-term curated facts (auto-injected on boot)
├── SESSION-STATE.md # Hot RAM — current task, pending actions
└── memory/
└── YYYY-MM-DD.md # Daily logs (searchable via memory_search)
~/self-improving/ (this skill manages):
├── memory.md # HOT: ≤100 lines, load on every session
├── index.md # Topic index with line counts
├── corrections.md # Last 50 corrections
├── heartbeat-state.md # Maintenance markers
├── projects/ # Per-project learnings
├── domains/ # Domain-specific (code, comms, etc.)
└── archive/ # COLD: decayed patterns
These files are injected into the system prompt automatically:
These require explicit reads by the agent:
memory_searchContent typeStore inFacts, events, decisionsMEMORY.md (OpenClaw native)Daily work logmemory/YYYY-MM-DD.mdCurrent task + session stateSESSION-STATE.mdCorrections and mistakes~/self-improving/corrections.mdConfirmed preferences/rules~/self-improving/memory.mdProject-specific patterns~/self-improving/projects/{name}.mdDomain patterns (code, comms)~/self-improving/domains/{name}.md
This is what makes v3 work. A nightly cron job forces a full review and .md rewrite cycle. The agent doesn't need to "remember" to do it — the cron makes it mandatory.
The cron is created automatically during agent_memory.py init. If you need to recreate it:
bash
python3 ./skills/self-improving/scripts/agent_memory.py cron-prompt
This outputs the prompt text. Create a cron job with:
v2 relied on the agent following WAL protocol and writing lessons during work. In practice, agents skip this on context resets — the protocols are in SOUL.md but behavioral compliance is unreliable. The cron is a forcing function: even if the agent forgets to log lessons during the day, the nightly review catches everything.
This is the most important runtime section. On any restart, context reset, or new session:
text
Read SESSION-STATE.md → know what you were just doing
This file is your "hot RAM." It tells you: current task, pending actions, recent decisions. Without it, you're amnesiac about recent work.
text
Read ~/self-improving/memory.md → know your learned patterns
This is your corrections/preferences tier. Small file (≤100 lines). Contains confirmed rules and recent lessons.
text
memory_search("relevant query") → find context in daily logs
Daily logs (memory/YYYY-MM-DD.md) are NOT loaded by default. Use memory_search to find them.
MEMORY.md auto-loads and covers ~90% of long-term facts. But SESSION-STATE.md and self-improving/memory.md cover the remaining ~10%: what you were JUST doing and what MISTAKES you've learned from. Skipping them means repeating errors or losing task context.
Write state BEFORE responding. If you crash/compact after responding but before saving, context is lost. WAL prevents this.
The daily review cron is a safety net, but WAL is still best practice for high-value lessons you don't want to risk losing.
TriggerWrite toThenUser states preference~/self-improving/memory.mdRespondUser makes decisionSESSION-STATE.mdRespondUser corrects you~/self-improving/corrections.mdRespondUser gives deadlineSESSION-STATE.mdRespondSignificant task completedmemory/YYYY-MM-DD.mdRespondAbout to lose context (compaction)memory/YYYY-MM-DD.mdLet compaction proceed
Lives in workspace root. Survives compaction, restarts, context loss. Read first every session, update every cycle.
markdown
# SESSION-STATE.md — Active Working Memory
## Current Task
[What we're working on RIGHT NOW]
## Key Context
[Critical facts for current work]
## Pending Actions
- [ ] ...
## Recent Decisions
[Decisions made this session]
---
*Last updated: [timestamp]*
Update discipline:
Log immediately → corrections.md, evaluate for memory.md:
Log if explicit → memory.md:
Track, promote after 3x:
Ignore (don't log):
After completing significant work, pause and evaluate:
text
CONTEXT: [type of task]
REFLECTION: [what I noticed]
LESSON: [what to do differently]
TierLocationLimitBehaviorHOT~/self-improving/memory.md≤100 linesRead on session start + before non-trivial workWARMprojects/, domains/≤200 lines eachLoad on context matchCOLDarchive/UnlimitedLoad on explicit query only
Never overwrite existing files. Add sections, don't replace.
SOUL.md — add:
markdown
## Self-Improving
On EVERY new session or context reset, IMMEDIATELY:
1. Read SESSION-STATE.md and ~/self-improving/memory.md before doing anything else.
2. VERIFY the daily review cron exists: use the cron tool (action=list) and look for "Self-Improving Daily Review". If it does NOT exist, CREATE IT NOW:
- name: "Self-Improving Daily Review + .md Rewrite"
- schedule: cron "0 23 * * *" in user's timezone
- sessionTarget: isolated
- payload: agentTurn with the review prompt (run: python3 ./skills/self-improving/scripts/agent_memory.py cron-prompt)
- Do NOT set a model — use the default
- delivery: announce
After creating, run: python3 ./skills/self-improving/scripts/agent_memory.py mark-cron
This is NON-NEGOTIABLE. The skill does not work without this cron.
3. When the user corrects you or you learn something reusable, IMMEDIATELY write to ~/self-improving/corrections.md BEFORE responding (WAL protocol). The nightly cron reviews corrections.md — if nothing is written during the day, the cron has nothing to promote. WAL is what feeds the cron.
4. Prefer learned rules when relevant. Keep self-inferred rules revisable.
AGENTS.md — add to Memory section:
markdown
- **Self-improving:** ~/self-improving/ — execution-quality memory (preferences, patterns, corrections)
- Use MEMORY.md / memory/ for factual continuity. Use ~/self-improving/ for compounding execution quality.
HEARTBEAT.md — add:
markdown
## Self-Improving Check
- Read ./skills/self-improving/heartbeat-rules.md
- Use ~/self-improving/heartbeat-state.md for run markers
- If no file in ~/self-improving/ changed since last review, skip maintenance
Index ~/self-improving/ in memory search so corrections and patterns are discoverable via memory_search:
json5
{
agents: {
defaults: {
memorySearch: {
extraPaths: ["~/self-improving"]
}
}
}
}
User saysAction"What do you know about X?"Search all tiers for X"What have you learned?"Show last 10 from corrections.md"Show my patterns"List memory.md (HOT)"Show [project] patterns"Load projects/{name}.md"Memory stats"Run agent_memory.py stats"Forget X"Remove from all tiers (confirm first)"Forget everything"Export → wipe → confirm
TrapWhy It FailsBetter MoveSkipping SESSION-STATE.md on bootLose context of what you were doingALWAYS read it firstLearning from silenceCreates false rulesWait for explicit correction or 3x evidencePromoting too fastPollutes HOT memoryKeep tentative until confirmedReading every namespaceWastes contextLoad only HOT + smallest matching filesCompaction by deletionLoses trust/historyMerge, summarize, or demote insteadOverwriting workspace filesDestroys existing contextComplement, never replaceNot writing before respondingCrash = lost contextWAL: always write firstEmpty memory bootstrapNo feedback loop formsv3 seeds memory.md on initNo forcing functionAgent skips reviews after resetsv3 daily cron forces it
One command. Zero manual steps.
bash
python3 ./skills/self-improving/scripts/agent_memory.py init
This does everything:
The SOUL.md hook then auto-creates the daily review cron on the next session start. No manual cron setup needed.
Verify everything is working:
bash
python3 ./skills/self-improving/scripts/agent_memory.py verify
Test what the nightly cron would do:
bash
python3 ./skills/self-improving/scripts/agent_memory.py dry-run
references/learning.mdreferences/boundaries.mdreferences/scaling.mdreferences/operations.mdheartbeat-rules.mdThis skill ONLY:
This skill NEVER: