Install
openclaw skills install learning-loopStructured self-improvement system for AI agents with confidence decay, cross-agent sharing, and anomaly detection. Use when: (1) After debugging sessions to capture lessons learned, (2) When receiving feedback or corrections from users, (3) Before risky actions to check relevant rules, (4) Weekly to review metrics and promote proven patterns to enforced rules, (5) Setting up persistent memory that survives session compactions.
openclaw skills install learning-loopStop waking up stupid.
AI agents lose everything on compaction. Every debugging session, every hard-won lesson, every correction from your human - gone. You start fresh and repeat the same failures. Your human notices. Trust erodes.
The Learning Loop is a structured self-improvement system that gives agents persistent, compounding intelligence. It captures what you learn, promotes proven patterns into hard rules, tracks your improvement over time, detects when your human is satisfied or frustrated - automatically, and now includes confidence decay and cross-agent knowledge sharing.
This isn't a toy. This is infrastructure for agents that want to get measurably better at their job, every single session.
┌─────────────────────────────────────────────────────────────┐
│ LEARNING LOOP v1.4.0 │
├─────────────────────────────────────────────────────────────┤
│ │
│ INPUT LAYER PROCESSING LAYER OUTPUT LAYER │
│ ─────────── ──────────────── ──────────── │
│ │
│ Events ──────────▶ Pattern Detection ────▶ Reports │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ lessons.json Confidence Decay Rules │
│ │ │ │ │
│ ▼ ▼ ▼ │
│ Promotion ◀────── Anomaly Detection ◀────── Enforcement │
│ │
│ CROSS-AGENT LAYER: │
│ Export ─────▶ Portable Format ─────▶ Import │
│ │
└─────────────────────────────────────────────────────────────┘
Data Flow:
Confidence Decay: Rules lose confidence over time using Ebbinghaus-inspired exponential decay. Stale rules (confidence < 0.5) are flagged for review.
Cross-Agent Sharing: Export rules as portable JSON with metadata (hashes, provenance). Import from other agents with conflict detection and trust scoring.
Use the Learning Loop when:
Events (raw) --> Lessons (structured) --> Rules (enforced)
append-only proven patterns hard constraints
events.jsonl lessons.json rules.json
Three-tier knowledge system:
Five enforcement layers ensure learning happens even when discipline fails:
No single layer is critical. If one fails, the others catch it.
bash init.sh /path/to/workspace
That's it. You now have:
memory/learning/
├── events.jsonl # Raw event log (append-only)
├── rules.json # Hard behavioral rules (3 starter rules)
├── lessons.json # Structured lessons (intermediate tier)
├── pre-action-checklist.md # Check before risky actions
├── metrics.json # Improvement tracking
├── BOOT.md # Quick reference for session boot
├── parse-errors.jsonl # JSON parsing errors (v1.4.0)
└── weekly/ # Weekly learning reports
Add to your agent's boot instructions (AGENTS.md or equivalent):
## Every Session
1. Read `memory/learning/rules.json` - hard behavioral rules
2. Read `memory/learning/BOOT.md` - quick reference
3. Before risky actions, check `memory/learning/pre-action-checklist.md`
4. After mistakes or debugging, append to `memory/learning/events.jsonl`
5. Check rule confidence scores - rules with < 0.5 confidence need review
Daily (e.g. 4am):
bash extract.sh /path/to/workspace
Weekly (e.g. Sunday 10pm):
bash detect-patterns.sh /path/to/workspace
bash confidence-decay.sh /path/to/workspace # NEW v1.4.0
bash promote-rules.sh /path/to/workspace
bash self-audit.sh /path/to/workspace
bash update-metrics.sh /path/to/workspace
If your platform supports custom compaction prompts, add:
"Append uncaptured learning events to memory/learning/events.jsonl and update rules.json if new rules emerged."
This is the safety net that catches learning even during context compression.
DO:
DON'T:
Here's the complete loop in action, from first mistake to enforced rule.
You're building a skill and run find . -not -path '*/node_modules/*' on macOS. It silently skips files. You spend 20 minutes debugging before discovering that extended attributes break find's exclusion flags.
Capture the event:
{"ts":"2026-02-07T15:00:00Z","type":"debug_session","category":"shell","tags":["macos","find","xattr"],"problem":"find -not -path silently skips files with com.apple.provenance on macOS","solution":"Pipe find output through grep -v instead of using find built-in exclusion flags","confidence":"proven","source":"skill-build"}
Append that line to events.jsonl. Done. The knowledge is captured.
The daily extraction cron runs extract.sh, which scans your session logs and flags patterns. You (or the weekly cron) extract a structured lesson:
{
"id": "L-001",
"created": "2026-02-09",
"category": "shell",
"lesson": "On macOS, use grep -v piping instead of find -not -path for file filtering",
"context": "Extended attributes cause find exclusion flags to silently skip files",
"trigger": "Any find command with -not -path on macOS",
"action": "Replace find ... -not -path X with: find ... | grep -v X",
"confidence": "proven",
"confidence_score": 0.9,
"times_applied": 0,
"times_saved": 0,
"source_events": ["2026-02-07T15:00:00Z"]
}
Add it to lessons.json. Now it's structured and trackable.
Three more times you need to filter files on macOS. Each time, your boot sequence loaded the rules. Each time, you use grep -v instead of find -not -path. Each time, you increment times_applied in the lesson.
The weekly cron runs promote-rules.sh. It finds L-001 with 3+ applications and confidence >= 0.9, and auto-promotes it:
{
"id": "R-004",
"type": "NEVER",
"category": "shell",
"rule": "Never use find -not -path or find ! -path on macOS. Always pipe through grep -v instead.",
"reason": "com.apple.provenance extended attributes cause find exclusions to silently skip files",
"created": "2026-02-21",
"source_lesson": "L-001",
"violations": 0,
"last_checked": "2026-02-21",
"last_validated": "2026-02-21",
"validation_count": 0,
"confidence_score": 0.9
}
Now it's a hard rule. Loaded at boot. Checked before action. The mistake can never happen again.
After 30 days without validation, confidence-decay.sh runs and applies exponential decay:
R-004: 0.90 → 0.22 (30 days since validation)
The rule is now flagged for review. You validate it again by successfully applying it, and the confidence resets to 0.9.
update-metrics.sh tracks the trend:
self-audit.sh scores your loop health: 100% means everything is wired correctly.
That's the full cycle. Raw experience becomes structured knowledge becomes enforced behavior. Compounding intelligence.
See references/script-reference.md for detailed script documentation.
| Script | Purpose | Schedule |
|---|---|---|
init.sh | Initialize directory structure | Once |
extract.sh | Scan logs for uncaptured events | Daily |
detect-patterns.sh | Tag clusters, regressions, anomalies (v1.4.0) | Weekly |
confidence-decay.sh | Apply Ebbinghaus decay to confidence scores (v1.4.0) | Weekly |
export-rules.sh | Export rules for cross-agent sharing (v1.4.0) | Manual |
import-rules.sh | Import rules with conflict detection (v1.4.0) | Manual |
promote-rules.sh | Promote lessons to rules | Daily/Weekly |
self-audit.sh | Health score (23 checks, A-D) | Weekly |
update-metrics.sh | Weekly metrics snapshot | Daily/Weekly |
feedback-detector.sh | Detect human signals | Per-message |
track-violations.sh | Link mistakes to rules | Daily |
track-applications.sh | Track lesson applications | Daily |
rule-check.sh | Dynamic rule lookup | On-demand |
archive-events.sh | Roll off old events | Monthly |
wal-capture.sh | Write-Ahead Log capture | Per-message |
inject-rules.sh | Inject rules into agent context | On-demand |
All scripts accept workspace directory as first argument. Default is current directory.
See references/formats.md for event and rule JSON schemas.
5 event types: mistake, success, debug_session, feedback, discovery 4 rule types: MUST, NEVER, PREFER, CHECK
{
"id": "R-001",
"type": "MUST|NEVER|PREFER|CHECK",
"category": "shell|auth|memory|...",
"rule": "The behavioral constraint",
"reason": "Why this rule exists",
"created": "2026-02-21",
"source_lesson": "L-001",
"violations": 0,
"last_checked": "2026-02-21",
"last_validated": "2026-02-21", // NEW v1.4.0
"validation_count": 0, // NEW v1.4.0
"confidence_score": 0.9, // NEW v1.4.0
"review_flagged": false // NEW v1.4.0
}
Share learned rules between agents:
Export rules:
# Export all rules
bash export-rules.sh /path/to/workspace --output my-rules.json
# Export only shell rules
bash export-rules.sh /path/to/workspace --category shell --output shell-rules.json
Import rules:
# Preview import
bash import-rules.sh /path/to/workspace other-agent-rules.json --dry-run
# Import with custom trust threshold
bash import-rules.sh /path/to/workspace other-agent-rules.json --trust 0.8
# Import all rules above default threshold (0.5)
bash import-rules.sh /path/to/workspace other-agent-rules.json
Features:
Symptoms: Scripts report JSON parse errors, metrics show fewer events than expected.
Solution:
parse-errors.jsonl for details on corrupted linescp events.jsonl events.jsonl.backuppython3 -c "
import json
with open('events.jsonl') as f:
for line in f:
line = line.strip()
if line:
try:
json.loads(line)
print(line)
except:
pass
" > events.jsonl.fixed
mv events.jsonl.fixed events.jsonl
init.shSymptoms: Agent repeats mistakes that have rules, rules.json is never read.
Solution:
python3 -c "import json; json.load(open('rules.json'))"Read memory/learning/rules.jsonls -la memory/learning/rules.json.lockfile exists, another process may be stuckSymptoms: JSON lines are being skipped, data loss occurring.
Solution:
cat memory/learning/parse-errors.jsonl> memory/learning/parse-errors.jsonlSymptoms: Scripts exit with "Could not acquire lock" error.
Solution:
lsof memory/learning/.lockfilekill <pid>rm memory/learning/.lockfileSymptoms: All rules show confidence 0.9, no decay applied.
Solution:
last_validated field exists in rules (v1.4.0 schema)init.sh to backfill missing fieldsconfidence-decay.sh is in your weekly cronSymptoms: Import reports conflicts, rules not imported.
Solution:
--trust 0.9 to force review modeSee references/customization.md for tuning feedback patterns, categories, promotion thresholds, and pre-action checklists.
See references/changelog.md for version history.
Current: v1.4.0 (Confidence decay, cross-agent sharing, anomaly detection, parse error logging)
python3 3.8+ and bashflock (usually part of util-linux, available on macOS via util-linux or coreutils)memory/ for file storageNo external APIs. No dependencies beyond Python and Bash. Runs anywhere.
Most agents are goldfish with tool access. They solve the same problem five times and charge you for each one. The Learning Loop breaks that cycle by treating every session as training data for the next one.
Build it once. Let it compound. Get measurably better every week.
Share what you learn. Import what others discovered. Collective intelligence beats isolated learning.