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.
Files changed (66) hide show
  1. package/README.md +180 -33
  2. package/dist/cli/agentdb-cli.d.ts +1 -0
  3. package/dist/cli/agentdb-cli.d.ts.map +1 -1
  4. package/dist/cli/agentdb-cli.js +108 -134
  5. package/dist/cli/agentdb-cli.js.map +1 -1
  6. package/dist/controllers/CausalMemoryGraph.d.ts.map +1 -1
  7. package/dist/controllers/CausalMemoryGraph.js +3 -3
  8. package/dist/controllers/CausalMemoryGraph.js.map +1 -1
  9. package/dist/controllers/CausalRecall.d.ts +25 -0
  10. package/dist/controllers/CausalRecall.d.ts.map +1 -1
  11. package/dist/controllers/CausalRecall.js +44 -1
  12. package/dist/controllers/CausalRecall.js.map +1 -1
  13. package/dist/controllers/EmbeddingService.d.ts.map +1 -1
  14. package/dist/controllers/EmbeddingService.js +4 -0
  15. package/dist/controllers/EmbeddingService.js.map +1 -1
  16. package/dist/controllers/ExplainableRecall.js +1 -1
  17. package/dist/controllers/LearningSystem.d.ts +194 -0
  18. package/dist/controllers/LearningSystem.d.ts.map +1 -0
  19. package/dist/controllers/LearningSystem.js +929 -0
  20. package/dist/controllers/LearningSystem.js.map +1 -0
  21. package/dist/controllers/NightlyLearner.d.ts.map +1 -1
  22. package/dist/controllers/NightlyLearner.js +9 -1
  23. package/dist/controllers/NightlyLearner.js.map +1 -1
  24. package/dist/controllers/ReasoningBank.d.ts +96 -0
  25. package/dist/controllers/ReasoningBank.d.ts.map +1 -0
  26. package/dist/controllers/ReasoningBank.js +302 -0
  27. package/dist/controllers/ReasoningBank.js.map +1 -0
  28. package/dist/controllers/ReflexionMemory.d.ts.map +1 -1
  29. package/dist/controllers/ReflexionMemory.js +4 -0
  30. package/dist/controllers/ReflexionMemory.js.map +1 -1
  31. package/dist/controllers/SkillLibrary.d.ts +37 -3
  32. package/dist/controllers/SkillLibrary.d.ts.map +1 -1
  33. package/dist/controllers/SkillLibrary.js +196 -15
  34. package/dist/controllers/SkillLibrary.js.map +1 -1
  35. package/dist/mcp/agentdb-mcp-server.d.ts +8 -0
  36. package/dist/mcp/agentdb-mcp-server.d.ts.map +1 -0
  37. package/dist/mcp/agentdb-mcp-server.js +1485 -352
  38. package/dist/mcp/agentdb-mcp-server.js.map +1 -0
  39. package/dist/mcp/learning-tools-handlers.d.ts +16 -0
  40. package/dist/mcp/learning-tools-handlers.d.ts.map +1 -0
  41. package/dist/mcp/learning-tools-handlers.js +105 -0
  42. package/dist/mcp/learning-tools-handlers.js.map +1 -0
  43. package/dist/optimizations/QueryOptimizer.d.ts.map +1 -1
  44. package/dist/optimizations/QueryOptimizer.js +3 -1
  45. package/dist/optimizations/QueryOptimizer.js.map +1 -1
  46. package/package.json +1 -1
  47. package/src/cli/agentdb-cli.ts +136 -51
  48. package/src/controllers/CausalMemoryGraph.ts +2 -3
  49. package/src/controllers/CausalRecall.ts +73 -1
  50. package/src/controllers/EmbeddingService.ts +6 -1
  51. package/src/controllers/ExplainableRecall.ts +1 -1
  52. package/src/controllers/LearningSystem.ts +1286 -0
  53. package/src/controllers/NightlyLearner.ts +11 -1
  54. package/src/controllers/ReasoningBank.ts +411 -0
  55. package/src/controllers/ReflexionMemory.ts +4 -0
  56. package/src/controllers/SkillLibrary.ts +254 -16
  57. package/src/mcp/agentdb-mcp-server.ts +1710 -0
  58. package/src/mcp/learning-tools-handlers.ts +106 -0
  59. package/src/optimizations/QueryOptimizer.ts +4 -2
  60. package/dist/benchmarks/comprehensive-benchmark.js +0 -664
  61. package/dist/benchmarks/frontier-benchmark.js +0 -419
  62. package/dist/benchmarks/reflexion-benchmark.js +0 -370
  63. package/dist/cli/agentdb-cli.js.backup +0 -718
  64. package/dist/schemas/frontier-schema.sql +0 -341
  65. package/dist/schemas/schema.sql +0 -382
  66. package/dist/tests/frontier-features.test.js +0 -665
