Skip to content

Commit 6737dcb

Browse files
committed
refactor: simplify continual learning hook — single script, two-tier memory, auto-init
Redesign inspired by beads' invariants: one-step setup, zero config, structured data. - Replace 3 scripts with single learn.sh handling all lifecycle events - Two-tier memory: global (~/.copilot/learnings.db) + local (.copilot-memory/) - Auto-initializes DBs and directories on first run - Compaction: old low-value learnings decay (60-day TTL), tool logs pruned (7 days) - Install is one step: cp -r hooks/continual-learning .github/hooks/ - Simplified README and SKILL.md to match
1 parent dc9f676 commit 6737dcb

File tree

9 files changed

+257
-398
lines changed

9 files changed

+257
-398
lines changed
Lines changed: 44 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,79 @@
11
---
22
name: continual-learning
3-
description: Guide for implementing continual learning in AI coding agents — hooks, memory files, reflection patterns, and session persistence. Use when setting up learning infrastructure for agents.
3+
description: Guide for implementing continual learning in AI coding agents — hooks, memory scoping, reflection patterns. Use when setting up learning infrastructure for agents.
44
---
55

66
# Continual Learning for AI Coding Agents
77

8-
## Core Concept
8+
Your agent forgets everything between sessions. Continual learning fixes that.
99

10-
Continual learning enables AI coding agents to improve across sessions by capturing corrections, reflecting on patterns, and persisting knowledge. Instead of starting each session from scratch, agents build on accumulated experience.
10+
## The Loop
1111

1212
```
1313
Experience → Capture → Reflect → Persist → Apply
14+
↑ │
15+
└───────────────────────────────────────┘
1416
```
1517

16-
## The Learning Loop
17-
18-
### 1. Capture (During Session)
19-
20-
Track corrections, tool outcomes, and user feedback as they happen:
21-
- User corrections: "no, use X not Y", "actually...", "that's wrong"
22-
- Tool failures: repeated failures on the same tool indicate a pattern
23-
- Successful patterns: approaches that worked well
24-
25-
### 2. Reflect (Session End)
26-
27-
At session end, synthesize raw observations into actionable learnings:
28-
- Abstract the general principle (not just the specific instance)
29-
- Determine scope: project-specific or global?
30-
- Check for conflicts with existing rules
31-
32-
### 3. Persist (To Storage)
33-
34-
Store learnings in one or more of:
35-
- **SQLite database** (`~/.copilot/continual-learning.db`) — structured, queryable
36-
- **Memory file** (`.github/memory/learnings.md`) — human-readable, version-controlled
37-
- **Agent memory tools** (`store_memory`, `sql` session store) — agent-native persistence
38-
39-
### 4. Apply (Next Session)
40-
41-
On session start, load accumulated context:
42-
- Query session store for recent project history
43-
- Read persisted learnings from database
44-
- Surface memory file content
45-
- Agent starts with full context of past work
46-
47-
## Implementation Patterns
48-
49-
### Hook-Based (Infrastructure Layer)
50-
51-
Install the `continual-learning` hook set for automatic capture and reflection:
18+
## Quick Start
5219

20+
Install the hook (one step):
5321
```bash
5422
cp -r hooks/continual-learning .github/hooks/
55-
chmod +x .github/hooks/continual-learning/scripts/*.sh
5623
```
5724

58-
This provides:
59-
- `sessionStart` → loads past learnings
60-
- `postToolUse` → tracks tool outcomes
61-
- `sessionEnd` → reflects and persists
25+
Auto-initializes on first session. No config needed.
26+
27+
## Two-Tier Memory
28+
29+
**Global** (`~/.copilot/learnings.db`) — follows you across all projects:
30+
- Tool patterns (which tools fail, which work)
31+
- Cross-project conventions
32+
- General coding preferences
6233

63-
### Agent-Native (Intelligence Layer)
34+
**Local** (`.copilot-memory/learnings.db`) — stays with this repo:
35+
- Project-specific conventions
36+
- Common mistakes for this codebase
37+
- Team preferences
6438

65-
Use the agent's built-in memory tools for higher-quality learnings:
39+
## How Learnings Get Stored
6640

