|
1 | 1 | --- |
2 | 2 | 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. |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # Continual Learning for AI Coding Agents |
7 | 7 |
|
8 | | -## Core Concept |
| 8 | +Your agent forgets everything between sessions. Continual learning fixes that. |
9 | 9 |
|
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 |
11 | 11 |
|
12 | 12 | ``` |
13 | 13 | Experience → Capture → Reflect → Persist → Apply |
| 14 | + ↑ │ |
| 15 | + └───────────────────────────────────────┘ |
14 | 16 | ``` |
15 | 17 |
|
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 |
52 | 19 |
|
| 20 | +Install the hook (one step): |
53 | 21 | ```bash |
54 | 22 | cp -r hooks/continual-learning .github/hooks/ |
55 | | -chmod +x .github/hooks/continual-learning/scripts/*.sh |
56 | 23 | ``` |
57 | 24 |
|
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 |
62 | 33 |
|
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 |
64 | 38 |
|
65 | | -Use the agent's built-in memory tools for higher-quality learnings: |
| 39 | +## How Learnings Get Stored |
66 | 40 |
|
| 41 | +### Automatic (via hooks) |
| 42 | +The hook observes tool outcomes and detects failure patterns: |
67 | 43 | ``` |
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 |
74 | 46 | ``` |
75 | 47 |
|
| 48 | +### Agent-native (via store_memory / SQL) |
| 49 | +The agent can write learnings directly: |
76 | 50 | ```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'); |
80 | 53 | ``` |
81 | 54 |
|
82 | | -### Memory File Pattern |
83 | | - |
84 | | -Create a living knowledge base the agent reads on startup: |
| 55 | +Categories: `pattern`, `mistake`, `preference`, `tool_insight` |
85 | 56 |
|
| 57 | +### Manual (memory files) |
| 58 | +For human-readable, version-controlled knowledge: |
86 | 59 | ```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= |
100 | 63 | ``` |
101 | 64 |
|
102 | | -### The Diary Pattern (Advanced) |
| 65 | +## Compaction |
103 | 66 |
|
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 |
105 | 71 |
|
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. |
110 | 73 |
|
111 | 74 | ## Best Practices |
112 | 75 |
|
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 |
0 commit comments