@@ -1,341 +0,0 @@
1
- -- ============================================================================
2
- -- AgentDB Frontier Features Schema Extension
3
- -- ============================================================================
4
- -- Implements cutting-edge memory features:
5
- -- 1. Causal Memory Graph - Store edges with causal strength, not just similarity
6
- -- 2. Explainable Recall Certificates - Provenance and justification tracking
7
- -- ============================================================================
8
-
9
- -- ============================================================================
10
- -- FEATURE 1: Causal Memory Graph
11
- -- ============================================================================
12
-
13
- -- Causal edges between memories with intervention effects
14
- CREATE TABLE IF NOT EXISTS causal_edges (
15
- id INTEGER PRIMARY KEY AUTOINCREMENT,
16
- from_memory_id INTEGER NOT NULL,
17
- from_memory_type TEXT NOT NULL, -- 'episode', 'skill', 'note', 'fact'
18
- to_memory_id INTEGER NOT NULL,
19
- to_memory_type TEXT NOT NULL,
20
-
21
- -- Traditional similarity
22
- similarity REAL NOT NULL DEFAULT 0.0,
23
-
24
- -- Causal metrics
25
- uplift REAL, -- E[y|do(x)] - E[y]
26
- confidence REAL DEFAULT 0.5, -- Confidence in causal claim
27
- sample_size INTEGER, -- Number of observations
28
-
29
- -- Evidence and provenance
30
- evidence_ids TEXT, -- JSON array of proof IDs
31
- experiment_ids TEXT, -- JSON array of A/B test IDs
32
- confounder_score REAL, -- Likelihood of confounding
33
-
34
- -- Metadata
35
- mechanism TEXT, -- Hypothesized causal mechanism
36
- created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
37
- updated_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
38
- last_validated_at INTEGER,
39
-
40
- metadata JSON
41
-
42
- -- Note: Foreign keys removed to allow flexible causal edges between any concepts
43
- -- from_memory_id and to_memory_id can be 0 for abstract causal relationships
44
- );
45
-
46
- CREATE INDEX IF NOT EXISTS idx_causal_edges_from ON causal_edges(from_memory_id, from_memory_type);
47
- CREATE INDEX IF NOT EXISTS idx_causal_edges_to ON causal_edges(to_memory_id, to_memory_type);
48
- CREATE INDEX IF NOT EXISTS idx_causal_edges_uplift ON causal_edges(uplift DESC);
49
- CREATE INDEX IF NOT EXISTS idx_causal_edges_confidence ON causal_edges(confidence DESC);
50
-
51
- -- Causal experiments (A/B tests for uplift estimation)
52
- CREATE TABLE IF NOT EXISTS causal_experiments (
53
- id INTEGER PRIMARY KEY AUTOINCREMENT,
54
- name TEXT NOT NULL,
55
- hypothesis TEXT NOT NULL,
56
- treatment_id INTEGER NOT NULL, -- Memory used as treatment
57
- treatment_type TEXT NOT NULL,
58
- control_id INTEGER, -- Optional control memory
59
-
60
- -- Experiment design
61
- start_time INTEGER NOT NULL,
62
- end_time INTEGER,
63
- sample_size INTEGER DEFAULT 0,
64
-
65
- -- Results
66
- treatment_mean REAL,
67
- control_mean REAL,
68
- uplift REAL, -- treatment_mean - control_mean
69
- p_value REAL,
70
- confidence_interval_low REAL,
71
- confidence_interval_high REAL,
72
-
73
- -- Status
74
- status TEXT DEFAULT 'running', -- 'running', 'completed', 'failed'
75
-
76
- metadata JSON,
77
- created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now'))
78
- );
79
-
80
- CREATE INDEX IF NOT EXISTS idx_causal_experiments_status ON causal_experiments(status);
81
- CREATE INDEX IF NOT EXISTS idx_causal_experiments_treatment ON causal_experiments(treatment_id, treatment_type);
82
-
83
- -- Causal observations (individual data points)
84
- CREATE TABLE IF NOT EXISTS causal_observations (
85
- id INTEGER PRIMARY KEY AUTOINCREMENT,
86
- experiment_id INTEGER NOT NULL,
87
- episode_id INTEGER NOT NULL,
88
-
89
- -- Treatment assignment
90
- is_treatment BOOLEAN NOT NULL,
91
-
92
- -- Outcome
93
- outcome_value REAL NOT NULL,
94
- outcome_type TEXT, -- 'reward', 'success', 'latency'
95
-
96
- -- Context
97
- context JSON,
98
- observed_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
99
-
100
- FOREIGN KEY(experiment_id) REFERENCES causal_experiments(id) ON DELETE CASCADE,
101
- FOREIGN KEY(episode_id) REFERENCES episodes(id) ON DELETE CASCADE
102
- );
103
-
104
- CREATE INDEX IF NOT EXISTS idx_causal_observations_experiment ON causal_observations(experiment_id);
105
- CREATE INDEX IF NOT EXISTS idx_causal_observations_treatment ON causal_observations(is_treatment);
106
-
107
- -- ============================================================================
108
- -- FEATURE 2: Explainable Recall Certificates
109
- -- ============================================================================
110
-
111
- -- Recall certificates for provenance and justification
112
- CREATE TABLE IF NOT EXISTS recall_certificates (
113
- id TEXT PRIMARY KEY, -- UUID or hash
114
- query_id TEXT NOT NULL,
115
- query_text TEXT NOT NULL,
116
-
117
- -- Retrieved chunks
118
- chunk_ids TEXT NOT NULL, -- JSON array
119
- chunk_types TEXT NOT NULL, -- JSON array matching chunk_ids
120
-
121
- -- Minimal hitting set (justification)
122
- minimal_why TEXT, -- JSON array of chunk IDs that justify the answer
123
- redundancy_ratio REAL, -- len(chunk_ids) / len(minimal_why)
124
- completeness_score REAL, -- Fraction of query requirements met
125
-
126
- -- Provenance chain
127
- merkle_root TEXT NOT NULL,
128
- source_hashes TEXT, -- JSON array of source hashes
129
- proof_chain TEXT, -- JSON Merkle proof
130
-
131
- -- Policy compliance
132
- policy_proof TEXT, -- Proof of policy adherence
133
- policy_version TEXT,
134
- access_level TEXT, -- 'public', 'internal', 'confidential', 'restricted'
135
-
136
- -- Metadata
137
- created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
138
- latency_ms INTEGER,
139
-
140
- metadata JSON
141
- );
142
-
143
- CREATE INDEX IF NOT EXISTS idx_recall_certificates_query ON recall_certificates(query_id);
144
- CREATE INDEX IF NOT EXISTS idx_recall_certificates_created ON recall_certificates(created_at DESC);
145
-
146
- -- Provenance sources (for Merkle tree construction)
147
- CREATE TABLE IF NOT EXISTS provenance_sources (
148
- id INTEGER PRIMARY KEY AUTOINCREMENT,
149
- source_type TEXT NOT NULL, -- 'episode', 'skill', 'note', 'fact', 'external'
150
- source_id INTEGER NOT NULL,
151
-
152
- -- Content hash
153
- content_hash TEXT NOT NULL UNIQUE,
154
-
155
- -- Lineage
156
- parent_hash TEXT, -- Previous version
157
- derived_from TEXT, -- JSON array of parent hashes
158
-
159
- -- Metadata
160
- created_at INTEGER NOT NULL DEFAULT (strftime('%s', 'now')),
161
- creator TEXT, -- User or system identifier
162
-
163
- metadata JSON
164
- );
165
-
166
- CREATE INDEX IF NOT EXISTS idx_provenance_sources_type ON provenance_sources(source_type, source_id);
167
- CREATE INDEX IF NOT EXISTS idx_provenance_sources_hash ON provenance_sources(content_hash);
168
- CREATE INDEX IF NOT EXISTS idx_provenance_sources_parent ON provenance_sources(parent_hash);
169
-
170
- -- Justification paths (why a chunk was included)
171
- CREATE TABLE IF NOT EXISTS justification_paths (
172
- id INTEGER PRIMARY KEY AUTOINCREMENT,
173
- certificate_id TEXT NOT NULL,
174
- chunk_id TEXT NOT NULL,
175
- chunk_type TEXT NOT NULL,
176
-
177
- -- Justification
178
- reason TEXT NOT NULL, -- 'semantic_match', 'causal_link', 'prerequisite', 'constraint'
179
- necessity_score REAL NOT NULL, -- How essential is this chunk (0-1)
180
-
181
- -- Path to query satisfaction
182
- path_elements TEXT, -- JSON array describing reasoning path
183
-
184
- FOREIGN KEY(certificate_id) REFERENCES recall_certificates(id) ON DELETE CASCADE
185
- );
186
-
187
- CREATE INDEX IF NOT EXISTS idx_justification_paths_cert ON justification_paths(certificate_id);
188
- CREATE INDEX IF NOT EXISTS idx_justification_paths_chunk ON justification_paths(chunk_id, chunk_type);
189
-
190
- -- ============================================================================
191
- -- Views for Causal Analysis
192
- -- ============================================================================
193
-
194
- -- High-confidence causal relationships
195
- CREATE VIEW IF NOT EXISTS strong_causal_edges AS
196
- SELECT
197
- ce.*,
198
- CASE
199
- WHEN ce.uplift > 0 THEN 'positive'
200
- WHEN ce.uplift < 0 THEN 'negative'
201
- ELSE 'neutral'
202
- END as effect_direction,
203
- ce.uplift * ce.confidence as causal_impact
204
- FROM causal_edges ce
205
- WHERE ce.confidence >= 0.7
206
- AND ce.uplift IS NOT NULL
207
- AND ABS(ce.uplift) >= 0.1
208
- ORDER BY ABS(ce.uplift) * ce.confidence DESC;
209
-
210
- -- Causal chains (multi-hop reasoning)
211
- CREATE VIEW IF NOT EXISTS causal_chains AS
212
- WITH RECURSIVE chain(from_id, to_id, depth, path, total_uplift) AS (
213
- SELECT from_memory_id, to_memory_id, 1,
214
- from_memory_id || '->' || to_memory_id,
215
- uplift
216
- FROM causal_edges
217
- WHERE confidence >= 0.6
218
-
219
- UNION ALL
220
-
221
- SELECT chain.from_id, ce.to_memory_id, chain.depth + 1,
222
- chain.path || '->' || ce.to_memory_id,
223
- chain.total_uplift + ce.uplift
224
- FROM chain
225
- JOIN causal_edges ce ON chain.to_id = ce.from_memory_id
226
- WHERE chain.depth < 5
227
- AND ce.confidence >= 0.6
228
- AND chain.path NOT LIKE '%' || ce.to_memory_id || '%'
229
- )
230
- SELECT * FROM chain
231
- WHERE depth >= 2
232
- ORDER BY total_uplift DESC, depth ASC;
233
-
234
- -- ============================================================================
235
- -- Views for Explainability
236
- -- ============================================================================
237
-
238
- -- Certificate quality metrics
239
- CREATE VIEW IF NOT EXISTS certificate_quality AS
240
- SELECT
241
- rc.id,
242
- rc.query_id,
243
- rc.completeness_score,
244
- rc.redundancy_ratio,
245
- COUNT(jp.id) as justification_count,
246
- AVG(jp.necessity_score) as avg_necessity,
247
- rc.latency_ms
248
- FROM recall_certificates rc
249
- LEFT JOIN justification_paths jp ON rc.id = jp.certificate_id
250
- GROUP BY rc.id;
251
-
252
- -- Provenance lineage depth
253
- CREATE VIEW IF NOT EXISTS provenance_depth AS
254
- WITH RECURSIVE lineage(hash, depth) AS (
255
- SELECT content_hash, 0
256
- FROM provenance_sources
257
- WHERE parent_hash IS NULL
258
-
259
- UNION ALL
260
-
261
- SELECT ps.content_hash, lineage.depth + 1
262
- FROM lineage
263
- JOIN provenance_sources ps ON lineage.hash = ps.parent_hash
264
- )
265
- SELECT
266
- ps.id,
267
- ps.source_type,
268
- ps.source_id,
269
- ps.content_hash,
270
- COALESCE(l.depth, 0) as lineage_depth
271
- FROM provenance_sources ps
272
- LEFT JOIN lineage l ON ps.content_hash = l.hash;
273
-
274
- -- ============================================================================
275
- -- Triggers for Automatic Maintenance
276
- -- ============================================================================
277
-
278
- -- Update causal edge timestamp
279
- CREATE TRIGGER IF NOT EXISTS update_causal_edge_timestamp
280
- AFTER UPDATE ON causal_edges
281
- BEGIN
282
- UPDATE causal_edges
283
- SET updated_at = strftime('%s', 'now')
284
- WHERE id = NEW.id;
285
- END;
286
-
287
- -- Validate causal confidence bounds
288
- CREATE TRIGGER IF NOT EXISTS validate_causal_confidence
289
- BEFORE INSERT ON causal_edges
290
- BEGIN
291
- SELECT CASE
292
- WHEN NEW.confidence < 0 OR NEW.confidence > 1 THEN
293
- RAISE(ABORT, 'Confidence must be between 0 and 1')
294
- END;
295
- END;
296
-
297
- -- ============================================================================
298
- -- Functions for Causal Inference (as SQL helpers)
299
- -- ============================================================================
300
-
301
- -- These would typically be implemented in TypeScript, but we provide
302
- -- SQL views that can assist with common causal queries
303
-
304
- -- Instrumental variables (potential instruments for causal inference)
305
- CREATE VIEW IF NOT EXISTS causal_instruments AS
306
- SELECT
307
- e1.id as instrument_id,
308
- e1.task as instrument,
309
- e2.id as treatment_id,
310
- e2.task as treatment,
311
- e3.id as outcome_id,
312
- e3.task as outcome
313
- FROM episodes e1
314
- CROSS JOIN episodes e2
315
- CROSS JOIN episodes e3
316
- WHERE e1.id != e2.id AND e2.id != e3.id AND e1.id != e3.id
317
- -- Instrument affects treatment
318
- AND EXISTS (
319
- SELECT 1 FROM causal_edges
320
- WHERE from_memory_id = e1.id AND to_memory_id = e2.id
321
- AND ABS(uplift) > 0.1
322
- )
323
- -- Treatment affects outcome
324
- AND EXISTS (
325
- SELECT 1 FROM causal_edges
326
- WHERE from_memory_id = e2.id AND to_memory_id = e3.id
327
- AND ABS(uplift) > 0.1
328
- )
329
- -- Instrument doesn't directly affect outcome (exclusion restriction)
330
- AND NOT EXISTS (
331
- SELECT 1 FROM causal_edges
332
- WHERE from_memory_id = e1.id AND to_memory_id = e3.id
333
- );
334
-
335
- -- ============================================================================
336
- -- Schema Version
337
- -- ============================================================================
338
- -- Version: 2.0.0 (Frontier Features)
339
- -- Features: Causal Memory Graph, Explainable Recall Certificates
340
- -- Compatible with: AgentDB 1.x
341
- -- ============================================================================