41+
### Automatic (via hooks)
42+
The hook observes tool outcomes and detects failure patterns:
6743
```
68-
# Using the store_memory tool
69-
store_memory(
70-
subject="error handling",
71-
fact="This project uses Result<T> pattern, not exceptions",
72-
category="general"
73-
)
44+
Session 1: bash tool fails 4 times → learning stored: "bash frequently fails"
45+
Session 2: hook surfaces that learning at start → agent adjusts approach
7446
```
7547

48+
### Agent-native (via store_memory / SQL)
49+
The agent can write learnings directly:
7650
```sql
77-
-- Using the SQL session database
78-
INSERT INTO session_state (key, value)
79-
VALUES ('learned_pattern', 'Always use async/await for Azure SDK calls');
51+
INSERT INTO learnings (scope, category, content, source)
52+
VALUES ('local', 'convention', 'This project uses Result<T> not exceptions', 'user_correction');
8053
```
8154

82-
### Memory File Pattern
83-
84-
Create a living knowledge base the agent reads on startup:
55+
Categories: `pattern`, `mistake`, `preference`, `tool_insight`
8556

57+
### Manual (memory files)
58+
For human-readable, version-controlled knowledge:
8659
```markdown
87-
# .github/memory/learnings.md
88-
89-
## Conventions
90-
- Use `DefaultAzureCredential` for all Azure auth
91-
- Prefer `create_or_update_*` for idempotent operations
92-
93-
## Common Mistakes
94-
- Don't use `azure-ai-inference` for Foundry agents — use `azure-ai-projects`
95-
- The `search()` parameter is `semantic_configuration_name`, not `semantic_configuration`
96-
97-
## Preferences
98-
- User prefers concise commit messages (50 char limit)
99-
- Always run tests before committing
60+
# .copilot-memory/conventions.md
61+
- Use DefaultAzureCredential for all Azure auth
62+
- Parameter is semantic_configuration_name=, not semantic_configuration=
10063
```
10164

102-
### The Diary Pattern (Advanced)
65+
## Compaction
10366

104-
For deeper reflection across multiple sessions:
67+
Learnings decay over time:
68+
- Entries older than 60 days with low hit count are pruned
69+
- High-value learnings (frequently referenced) persist indefinitely
70+
- Tool logs are pruned after 7 days
10571

106-
1. **Log sessions** — Save session summaries with decisions, challenges, outcomes
107-
2. **Cross-reference** — Identify patterns across sessions (recurring mistakes, preferences)
108-
3. **Synthesize** — Convert patterns into rules
109-
4. **Prune** — Remove redundant or outdated learnings
72+
This prevents unbounded growth while preserving what matters.
11073

11174
## Best Practices
11275

113-
1. **Start simple** — Begin with the hook set, add agent-native memory later
114-
2. **Be specific** — "Use `semantic_configuration_name=`" is better than "use the right parameter"
115-
3. **Scope learnings** — Mark whether something is project-specific or global
116-
4. **Prune regularly** — Outdated learnings cause more harm than no learnings
117-
5. **Don't log secrets** — Only store tool names, result types, and abstract patterns
118-
6. **Compound over time** — Small improvements per session create exponential gains
76+
1. **One step to install** — if it takes more than `cp -r`, it won't get adopted
77+
2. **Scope correctly** — global for tool patterns, local for project conventions
78+
3. **Be specific**`"Use semantic_configuration_name="` beats `"use the right parameter"`
79+
4. **Let it compound** — small improvements per session create exponential gains over weeks

