agentdb 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -33
- package/dist/cli/agentdb-cli.d.ts +1 -0
- package/dist/cli/agentdb-cli.d.ts.map +1 -1
- package/dist/cli/agentdb-cli.js +108 -134
- package/dist/cli/agentdb-cli.js.map +1 -1
- package/dist/controllers/CausalMemoryGraph.d.ts.map +1 -1
- package/dist/controllers/CausalMemoryGraph.js +3 -3
- package/dist/controllers/CausalMemoryGraph.js.map +1 -1
- package/dist/controllers/CausalRecall.d.ts +25 -0
- package/dist/controllers/CausalRecall.d.ts.map +1 -1
- package/dist/controllers/CausalRecall.js +44 -1
- package/dist/controllers/CausalRecall.js.map +1 -1
- package/dist/controllers/EmbeddingService.d.ts.map +1 -1
- package/dist/controllers/EmbeddingService.js +4 -0
- package/dist/controllers/EmbeddingService.js.map +1 -1
- package/dist/controllers/ExplainableRecall.js +1 -1
- package/dist/controllers/LearningSystem.d.ts +194 -0
- package/dist/controllers/LearningSystem.d.ts.map +1 -0
- package/dist/controllers/LearningSystem.js +929 -0
- package/dist/controllers/LearningSystem.js.map +1 -0
- package/dist/controllers/NightlyLearner.d.ts.map +1 -1
- package/dist/controllers/NightlyLearner.js +9 -1
- package/dist/controllers/NightlyLearner.js.map +1 -1
- package/dist/controllers/ReasoningBank.d.ts +96 -0
- package/dist/controllers/ReasoningBank.d.ts.map +1 -0
- package/dist/controllers/ReasoningBank.js +302 -0
- package/dist/controllers/ReasoningBank.js.map +1 -0
- package/dist/controllers/ReflexionMemory.d.ts.map +1 -1
- package/dist/controllers/ReflexionMemory.js +4 -0
- package/dist/controllers/ReflexionMemory.js.map +1 -1
- package/dist/controllers/SkillLibrary.d.ts +37 -3
- package/dist/controllers/SkillLibrary.d.ts.map +1 -1
- package/dist/controllers/SkillLibrary.js +196 -15
- package/dist/controllers/SkillLibrary.js.map +1 -1
- package/dist/mcp/agentdb-mcp-server.d.ts +8 -0
- package/dist/mcp/agentdb-mcp-server.d.ts.map +1 -0
- package/dist/mcp/agentdb-mcp-server.js +1485 -352
- package/dist/mcp/agentdb-mcp-server.js.map +1 -0
- package/dist/mcp/learning-tools-handlers.d.ts +16 -0
- package/dist/mcp/learning-tools-handlers.d.ts.map +1 -0
- package/dist/mcp/learning-tools-handlers.js +105 -0
- package/dist/mcp/learning-tools-handlers.js.map +1 -0
- package/dist/optimizations/QueryOptimizer.d.ts.map +1 -1
- package/dist/optimizations/QueryOptimizer.js +3 -1
- package/dist/optimizations/QueryOptimizer.js.map +1 -1
- package/package.json +1 -1
- package/src/cli/agentdb-cli.ts +136 -51
- package/src/controllers/CausalMemoryGraph.ts +2 -3
- package/src/controllers/CausalRecall.ts +73 -1
- package/src/controllers/EmbeddingService.ts +6 -1
- package/src/controllers/ExplainableRecall.ts +1 -1
- package/src/controllers/LearningSystem.ts +1286 -0
- package/src/controllers/NightlyLearner.ts +11 -1
- package/src/controllers/ReasoningBank.ts +411 -0
- package/src/controllers/ReflexionMemory.ts +4 -0
- package/src/controllers/SkillLibrary.ts +254 -16
- package/src/mcp/agentdb-mcp-server.ts +1710 -0
- package/src/mcp/learning-tools-handlers.ts +106 -0
- package/src/optimizations/QueryOptimizer.ts +4 -2
- package/dist/benchmarks/comprehensive-benchmark.js +0 -664
- package/dist/benchmarks/frontier-benchmark.js +0 -419
- package/dist/benchmarks/reflexion-benchmark.js +0 -370
- package/dist/cli/agentdb-cli.js.backup +0 -718
- package/dist/schemas/frontier-schema.sql +0 -341
- package/dist/schemas/schema.sql +0 -382
- package/dist/tests/frontier-features.test.js +0 -665
package/dist/schemas/schema.sql
DELETED
|
@@ -1,382 +0,0 @@
|
|
|
1
|
-
-- ============================================================================
|
|
2
|
-
-- AgentDB State-of-the-Art Memory Schema
|
|
3
|
-
-- ============================================================================
|
|
4
|
-
-- Implements 5 cutting-edge memory patterns for autonomous agents:
|
|
5
|
-
-- 1. Reflexion-style episodic replay
|
|
6
|
-
-- 2. Skill library from trajectories
|
|
7
|
-
-- 3. Structured mixed memory (facts + summaries)
|
|
8
|
-
-- 4. Episodic segmentation and consolidation
|
|
9
|
-
-- 5. Graph-aware recall
|
|
10
|
-
-- ============================================================================
|
|
11
|
-
|
|
12
|
-
-- Enable foreign keys
|
|
13
|
-
PRAGMA foreign_keys = ON;
|
|
14
|
-
|
|
15
|
-
-- ============================================================================
|
|
16
|
-
-- Pattern 1: Reflexion-Style Episodic Replay
|
|
17
|
-
-- ============================================================================
|
|
18
|
-
-- Store self-critique and outcomes after each attempt.
|
|
19
|
-
-- Retrieve nearest failures and fixes before the next run.
|
|
20
|
-
|
|
21
|
-
CREATE TABLE IF NOT EXISTS episodes (
|
|
22
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
23
|
-
ts INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
24
|
-
session_id TEXT NOT NULL,
|
|
25
|
-
task TEXT NOT NULL,
|
|
26
|
-
input TEXT,
|
|
27
|
-
output TEXT,
|
|
28
|
-
critique TEXT,
|
|
29
|
-
reward REAL DEFAULT 0.0,
|
|
30
|
-
success BOOLEAN DEFAULT 0,
|
|
31
|
-
latency_ms INTEGER,
|
|
32
|
-
tokens_used INTEGER,
|
|
33
|
-
tags TEXT, -- JSON array of tags
|
|
34
|
-
metadata JSON,
|
|
35
|
-
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
CREATE INDEX IF NOT EXISTS idx_episodes_ts ON episodes(ts DESC);
|
|
39
|
-
CREATE INDEX IF NOT EXISTS idx_episodes_session ON episodes(session_id);
|
|
40
|
-
CREATE INDEX IF NOT EXISTS idx_episodes_reward ON episodes(reward DESC);
|
|
41
|
-
CREATE INDEX IF NOT EXISTS idx_episodes_task ON episodes(task);
|
|
42
|
-
|
|
43
|
-
-- Vector embeddings for episodes (384-dim for all-MiniLM-L6-v2)
|
|
44
|
-
-- Will use sqlite-vec when available, fallback to JSON storage
|
|
45
|
-
CREATE TABLE IF NOT EXISTS episode_embeddings (
|
|
46
|
-
episode_id INTEGER PRIMARY KEY,
|
|
47
|
-
embedding BLOB NOT NULL, -- Float32Array as BLOB
|
|
48
|
-
embedding_model TEXT DEFAULT 'all-MiniLM-L6-v2',
|
|
49
|
-
FOREIGN KEY(episode_id) REFERENCES episodes(id) ON DELETE CASCADE
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
-- ============================================================================
|
|
53
|
-
-- Pattern 2: Skill Library from Trajectories
|
|
54
|
-
-- ============================================================================
|
|
55
|
-
-- Promote high-reward traces into reusable "skills" with typed IO.
|
|
56
|
-
|
|
57
|
-
CREATE TABLE IF NOT EXISTS skills (
|
|
58
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
59
|
-
name TEXT UNIQUE NOT NULL,
|
|
60
|
-
description TEXT,
|
|
61
|
-
signature JSON NOT NULL, -- {inputs: {...}, outputs: {...}}
|
|
62
|
-
code TEXT, -- Tool call manifest or code template
|
|
63
|
-
success_rate REAL DEFAULT 0.0,
|
|
64
|
-
uses INTEGER DEFAULT 0,
|
|
65
|
-
avg_reward REAL DEFAULT 0.0,
|
|
66
|
-
avg_latency_ms INTEGER DEFAULT 0,
|
|
67
|
-
created_from_episode INTEGER, -- Source episode ID
|
|
68
|
-
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
69
|
-
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
70
|
-
last_used_at INTEGER,
|
|
71
|
-
metadata JSON,
|
|
72
|
-
FOREIGN KEY(created_from_episode) REFERENCES episodes(id)
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
CREATE INDEX IF NOT EXISTS idx_skills_success ON skills(success_rate DESC);
|
|
76
|
-
CREATE INDEX IF NOT EXISTS idx_skills_uses ON skills(uses DESC);
|
|
77
|
-
CREATE INDEX IF NOT EXISTS idx_skills_name ON skills(name);
|
|
78
|
-
|
|
79
|
-
-- Skill relationships and composition
|
|
80
|
-
CREATE TABLE IF NOT EXISTS skill_links (
|
|
81
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
82
|
-
parent_skill_id INTEGER NOT NULL,
|
|
83
|
-
child_skill_id INTEGER NOT NULL,
|
|
84
|
-
relationship TEXT NOT NULL, -- 'prerequisite', 'alternative', 'refinement', 'composition'
|
|
85
|
-
weight REAL DEFAULT 1.0,
|
|
86
|
-
metadata JSON,
|
|
87
|
-
FOREIGN KEY(parent_skill_id) REFERENCES skills(id) ON DELETE CASCADE,
|
|
88
|
-
FOREIGN KEY(child_skill_id) REFERENCES skills(id) ON DELETE CASCADE,
|
|
89
|
-
UNIQUE(parent_skill_id, child_skill_id, relationship)
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
CREATE INDEX IF NOT EXISTS idx_skill_links_parent ON skill_links(parent_skill_id);
|
|
93
|
-
CREATE INDEX IF NOT EXISTS idx_skill_links_child ON skill_links(child_skill_id);
|
|
94
|
-
|
|
95
|
-
-- Skill embeddings for semantic search
|
|
96
|
-
CREATE TABLE IF NOT EXISTS skill_embeddings (
|
|
97
|
-
skill_id INTEGER PRIMARY KEY,
|
|
98
|
-
embedding BLOB NOT NULL,
|
|
99
|
-
embedding_model TEXT DEFAULT 'all-MiniLM-L6-v2',
|
|
100
|
-
FOREIGN KEY(skill_id) REFERENCES skills(id) ON DELETE CASCADE
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
-- ============================================================================
|
|
104
|
-
-- Pattern 3: Structured Mixed Memory (Facts + Summaries)
|
|
105
|
-
-- ============================================================================
|
|
106
|
-
-- Combine facts, summaries, and vectors to avoid over-embedding.
|
|
107
|
-
|
|
108
|
-
-- Atomic facts as triples (subject-predicate-object)
|
|
109
|
-
CREATE TABLE IF NOT EXISTS facts (
|
|
110
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
111
|
-
subject TEXT NOT NULL,
|
|
112
|
-
predicate TEXT NOT NULL,
|
|
113
|
-
object TEXT NOT NULL,
|
|
114
|
-
source_type TEXT, -- 'episode', 'skill', 'external', 'inferred'
|
|
115
|
-
source_id INTEGER,
|
|
116
|
-
confidence REAL DEFAULT 1.0,
|
|
117
|
-
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
118
|
-
expires_at INTEGER, -- TTL for temporal facts
|
|
119
|
-
metadata JSON
|
|
120
|
-
);
|
|
121
|
-
|
|
122
|
-
CREATE INDEX IF NOT EXISTS idx_facts_subject ON facts(subject);
|
|
123
|
-
CREATE INDEX IF NOT EXISTS idx_facts_predicate ON facts(predicate);
|
|
124
|
-
CREATE INDEX IF NOT EXISTS idx_facts_object ON facts(object);
|
|
125
|
-
CREATE INDEX IF NOT EXISTS idx_facts_source ON facts(source_type, source_id);
|
|
126
|
-
CREATE INDEX IF NOT EXISTS idx_facts_expires ON facts(expires_at) WHERE expires_at IS NOT NULL;
|
|
127
|
-
|
|
128
|
-
-- Notes and summaries with semantic embeddings
|
|
129
|
-
CREATE TABLE IF NOT EXISTS notes (
|
|
130
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
131
|
-
title TEXT,
|
|
132
|
-
text TEXT NOT NULL,
|
|
133
|
-
summary TEXT, -- Condensed version for context
|
|
134
|
-
note_type TEXT DEFAULT 'general', -- 'insight', 'constraint', 'goal', 'observation'
|
|
135
|
-
importance REAL DEFAULT 0.5,
|
|
136
|
-
access_count INTEGER DEFAULT 0,
|
|
137
|
-
last_accessed_at INTEGER,
|
|
138
|
-
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
139
|
-
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
140
|
-
metadata JSON
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
CREATE INDEX IF NOT EXISTS idx_notes_type ON notes(note_type);
|
|
144
|
-
CREATE INDEX IF NOT EXISTS idx_notes_importance ON notes(importance DESC);
|
|
145
|
-
CREATE INDEX IF NOT EXISTS idx_notes_accessed ON notes(last_accessed_at DESC);
|
|
146
|
-
|
|
147
|
-
-- Note embeddings (only for summaries to reduce storage)
|
|
148
|
-
CREATE TABLE IF NOT EXISTS note_embeddings (
|
|
149
|
-
note_id INTEGER PRIMARY KEY,
|
|
150
|
-
embedding BLOB NOT NULL,
|
|
151
|
-
embedding_model TEXT DEFAULT 'all-MiniLM-L6-v2',
|
|
152
|
-
FOREIGN KEY(note_id) REFERENCES notes(id) ON DELETE CASCADE
|
|
153
|
-
);
|
|
154
|
-
|
|
155
|
-
-- ============================================================================
|
|
156
|
-
-- Pattern 4: Episodic Segmentation and Consolidation
|
|
157
|
-
-- ============================================================================
|
|
158
|
-
-- Segment long tasks into events and consolidate into compact memories.
|
|
159
|
-
|
|
160
|
-
CREATE TABLE IF NOT EXISTS events (
|
|
161
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
162
|
-
session_id TEXT NOT NULL,
|
|
163
|
-
episode_id INTEGER, -- Link to parent episode
|
|
164
|
-
step INTEGER NOT NULL,
|
|
165
|
-
phase TEXT, -- 'planning', 'execution', 'reflection', 'learning'
|
|
166
|
-
role TEXT, -- 'user', 'assistant', 'system', 'tool'
|
|
167
|
-
content TEXT NOT NULL,
|
|
168
|
-
features JSON, -- Extracted features for learning
|
|
169
|
-
tool_calls JSON, -- Tool invocations in this event
|
|
170
|
-
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
171
|
-
FOREIGN KEY(episode_id) REFERENCES episodes(id) ON DELETE CASCADE
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
CREATE INDEX IF NOT EXISTS idx_events_session ON events(session_id, step);
|
|
175
|
-
CREATE INDEX IF NOT EXISTS idx_events_phase ON events(phase);
|
|
176
|
-
CREATE INDEX IF NOT EXISTS idx_events_episode ON events(episode_id);
|
|
177
|
-
|
|
178
|
-
-- Consolidated memories from event windows
|
|
179
|
-
CREATE TABLE IF NOT EXISTS consolidated_memories (
|
|
180
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
181
|
-
session_id TEXT NOT NULL,
|
|
182
|
-
start_event_id INTEGER NOT NULL,
|
|
183
|
-
end_event_id INTEGER NOT NULL,
|
|
184
|
-
phase TEXT,
|
|
185
|
-
summary TEXT NOT NULL,
|
|
186
|
-
key_insights JSON, -- Extracted learnings
|
|
187
|
-
success_patterns JSON, -- What worked
|
|
188
|
-
failure_patterns JSON, -- What didn't work
|
|
189
|
-
quality_score REAL DEFAULT 0.5,
|
|
190
|
-
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
191
|
-
FOREIGN KEY(start_event_id) REFERENCES events(id),
|
|
192
|
-
FOREIGN KEY(end_event_id) REFERENCES events(id)
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
CREATE INDEX IF NOT EXISTS idx_consolidated_session ON consolidated_memories(session_id);
|
|
196
|
-
CREATE INDEX IF NOT EXISTS idx_consolidated_quality ON consolidated_memories(quality_score DESC);
|
|
197
|
-
|
|
198
|
-
-- ============================================================================
|
|
199
|
-
-- Pattern 5: Graph-Aware Recall (Lightweight GraphRAG)
|
|
200
|
-
-- ============================================================================
|
|
201
|
-
-- Build a lightweight GraphRAG overlay for experiences.
|
|
202
|
-
|
|
203
|
-
CREATE TABLE IF NOT EXISTS exp_nodes (
|
|
204
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
205
|
-
kind TEXT NOT NULL, -- 'task', 'skill', 'concept', 'tool', 'outcome'
|
|
206
|
-
label TEXT NOT NULL,
|
|
207
|
-
payload JSON,
|
|
208
|
-
centrality REAL DEFAULT 0.0, -- Graph importance metric
|
|
209
|
-
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
210
|
-
updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
|
|
211
|
-
);
|
|
212
|
-
|
|
213
|
-
CREATE INDEX IF NOT EXISTS idx_exp_nodes_kind ON exp_nodes(kind);
|
|
214
|
-
CREATE INDEX IF NOT EXISTS idx_exp_nodes_label ON exp_nodes(label);
|
|
215
|
-
CREATE INDEX IF NOT EXISTS idx_exp_nodes_centrality ON exp_nodes(centrality DESC);
|
|
216
|
-
|
|
217
|
-
CREATE TABLE IF NOT EXISTS exp_edges (
|
|
218
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
219
|
-
src_node_id INTEGER NOT NULL,
|
|
220
|
-
dst_node_id INTEGER NOT NULL,
|
|
221
|
-
relationship TEXT NOT NULL, -- 'requires', 'produces', 'similar_to', 'refines', 'part_of'
|
|
222
|
-
weight REAL DEFAULT 1.0,
|
|
223
|
-
metadata JSON,
|
|
224
|
-
created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
225
|
-
FOREIGN KEY(src_node_id) REFERENCES exp_nodes(id) ON DELETE CASCADE,
|
|
226
|
-
FOREIGN KEY(dst_node_id) REFERENCES exp_nodes(id) ON DELETE CASCADE,
|
|
227
|
-
UNIQUE(src_node_id, dst_node_id, relationship)
|
|
228
|
-
);
|
|
229
|
-
|
|
230
|
-
CREATE INDEX IF NOT EXISTS idx_exp_edges_src ON exp_edges(src_node_id);
|
|
231
|
-
CREATE INDEX IF NOT EXISTS idx_exp_edges_dst ON exp_edges(dst_node_id);
|
|
232
|
-
CREATE INDEX IF NOT EXISTS idx_exp_edges_rel ON exp_edges(relationship);
|
|
233
|
-
|
|
234
|
-
-- Node embeddings for graph-augmented retrieval
|
|
235
|
-
CREATE TABLE IF NOT EXISTS exp_node_embeddings (
|
|
236
|
-
node_id INTEGER PRIMARY KEY,
|
|
237
|
-
embedding BLOB NOT NULL,
|
|
238
|
-
embedding_model TEXT DEFAULT 'all-MiniLM-L6-v2',
|
|
239
|
-
FOREIGN KEY(node_id) REFERENCES exp_nodes(id) ON DELETE CASCADE
|
|
240
|
-
);
|
|
241
|
-
|
|
242
|
-
-- ============================================================================
|
|
243
|
-
-- Memory Management and Scoring
|
|
244
|
-
-- ============================================================================
|
|
245
|
-
|
|
246
|
-
-- Track memory quality scores and usage statistics
|
|
247
|
-
CREATE TABLE IF NOT EXISTS memory_scores (
|
|
248
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
249
|
-
memory_type TEXT NOT NULL, -- 'episode', 'skill', 'note', 'consolidated'
|
|
250
|
-
memory_id INTEGER NOT NULL,
|
|
251
|
-
quality_score REAL NOT NULL,
|
|
252
|
-
novelty_score REAL,
|
|
253
|
-
relevance_score REAL,
|
|
254
|
-
utility_score REAL,
|
|
255
|
-
computed_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
|
|
256
|
-
metadata JSON
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
CREATE INDEX IF NOT EXISTS idx_memory_scores_type ON memory_scores(memory_type, memory_id);
|
|
260
|
-
CREATE INDEX IF NOT EXISTS idx_memory_scores_quality ON memory_scores(quality_score DESC);
|
|
261
|
-
|
|
262
|
-
-- Memory access patterns for adaptive retrieval
|
|
263
|
-
CREATE TABLE IF NOT EXISTS memory_access_log (
|
|
264
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
265
|
-
memory_type TEXT NOT NULL,
|
|
266
|
-
memory_id INTEGER NOT NULL,
|
|
267
|
-
query TEXT,
|
|
268
|
-
relevance_score REAL,
|
|
269
|
-
was_useful BOOLEAN,
|
|
270
|
-
feedback JSON,
|
|
271
|
-
accessed_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
CREATE INDEX IF NOT EXISTS idx_access_log_type ON memory_access_log(memory_type, memory_id);
|
|
275
|
-
CREATE INDEX IF NOT EXISTS idx_access_log_time ON memory_access_log(accessed_at DESC);
|
|
276
|
-
|
|
277
|
-
-- ============================================================================
|
|
278
|
-
-- Consolidation and Maintenance
|
|
279
|
-
-- ============================================================================
|
|
280
|
-
|
|
281
|
-
-- Track consolidation jobs and their results
|
|
282
|
-
CREATE TABLE IF NOT EXISTS consolidation_runs (
|
|
283
|
-
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
284
|
-
job_type TEXT NOT NULL, -- 'episode_to_skill', 'event_to_memory', 'deduplication', 'pruning'
|
|
285
|
-
records_processed INTEGER DEFAULT 0,
|
|
286
|
-
records_created INTEGER DEFAULT 0,
|
|
287
|
-
records_deleted INTEGER DEFAULT 0,
|
|
288
|
-
duration_ms INTEGER,
|
|
289
|
-
status TEXT DEFAULT 'pending', -- 'pending', 'running', 'completed', 'failed'
|
|
290
|
-
error TEXT,
|
|
291
|
-
started_at INTEGER,
|
|
292
|
-
completed_at INTEGER,
|
|
293
|
-
metadata JSON
|
|
294
|
-
);
|
|
295
|
-
|
|
296
|
-
CREATE INDEX IF NOT EXISTS idx_consolidation_status ON consolidation_runs(status);
|
|
297
|
-
CREATE INDEX IF NOT EXISTS idx_consolidation_type ON consolidation_runs(job_type);
|
|
298
|
-
|
|
299
|
-
-- ============================================================================
|
|
300
|
-
-- Views for Common Queries
|
|
301
|
-
-- ============================================================================
|
|
302
|
-
|
|
303
|
-
-- High-value episodes for skill creation
|
|
304
|
-
CREATE VIEW IF NOT EXISTS skill_candidates AS
|
|
305
|
-
SELECT
|
|
306
|
-
task,
|
|
307
|
-
COUNT(*) as attempt_count,
|
|
308
|
-
AVG(reward) as avg_reward,
|
|
309
|
-
AVG(success) as success_rate,
|
|
310
|
-
MAX(id) as latest_episode_id,
|
|
311
|
-
GROUP_CONCAT(id) as episode_ids
|
|
312
|
-
FROM episodes
|
|
313
|
-
WHERE ts > strftime('%s', 'now') - 86400 * 7 -- Last 7 days
|
|
314
|
-
GROUP BY task
|
|
315
|
-
HAVING attempt_count >= 3 AND avg_reward >= 0.7;
|
|
316
|
-
|
|
317
|
-
-- Top performing skills
|
|
318
|
-
CREATE VIEW IF NOT EXISTS top_skills AS
|
|
319
|
-
SELECT
|
|
320
|
-
s.*,
|
|
321
|
-
COALESCE(s.success_rate, 0) * 0.4 +
|
|
322
|
-
COALESCE(s.uses, 0) * 0.0001 +
|
|
323
|
-
COALESCE(s.avg_reward, 0) * 0.6 as composite_score
|
|
324
|
-
FROM skills s
|
|
325
|
-
ORDER BY composite_score DESC;
|
|
326
|
-
|
|
327
|
-
-- Recent high-quality memories
|
|
328
|
-
CREATE VIEW IF NOT EXISTS recent_quality_memories AS
|
|
329
|
-
SELECT
|
|
330
|
-
'episode' as type, id, task as title, critique as content, reward as score, created_at
|
|
331
|
-
FROM episodes
|
|
332
|
-
WHERE reward >= 0.7 AND ts > strftime('%s', 'now') - 86400 * 3
|
|
333
|
-
UNION ALL
|
|
334
|
-
SELECT
|
|
335
|
-
'note' as type, id, title, summary as content, importance as score, created_at
|
|
336
|
-
FROM notes
|
|
337
|
-
WHERE importance >= 0.7 AND created_at > strftime('%s', 'now') - 86400 * 3
|
|
338
|
-
UNION ALL
|
|
339
|
-
SELECT
|
|
340
|
-
'consolidated' as type, id, session_id as title, summary as content, quality_score as score, created_at
|
|
341
|
-
FROM consolidated_memories
|
|
342
|
-
WHERE quality_score >= 0.7 AND created_at > strftime('%s', 'now') - 86400 * 3
|
|
343
|
-
ORDER BY created_at DESC;
|
|
344
|
-
|
|
345
|
-
-- ============================================================================
|
|
346
|
-
-- Triggers for Auto-Maintenance
|
|
347
|
-
-- ============================================================================
|
|
348
|
-
|
|
349
|
-
-- Update skill usage statistics
|
|
350
|
-
CREATE TRIGGER IF NOT EXISTS update_skill_last_used
|
|
351
|
-
AFTER UPDATE OF uses ON skills
|
|
352
|
-
BEGIN
|
|
353
|
-
UPDATE skills SET last_used_at = strftime('%s', 'now') WHERE id = NEW.id;
|
|
354
|
-
END;
|
|
355
|
-
|
|
356
|
-
-- Update note access tracking
|
|
357
|
-
CREATE TRIGGER IF NOT EXISTS update_note_access
|
|
358
|
-
AFTER UPDATE OF access_count ON notes
|
|
359
|
-
BEGIN
|
|
360
|
-
UPDATE notes SET last_accessed_at = strftime('%s', 'now') WHERE id = NEW.id;
|
|
361
|
-
END;
|
|
362
|
-
|
|
363
|
-
-- Auto-update timestamps
|
|
364
|
-
CREATE TRIGGER IF NOT EXISTS update_skill_timestamp
|
|
365
|
-
AFTER UPDATE ON skills
|
|
366
|
-
BEGIN
|
|
367
|
-
UPDATE skills SET updated_at = strftime('%s', 'now') WHERE id = NEW.id;
|
|
368
|
-
END;
|
|
369
|
-
|
|
370
|
-
CREATE TRIGGER IF NOT EXISTS update_note_timestamp
|
|
371
|
-
AFTER UPDATE ON notes
|
|
372
|
-
BEGIN
|
|
373
|
-
UPDATE notes SET updated_at = strftime('%s', 'now') WHERE id = NEW.id;
|
|
374
|
-
END;
|
|
375
|
-
|
|
376
|
-
-- ============================================================================
|
|
377
|
-
-- Initialization Complete
|
|
378
|
-
-- ============================================================================
|
|
379
|
-
-- Schema version: 1.0.0
|
|
380
|
-
-- Compatible with: SQLite 3.35+, sqlite-vec (optional), sqlite-vss (optional)
|
|
381
|
-
-- WASM compatible: Yes (via SQLite-WASM + OPFS)
|
|
382
|
-
-- ============================================================================
|