Learning engine

From Miosa-osa/canopy · View interactive version

Learning engine is an AI agent skill from the GitHub repository Miosa-osa/canopy. Self-learning system based on SICA, VIGIL, and Mem0 patterns. Auto-triggers after task completion. Captures patterns, consolidates memory, generates skills, recovers from errors.

How to use this skill

Skill file

Learning Engine v4.0 (Self-Learning Core)

Overview

The learning engine implements a continuous self-improvement loop:

OBSERVE → REFLECT → PROPOSE → TEST → INTEGRATE
   ↓         ↓         ↓        ↓        ↓
Capture   Analyze   Generate   Rank    Accept if
metrics   failures  options    by      beneficial
& traces  & gaps             merit

Self-Learning Loop (SICA Pattern)

1. Observe

2. Reflect

3. Propose

4. Test

5. Integrate

Quick Classification

After task completion, classify:

  1. Task Type: feature | bug | refactor | test | docs | research | security
  2. Domain: frontend | backend | database | devops | security | ai-ml | orchestration
  3. Complexity: simple | moderate | complex | critical
  4. Agent Used: Record which agent handled the task
  5. Outcome: success | partial | failed | escalated
  6. Learning Value: low | medium | high (errors are high value)

Memory Architecture (Three-Tier)

Tier 1: Working Memory

Tier 2: Episodic Memory

Tier 3: Semantic Memory

Consolidation Process (Mem0 Pattern)

Run periodically (after 5 interactions or end of session):

python3 ~/.claude/skills/learning-engine/scripts/consolidate-memory.py

Operations:

Dynamic Skill Generation (ReCreate Pattern)

When patterns repeat 5+ times:

python3 ~/.claude/skills/learning-engine/scripts/generate-skill.py

Generated skills stored in ~/.claude/skills/generated/ with:

Error Recovery (VIGIL Pattern)

Error taxonomy with recovery strategies:

| Error Type | Severity | Recovery |

|------------|----------|----------|

| file_not_found | recoverable | Check path, use Glob |

| permission_denied | recoverable | Check permissions |

| syntax_error | recoverable | Review code, validate syntax |

| import_error | recoverable | Install dependency |

| type_error | recoverable | Check signatures |

| network_error | transient | Retry, check connectivity |

| timeout_error | transient | Increase timeout, chunk work |

Gap Detection Signals

When a gap is detected:

  1. Log to ~/.claude/learning/gaps/
  2. Suggest agent creation
  3. Track for pattern emergence

Storage Structure

~/.claude/learning/
├── episodes/           # Episodic memory (by date)
│   └── YYYY-MM-DD-episodes.jsonl
├── semantic/           # Semantic memory (consolidated)
│   ├── facts.jsonl
│   ├── patterns.jsonl
│   └── decisions.jsonl
├── patterns/           # Extracted patterns (by domain)
│   ├── go/
│   ├── typescript/
│   └── general/
├── solutions/          # Problem-solution pairs
│   ├── error_resolution/
│   └── feature_implementation/
├── gaps/               # Detected capability gaps
│   └── index.json
├── metrics/            # Usage statistics
│   └── index.json
├── errors/             # Error log for VIGIL
│   └── error-log.jsonl
└── consolidated/       # Consolidation history
    └── consolidation-log.jsonl

Pattern Storage Format

{
  "id": "auth-jwt-refresh",
  "domain": "backend",
  "type": "code_pattern",
  "title": "JWT Token Refresh",
  "description": "Pattern for refreshing expired JWT tokens",
  "code_snippet": "...",
  "tags": ["auth", "jwt", "security"],
  "usage_count": 5,
  "success_rate": 0.9,
  "confidence": 0.85,
  "created": "2026-01-15",
  "last_used": "2026-01-26",
  "hash": "abc123def456"
}

Hooks Integration

learning-capture.py (PostToolUse)

error-recovery.py (PostToolUse)

telemetry-collector.py (PostToolUse)

context-optimizer.py (PreToolUse)

Commands

# Run memory consolidation
python3 ~/.claude/skills/learning-engine/scripts/consolidate-memory.py

# Generate skills from patterns
python3 ~/.claude/skills/learning-engine/scripts/generate-skill.py

# View learning metrics
cat ~/.claude/learning/metrics/index.json | jq .

# View recent episodes
tail -20 ~/.claude/learning/episodes/$(date +%Y-%m-%d)-episodes.jsonl | jq .

# View error log
tail -20 ~/.claude/learning/errors/error-log.jsonl | jq .

Performance Targets

| Metric | Target | Measurement |

|--------|--------|-------------|

| Pattern Extraction | 80%+ success rate | patterns with usage_count > 3 |

| Memory Consolidation | <500ms latency | consolidation run time |

| Skill Generation | 70%+ confidence | generated skill confidence |

| Error Recovery | 60%+ auto-resolution | errors with recovery applied |

| Gap Detection | 90%+ coverage | detected vs undetected gaps |

Advanced Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.