docs-site/src/data/skills.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@
932932
},
933933
{
934934
"name": "continual-learning",
935-
"description": "Guide for implementing continual learning in AI coding agents — hooks, memory files, reflection patterns, and session persistence. Use when setting up learning infrastructure for agents.",
935+
"description": "Guide for implementing continual learning in AI coding agents — hooks, memory scoping, reflection patterns. Use when setting up learning infrastructure for agents.",
936936
"lang": "core",
937937
"category": "general",
938938
"path": ".github/skills/continual-learning"

docs/index.html

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

hooks/continual-learning/README.md

Lines changed: 42 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,117 +6,70 @@ tags: ['learning', 'memory', 'reflection', 'productivity', 'featured']
66

77
# Continual Learning Hook
88

9-
Enable your AI coding agent to learn from every session. This hook set implements the **continual learning loop** — capturing tool outcomes, reflecting on patterns, and persisting knowledge so each session starts smarter than the last.
9+
Your agent forgets everything between sessions. This hook fixes that.
1010

11-
## The Problem
11+
## Quick Start
1212

13-
AI coding agents start every session from scratch. You correct them, they adapt — then the session ends and the knowledge is lost. Next session: same mistakes, same corrections, infinite loop.
14-
15-
## The Solution
16-
17-
```
18-
Experience → Capture → Reflect → Persist → Apply
13+
```bash
14+
cp -r hooks/continual-learning .github/hooks/
1915
```
2016

21-
This hook set closes the loop by:
22-
23-
1. **Loading context** at session start — past session summaries, accumulated learnings
24-
2. **Tracking outcomes** during the session — which tools succeed, which fail
25-
3. **Reflecting** at session end — analyzing patterns, identifying repeated failures
26-
4. **Persisting** learnings to a SQLite database and optional memory file
27-
28-
## How It Works
29-
30-
### Session Start (`load-session-start.sh`)
31-
- Queries `~/.copilot/session-store.db` for recent sessions in the current project
32-
- Loads accumulated learnings from `~/.copilot/continual-learning.db`
33-
- Surfaces the local `.github/memory/learnings.md` file if present
17+
That's it. The hook auto-initializes on first session — no config, no setup, no manual steps.
3418

35-
### During Session (`track-tool-use.sh`)
36-
- Records every tool invocation and its result (success/failure)
37-
- Builds a tool usage history in `~/.copilot/continual-learning.db`
38-
- Lightweight — adds <5ms per tool call
19+
## What It Does
3920

40-
### Session End (`reflect-session-end.sh`)
41-
- Analyzes tool outcomes: total usage, failure rate, top tools
42-
- Detects repeated failure patterns (same tool failing multiple times)
43-
- Persists failure patterns as learnings
44-
- Appends a session summary to `.github/memory/learnings.md`
45-
- Cleans up data older than 7 days
21+
- **Session start** — Loads learnings from previous sessions (global + this repo)
22+
- **During session** — Tracks tool outcomes silently
23+
- **Session end** — Reflects on patterns, stores insights, compacts old data
4624

47-
## Installation
25+
## Two-Tier Memory
4826

49-
1. Copy the hook folder to your repository:
50-
```bash
51-
cp -r hooks/continual-learning .github/hooks/
52-
```
27+
| Scope | Location | What goes here |
28+
|-------|----------|----------------|
29+
| **Global** | `~/.copilot/learnings.db` | Tool patterns, cross-project insights |
30+
| **Local** | `.copilot-memory/learnings.db` | Repo conventions, project-specific mistakes |
5331

54-
2. Ensure scripts are executable:
55-
```bash
56-
chmod +x .github/hooks/continual-learning/scripts/*.sh
57-
```
32+
Global learnings follow you everywhere. Local learnings stay with the project.
5833

59-
3. Optionally create a memory file for project-specific learnings:
60-
```bash
61-
mkdir -p .github/memory
62-
echo "# Project Learnings" > .github/memory/learnings.md
63-
```
34+
Both auto-create on first run. Local memory only activates inside a git repo.
6435

65-
4. Commit to your repository's default branch.
36+
## How It Compounds
6637

67-
## Configuration
38+
| Time | Effect |
39+
|------|--------|
40+
| Day 1 | Agent starts fresh — hook begins observing |
41+
| Week 2 | Failure patterns detected, surfaced at session start |
42+
| Month 2 | Rich context loaded — agent avoids known pitfalls |
6843

69-
| Variable | Default | Description |
70-
|----------|---------|-------------|
71-
| `SKIP_CONTINUAL_LEARNING` | unset | Set to `true` to disable entirely |
72-
| `MEMORY_FILE` | `.github/memory/learnings.md` | Path to the project memory file |
44+
Old low-value learnings decay automatically (60-day TTL, low hit count). High-value learnings persist and rank higher.
7345

74-
## Database Schema
46+
## Adding Learnings Manually
7547

76-
The hook creates `~/.copilot/continual-learning.db` with two tables:
48+
The agent can also write learnings directly using its built-in `store_memory` tool or SQL:
7749

7850
```sql
79-
-- Tool invocation history (auto-cleaned after 7 days)
80-
CREATE TABLE tool_outcomes (
81-
id INTEGER PRIMARY KEY AUTOINCREMENT,
82-
session_id TEXT,
83-
tool_name TEXT,
84-
result_type TEXT,
85-
timestamp INTEGER,
86-
recorded_at TEXT DEFAULT (datetime('now'))
87-
);
88-
89-
-- Persistent learnings extracted from sessions
90-
CREATE TABLE learnings (
91-
id INTEGER PRIMARY KEY AUTOINCREMENT,
92-
category TEXT, -- 'failure_pattern', 'correction', 'preference'
93-
content TEXT, -- The actual learning
94-
source TEXT, -- Where it came from (session ID, timestamp)
95-
created_at TEXT DEFAULT (datetime('now'))
96-
);
51+
-- Agent writes a repo-specific learning
52+
INSERT INTO learnings (scope, category, content, source)
53+
VALUES ('local', 'mistake', 'Use semantic_configuration_name= not semantic_configuration=', 'user_correction');
9754
```
9855

99-
## The Compound Effect
56+
## Architecture
10057

101-
| Week | State |
102-
|------|-------|
103-
| Week 1 | Agent starts fresh each session, repeats mistakes |
104-
| Week 4 | Database has failure patterns, agent avoids known issues |
105-
| Week 12 | Rich history of learnings, agent rarely makes previously-seen mistakes |
58+
```
59+
learn.sh <event> ← Single script handles all lifecycle events
60+
61+
├── sessionStart → Query both DBs, surface top learnings
62+
├── postToolUse → Log tool name + result (3ms overhead)
63+
└── sessionEnd → Analyze patterns, persist insights, compact old data
64+
```
10665

107-
## Combining with Agent Memory
66+
## Disable
10867

109-
If your coding agent supports a `store_memory` tool or similar, the learnings from this hook can inform what the agent persists. The hook provides the **infrastructure** (capture, store, surface) while the agent provides the **intelligence** (deciding what's worth remembering).
68+
```bash
69+
export SKIP_CONTINUAL_LEARNING=true
70+
```
11071

11172
## Requirements
11273

113-
- `sqlite3` for database operations
114-
- `jq` for JSON parsing (optional, gracefully degrades)
115-
- Bash 4+ with standard Unix tools
116-
117-
## Privacy
118-
119-
- Tool outcomes are stored locally in `~/.copilot/continual-learning.db`
120-
- No tool arguments or prompt content is logged — only tool names and result types
121-
- Memory file is project-local and should be in `.gitignore` if sensitive
122-
- All data stays local — no external network calls
74+
- `sqlite3` (pre-installed on macOS and most Linux)
75+
- `jq` (optional — gracefully degrades without it)

hooks/continual-learning/hooks.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
"sessionStart": [
55
{
66
"type": "command",
7-
"bash": ".github/hooks/continual-learning/scripts/load-session-start.sh",
7+
"bash": ".github/hooks/continual-learning/learn.sh sessionStart",
88
"cwd": ".",
9-
"timeoutSec": 10
9+
"timeoutSec": 5
1010
}
1111
],
1212
"postToolUse": [
1313
{
1414
"type": "command",
15-
"bash": ".github/hooks/continual-learning/scripts/track-tool-use.sh",
15+
"bash": ".github/hooks/continual-learning/learn.sh postToolUse",
1616
"cwd": ".",
17-
"timeoutSec": 5
17+
"timeoutSec": 3
1818
}
1919
],
2020
"sessionEnd": [
2121
{
2222
"type": "command",
23-
"bash": ".github/hooks/continual-learning/scripts/reflect-session-end.sh",
23+
"bash": ".github/hooks/continual-learning/learn.sh sessionEnd",
2424
"cwd": ".",
25-
"timeoutSec": 15
25+
"timeoutSec": 10
2626
}
2727
]
2828
}

0 commit comments

Comments
 (0)