agentdb 1.0.11 → 1.1.0
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 +196 -838
- package/dist/benchmarks/comprehensive-benchmark.js +664 -0
- package/dist/benchmarks/frontier-benchmark.js +419 -0
- package/dist/benchmarks/reflexion-benchmark.js +370 -0
- package/dist/cli/agentdb-cli.d.ts +117 -0
- package/dist/cli/agentdb-cli.d.ts.map +1 -0
- package/dist/cli/agentdb-cli.js +718 -0
- package/dist/cli/agentdb-cli.js.map +1 -0
- package/dist/controllers/CausalMemoryGraph.d.ts +125 -0
- package/dist/controllers/CausalMemoryGraph.d.ts.map +1 -0
- package/dist/controllers/CausalMemoryGraph.js +323 -0
- package/dist/controllers/CausalMemoryGraph.js.map +1 -0
- package/dist/controllers/CausalRecall.d.ts +111 -0
- package/dist/controllers/CausalRecall.d.ts.map +1 -0
- package/dist/controllers/CausalRecall.js +282 -0
- package/dist/controllers/CausalRecall.js.map +1 -0
- package/dist/controllers/EmbeddingService.d.ts +37 -0
- package/dist/controllers/EmbeddingService.d.ts.map +1 -0
- package/dist/controllers/EmbeddingService.js +119 -0
- package/dist/controllers/EmbeddingService.js.map +1 -0
- package/dist/controllers/ExplainableRecall.d.ts +138 -0
- package/dist/controllers/ExplainableRecall.d.ts.map +1 -0
- package/dist/controllers/ExplainableRecall.js +388 -0
- package/dist/controllers/ExplainableRecall.js.map +1 -0
- package/dist/controllers/NightlyLearner.d.ts +113 -0
- package/dist/controllers/NightlyLearner.d.ts.map +1 -0
- package/dist/controllers/NightlyLearner.js +383 -0
- package/dist/controllers/NightlyLearner.js.map +1 -0
- package/dist/controllers/ReflexionMemory.d.ts +84 -0
- package/dist/controllers/ReflexionMemory.d.ts.map +1 -0
- package/dist/controllers/ReflexionMemory.js +240 -0
- package/dist/controllers/ReflexionMemory.js.map +1 -0
- package/dist/controllers/SkillLibrary.d.ts +96 -0
- package/dist/controllers/SkillLibrary.d.ts.map +1 -0
- package/dist/controllers/SkillLibrary.js +277 -0
- package/dist/controllers/SkillLibrary.js.map +1 -0
- package/dist/controllers/frontier-index.d.ts +14 -0
- package/dist/controllers/frontier-index.d.ts.map +1 -0
- package/dist/controllers/frontier-index.js +10 -0
- package/dist/controllers/frontier-index.js.map +1 -0
- package/dist/controllers/index.d.ts +12 -0
- package/dist/controllers/index.d.ts.map +1 -0
- package/dist/controllers/index.js +9 -0
- package/dist/controllers/index.js.map +1 -0
- package/dist/optimizations/BatchOperations.d.ts +61 -0
- package/dist/optimizations/BatchOperations.d.ts.map +1 -0
- package/dist/optimizations/BatchOperations.js +199 -0
- package/dist/optimizations/BatchOperations.js.map +1 -0
- package/dist/optimizations/QueryOptimizer.d.ts +82 -0
- package/dist/optimizations/QueryOptimizer.d.ts.map +1 -0
- package/dist/optimizations/QueryOptimizer.js +226 -0
- package/dist/optimizations/QueryOptimizer.js.map +1 -0
- package/dist/optimizations/index.d.ts +10 -0
- package/dist/optimizations/index.d.ts.map +1 -0
- package/dist/optimizations/index.js +8 -0
- package/dist/optimizations/index.js.map +1 -0
- package/dist/schemas/frontier-schema.sql +341 -0
- package/dist/schemas/schema.sql +382 -0
- package/dist/tests/frontier-features.test.js +665 -0
- package/package.json +54 -117
- package/src/cli/agentdb-cli.ts +861 -0
- package/src/cli/examples.sh +83 -0
- package/src/controllers/CausalMemoryGraph.ts +504 -0
- package/src/controllers/CausalRecall.ts +395 -0
- package/src/controllers/EmbeddingService.ts +141 -0
- package/src/controllers/ExplainableRecall.ts +577 -0
- package/src/controllers/NightlyLearner.ts +475 -0
- package/src/controllers/ReflexionMemory.ts +349 -0
- package/src/controllers/SkillLibrary.ts +391 -0
- package/src/controllers/frontier-index.ts +35 -0
- package/src/controllers/index.ts +13 -0
- package/src/optimizations/BatchOperations.ts +292 -0
- package/src/optimizations/QueryOptimizer.ts +294 -0
- package/src/optimizations/index.ts +11 -0
- package/src/schemas/frontier-schema.sql +341 -0
- package/src/schemas/schema.sql +382 -0
- package/CHANGELOG.md +0 -166
- package/LICENSE +0 -38
- package/LICENSE-APACHE +0 -190
- package/LICENSE-MIT +0 -21
- package/bin/agentdb.js +0 -733
- package/bin/benchmark.js +0 -162
- package/bin/plugin-cli-wrapper.mjs +0 -21
- package/dist/agentdb.js +0 -5352
- package/dist/agentdb.js.map +0 -7
- package/dist/agentdb.min.js +0 -143
- package/dist/agentdb.min.js.map +0 -7
- package/dist/cache/query-cache.d.ts +0 -105
- package/dist/cache/query-cache.d.ts.map +0 -1
- package/dist/cache/query-cache.js +0 -224
- package/dist/cache/query-cache.js.map +0 -1
- package/dist/cache/query-cache.mjs +0 -219
- package/dist/cli/cache/query-cache.d.ts +0 -104
- package/dist/cli/cache/query-cache.js +0 -244
- package/dist/cli/cli/db-commands.d.ts +0 -48
- package/dist/cli/cli/db-commands.js +0 -613
- package/dist/cli/commands.d.ts +0 -7
- package/dist/cli/commands.d.ts.map +0 -1
- package/dist/cli/commands.js +0 -113
- package/dist/cli/commands.js.map +0 -1
- package/dist/cli/commands.mjs +0 -104
- package/dist/cli/core/backend-interface.d.ts +0 -70
- package/dist/cli/core/backend-interface.js +0 -15
- package/dist/cli/core/native-backend.d.ts +0 -140
- package/dist/cli/core/native-backend.js +0 -432
- package/dist/cli/core/vector-db.d.ts +0 -126
- package/dist/cli/core/vector-db.js +0 -338
- package/dist/cli/core/wasm-backend.d.ts +0 -95
- package/dist/cli/core/wasm-backend.js +0 -418
- package/dist/cli/db-commands.d.ts +0 -49
- package/dist/cli/db-commands.d.ts.map +0 -1
- package/dist/cli/db-commands.js +0 -533
- package/dist/cli/db-commands.js.map +0 -1
- package/dist/cli/db-commands.mjs +0 -522
- package/dist/cli/generator.d.ts +0 -11
- package/dist/cli/generator.d.ts.map +0 -1
- package/dist/cli/generator.js +0 -567
- package/dist/cli/generator.js.map +0 -1
- package/dist/cli/generator.mjs +0 -527
- package/dist/cli/help.d.ts +0 -18
- package/dist/cli/help.d.ts.map +0 -1
- package/dist/cli/help.js +0 -676
- package/dist/cli/help.js.map +0 -1
- package/dist/cli/help.mjs +0 -667
- package/dist/cli/index/hnsw.d.ts +0 -164
- package/dist/cli/index/hnsw.js +0 -558
- package/dist/cli/plugin-cli.d.ts +0 -7
- package/dist/cli/plugin-cli.d.ts.map +0 -1
- package/dist/cli/plugin-cli.js +0 -295
- package/dist/cli/plugin-cli.js.map +0 -1
- package/dist/cli/plugin-cli.mjs +0 -289
- package/dist/cli/quantization/product-quantization.d.ts +0 -108
- package/dist/cli/quantization/product-quantization.js +0 -350
- package/dist/cli/query/query-builder.d.ts +0 -322
- package/dist/cli/query/query-builder.js +0 -600
- package/dist/cli/templates.d.ts +0 -14
- package/dist/cli/templates.d.ts.map +0 -1
- package/dist/cli/templates.js +0 -182
- package/dist/cli/templates.js.map +0 -1
- package/dist/cli/templates.mjs +0 -176
- package/dist/cli/types/index.d.ts +0 -116
- package/dist/cli/types/index.js +0 -5
- package/dist/cli/types.d.ts +0 -91
- package/dist/cli/types.d.ts.map +0 -1
- package/dist/cli/types.js +0 -6
- package/dist/cli/types.js.map +0 -1
- package/dist/cli/types.mjs +0 -4
- package/dist/cli/wizard/index.d.ts +0 -6
- package/dist/cli/wizard/index.d.ts.map +0 -1
- package/dist/cli/wizard/index.js +0 -138
- package/dist/cli/wizard/index.js.map +0 -1
- package/dist/cli/wizard/index.mjs +0 -131
- package/dist/cli/wizard/prompts.d.ts +0 -11
- package/dist/cli/wizard/prompts.d.ts.map +0 -1
- package/dist/cli/wizard/prompts.js +0 -482
- package/dist/cli/wizard/prompts.js.map +0 -1
- package/dist/cli/wizard/prompts.mjs +0 -470
- package/dist/cli/wizard/validator.d.ts +0 -13
- package/dist/cli/wizard/validator.d.ts.map +0 -1
- package/dist/cli/wizard/validator.js +0 -234
- package/dist/cli/wizard/validator.js.map +0 -1
- package/dist/cli/wizard/validator.mjs +0 -224
- package/dist/core/backend-interface.d.ts +0 -71
- package/dist/core/backend-interface.d.ts.map +0 -1
- package/dist/core/backend-interface.js +0 -16
- package/dist/core/backend-interface.js.map +0 -1
- package/dist/core/backend-interface.mjs +0 -12
- package/dist/core/native-backend.d.ts +0 -141
- package/dist/core/native-backend.d.ts.map +0 -1
- package/dist/core/native-backend.js +0 -457
- package/dist/core/native-backend.js.map +0 -1
- package/dist/core/native-backend.mjs +0 -449
- package/dist/core/vector-db.d.ts +0 -127
- package/dist/core/vector-db.d.ts.map +0 -1
- package/dist/core/vector-db.js +0 -270
- package/dist/core/vector-db.js.map +0 -1
- package/dist/core/vector-db.mjs +0 -265
- package/dist/core/wasm-backend.d.ts +0 -96
- package/dist/core/wasm-backend.d.ts.map +0 -1
- package/dist/core/wasm-backend.js +0 -393
- package/dist/core/wasm-backend.js.map +0 -1
- package/dist/core/wasm-backend.mjs +0 -385
- package/dist/index/hnsw-optimized.d.ts +0 -75
- package/dist/index/hnsw-optimized.d.ts.map +0 -1
- package/dist/index/hnsw-optimized.js +0 -412
- package/dist/index/hnsw-optimized.js.map +0 -1
- package/dist/index/hnsw-optimized.mjs +0 -407
- package/dist/index/hnsw.d.ts +0 -165
- package/dist/index/hnsw.d.ts.map +0 -1
- package/dist/index/hnsw.js +0 -521
- package/dist/index/hnsw.js.map +0 -1
- package/dist/index/hnsw.mjs +0 -516
- package/dist/index.browser.d.ts +0 -47
- package/dist/index.browser.d.ts.map +0 -1
- package/dist/index.browser.js +0 -72
- package/dist/index.browser.js.map +0 -1
- package/dist/index.browser.mjs +0 -54
- package/dist/index.d.ts +0 -59
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -84
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -65
- package/dist/mcp/learning/core/experience-buffer.d.ts +0 -61
- package/dist/mcp/learning/core/experience-buffer.d.ts.map +0 -1
- package/dist/mcp/learning/core/experience-buffer.js +0 -175
- package/dist/mcp/learning/core/experience-buffer.js.map +0 -1
- package/dist/mcp/learning/core/experience-buffer.mjs +0 -170
- package/dist/mcp/learning/core/experience-recorder.d.ts +0 -40
- package/dist/mcp/learning/core/experience-recorder.d.ts.map +0 -1
- package/dist/mcp/learning/core/experience-recorder.js +0 -200
- package/dist/mcp/learning/core/experience-recorder.js.map +0 -1
- package/dist/mcp/learning/core/experience-recorder.mjs +0 -195
- package/dist/mcp/learning/core/learning-manager.d.ts +0 -66
- package/dist/mcp/learning/core/learning-manager.d.ts.map +0 -1
- package/dist/mcp/learning/core/learning-manager.js +0 -252
- package/dist/mcp/learning/core/learning-manager.js.map +0 -1
- package/dist/mcp/learning/core/learning-manager.mjs +0 -247
- package/dist/mcp/learning/core/policy-optimizer.d.ts +0 -53
- package/dist/mcp/learning/core/policy-optimizer.d.ts.map +0 -1
- package/dist/mcp/learning/core/policy-optimizer.js +0 -251
- package/dist/mcp/learning/core/policy-optimizer.js.map +0 -1
- package/dist/mcp/learning/core/policy-optimizer.mjs +0 -246
- package/dist/mcp/learning/core/reward-estimator.d.ts +0 -44
- package/dist/mcp/learning/core/reward-estimator.d.ts.map +0 -1
- package/dist/mcp/learning/core/reward-estimator.js +0 -158
- package/dist/mcp/learning/core/reward-estimator.js.map +0 -1
- package/dist/mcp/learning/core/reward-estimator.mjs +0 -153
- package/dist/mcp/learning/core/session-manager.d.ts +0 -63
- package/dist/mcp/learning/core/session-manager.d.ts.map +0 -1
- package/dist/mcp/learning/core/session-manager.js +0 -202
- package/dist/mcp/learning/core/session-manager.js.map +0 -1
- package/dist/mcp/learning/core/session-manager.mjs +0 -197
- package/dist/mcp/learning/index.d.ts +0 -19
- package/dist/mcp/learning/index.d.ts.map +0 -1
- package/dist/mcp/learning/index.js +0 -30
- package/dist/mcp/learning/index.js.map +0 -1
- package/dist/mcp/learning/index.mjs +0 -19
- package/dist/mcp/learning/tools/mcp-learning-tools.d.ts +0 -369
- package/dist/mcp/learning/tools/mcp-learning-tools.d.ts.map +0 -1
- package/dist/mcp/learning/tools/mcp-learning-tools.js +0 -361
- package/dist/mcp/learning/tools/mcp-learning-tools.js.map +0 -1
- package/dist/mcp/learning/tools/mcp-learning-tools.mjs +0 -356
- package/dist/mcp/learning/types/index.d.ts +0 -138
- package/dist/mcp/learning/types/index.d.ts.map +0 -1
- package/dist/mcp/learning/types/index.js +0 -6
- package/dist/mcp/learning/types/index.js.map +0 -1
- package/dist/mcp/learning/types/index.mjs +0 -4
- package/dist/mcp-server.d.ts +0 -29
- package/dist/mcp-server.d.ts.map +0 -1
- package/dist/mcp-server.js +0 -862
- package/dist/mcp-server.js.map +0 -1
- package/dist/mcp-server.mjs +0 -857
- package/dist/plugins/base-plugin.d.ts +0 -114
- package/dist/plugins/base-plugin.d.ts.map +0 -1
- package/dist/plugins/base-plugin.js +0 -313
- package/dist/plugins/base-plugin.js.map +0 -1
- package/dist/plugins/base-plugin.mjs +0 -275
- package/dist/plugins/implementations/active-learning.d.ts +0 -135
- package/dist/plugins/implementations/active-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/active-learning.js +0 -372
- package/dist/plugins/implementations/active-learning.js.map +0 -1
- package/dist/plugins/implementations/active-learning.mjs +0 -367
- package/dist/plugins/implementations/actor-critic.d.ts +0 -64
- package/dist/plugins/implementations/actor-critic.d.ts.map +0 -1
- package/dist/plugins/implementations/actor-critic.js +0 -363
- package/dist/plugins/implementations/actor-critic.js.map +0 -1
- package/dist/plugins/implementations/actor-critic.mjs +0 -358
- package/dist/plugins/implementations/adversarial-training.d.ts +0 -133
- package/dist/plugins/implementations/adversarial-training.d.ts.map +0 -1
- package/dist/plugins/implementations/adversarial-training.js +0 -409
- package/dist/plugins/implementations/adversarial-training.js.map +0 -1
- package/dist/plugins/implementations/adversarial-training.mjs +0 -404
- package/dist/plugins/implementations/curriculum-learning.d.ts +0 -132
- package/dist/plugins/implementations/curriculum-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/curriculum-learning.js +0 -354
- package/dist/plugins/implementations/curriculum-learning.js.map +0 -1
- package/dist/plugins/implementations/curriculum-learning.mjs +0 -349
- package/dist/plugins/implementations/decision-transformer.d.ts +0 -77
- package/dist/plugins/implementations/decision-transformer.d.ts.map +0 -1
- package/dist/plugins/implementations/decision-transformer.js +0 -422
- package/dist/plugins/implementations/decision-transformer.js.map +0 -1
- package/dist/plugins/implementations/decision-transformer.mjs +0 -417
- package/dist/plugins/implementations/federated-learning.d.ts +0 -126
- package/dist/plugins/implementations/federated-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/federated-learning.js +0 -436
- package/dist/plugins/implementations/federated-learning.js.map +0 -1
- package/dist/plugins/implementations/federated-learning.mjs +0 -431
- package/dist/plugins/implementations/index.d.ts +0 -30
- package/dist/plugins/implementations/index.d.ts.map +0 -1
- package/dist/plugins/implementations/index.js +0 -45
- package/dist/plugins/implementations/index.js.map +0 -1
- package/dist/plugins/implementations/index.mjs +0 -31
- package/dist/plugins/implementations/multi-task-learning.d.ts +0 -115
- package/dist/plugins/implementations/multi-task-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/multi-task-learning.js +0 -369
- package/dist/plugins/implementations/multi-task-learning.js.map +0 -1
- package/dist/plugins/implementations/multi-task-learning.mjs +0 -364
- package/dist/plugins/implementations/neural-architecture-search.d.ts +0 -148
- package/dist/plugins/implementations/neural-architecture-search.d.ts.map +0 -1
- package/dist/plugins/implementations/neural-architecture-search.js +0 -379
- package/dist/plugins/implementations/neural-architecture-search.js.map +0 -1
- package/dist/plugins/implementations/neural-architecture-search.mjs +0 -374
- package/dist/plugins/implementations/q-learning.d.ts +0 -98
- package/dist/plugins/implementations/q-learning.d.ts.map +0 -1
- package/dist/plugins/implementations/q-learning.js +0 -435
- package/dist/plugins/implementations/q-learning.js.map +0 -1
- package/dist/plugins/implementations/q-learning.mjs +0 -430
- package/dist/plugins/implementations/sarsa.d.ts +0 -103
- package/dist/plugins/implementations/sarsa.d.ts.map +0 -1
- package/dist/plugins/implementations/sarsa.js +0 -347
- package/dist/plugins/implementations/sarsa.js.map +0 -1
- package/dist/plugins/implementations/sarsa.mjs +0 -342
- package/dist/plugins/index.d.ts +0 -107
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -179
- package/dist/plugins/index.js.map +0 -1
- package/dist/plugins/index.mjs +0 -168
- package/dist/plugins/interface.d.ts +0 -439
- package/dist/plugins/interface.d.ts.map +0 -1
- package/dist/plugins/interface.js +0 -12
- package/dist/plugins/interface.js.map +0 -1
- package/dist/plugins/interface.mjs +0 -10
- package/dist/plugins/learning-plugin.interface.d.ts +0 -257
- package/dist/plugins/learning-plugin.interface.d.ts.map +0 -1
- package/dist/plugins/learning-plugin.interface.js +0 -7
- package/dist/plugins/learning-plugin.interface.js.map +0 -1
- package/dist/plugins/learning-plugin.interface.mjs +0 -5
- package/dist/plugins/plugin-exports.d.ts +0 -71
- package/dist/plugins/plugin-exports.d.ts.map +0 -1
- package/dist/plugins/plugin-exports.js +0 -78
- package/dist/plugins/plugin-exports.js.map +0 -1
- package/dist/plugins/plugin-exports.mjs +0 -69
- package/dist/plugins/registry.d.ts +0 -206
- package/dist/plugins/registry.d.ts.map +0 -1
- package/dist/plugins/registry.js +0 -365
- package/dist/plugins/registry.js.map +0 -1
- package/dist/plugins/registry.mjs +0 -356
- package/dist/plugins/validator.d.ts +0 -63
- package/dist/plugins/validator.d.ts.map +0 -1
- package/dist/plugins/validator.js +0 -464
- package/dist/plugins/validator.js.map +0 -1
- package/dist/plugins/validator.mjs +0 -458
- package/dist/presets.d.ts +0 -65
- package/dist/presets.d.ts.map +0 -1
- package/dist/presets.js +0 -145
- package/dist/presets.js.map +0 -1
- package/dist/presets.mjs +0 -140
- package/dist/quantization/binary-quantization.d.ts +0 -104
- package/dist/quantization/binary-quantization.d.ts.map +0 -1
- package/dist/quantization/binary-quantization.js +0 -246
- package/dist/quantization/binary-quantization.js.map +0 -1
- package/dist/quantization/binary-quantization.mjs +0 -240
- package/dist/quantization/optimized-pq.d.ts +0 -138
- package/dist/quantization/optimized-pq.d.ts.map +0 -1
- package/dist/quantization/optimized-pq.js +0 -320
- package/dist/quantization/optimized-pq.js.map +0 -1
- package/dist/quantization/optimized-pq.mjs +0 -313
- package/dist/quantization/product-quantization.d.ts +0 -109
- package/dist/quantization/product-quantization.d.ts.map +0 -1
- package/dist/quantization/product-quantization.js +0 -287
- package/dist/quantization/product-quantization.js.map +0 -1
- package/dist/quantization/product-quantization.mjs +0 -282
- package/dist/quantization/scalar-quantization.d.ts +0 -100
- package/dist/quantization/scalar-quantization.d.ts.map +0 -1
- package/dist/quantization/scalar-quantization.js +0 -324
- package/dist/quantization/scalar-quantization.js.map +0 -1
- package/dist/quantization/scalar-quantization.mjs +0 -319
- package/dist/query/index.d.ts +0 -6
- package/dist/query/index.d.ts.map +0 -1
- package/dist/query/index.js +0 -9
- package/dist/query/index.js.map +0 -1
- package/dist/query/index.mjs +0 -4
- package/dist/query/query-builder.d.ts +0 -323
- package/dist/query/query-builder.d.ts.map +0 -1
- package/dist/query/query-builder.js +0 -524
- package/dist/query/query-builder.js.map +0 -1
- package/dist/query/query-builder.mjs +0 -519
- package/dist/reasoning/context-synthesizer.d.ts +0 -57
- package/dist/reasoning/context-synthesizer.d.ts.map +0 -1
- package/dist/reasoning/context-synthesizer.js +0 -224
- package/dist/reasoning/context-synthesizer.js.map +0 -1
- package/dist/reasoning/context-synthesizer.mjs +0 -219
- package/dist/reasoning/experience-curator.d.ts +0 -66
- package/dist/reasoning/experience-curator.d.ts.map +0 -1
- package/dist/reasoning/experience-curator.js +0 -288
- package/dist/reasoning/experience-curator.js.map +0 -1
- package/dist/reasoning/experience-curator.mjs +0 -283
- package/dist/reasoning/memory-optimizer.d.ts +0 -69
- package/dist/reasoning/memory-optimizer.d.ts.map +0 -1
- package/dist/reasoning/memory-optimizer.js +0 -331
- package/dist/reasoning/memory-optimizer.js.map +0 -1
- package/dist/reasoning/memory-optimizer.mjs +0 -326
- package/dist/reasoning/pattern-matcher.d.ts +0 -59
- package/dist/reasoning/pattern-matcher.d.ts.map +0 -1
- package/dist/reasoning/pattern-matcher.js +0 -229
- package/dist/reasoning/pattern-matcher.js.map +0 -1
- package/dist/reasoning/pattern-matcher.mjs +0 -224
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +0 -118
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +0 -1
- package/dist/reasoningbank/adapter/agentdb-adapter.js +0 -477
- package/dist/reasoningbank/adapter/agentdb-adapter.js.map +0 -1
- package/dist/reasoningbank/adapter/types.d.ts +0 -113
- package/dist/reasoningbank/adapter/types.d.ts.map +0 -1
- package/dist/reasoningbank/adapter/types.js +0 -9
- package/dist/reasoningbank/adapter/types.js.map +0 -1
- package/dist/reasoningbank/cli/commands.d.ts +0 -16
- package/dist/reasoningbank/cli/commands.d.ts.map +0 -1
- package/dist/reasoningbank/cli/commands.js +0 -272
- package/dist/reasoningbank/cli/commands.js.map +0 -1
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts +0 -319
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +0 -1
- package/dist/reasoningbank/mcp/agentdb-tools.js +0 -301
- package/dist/reasoningbank/mcp/agentdb-tools.js.map +0 -1
- package/dist/reasoningbank/migration/migrate.d.ts +0 -25
- package/dist/reasoningbank/migration/migrate.d.ts.map +0 -1
- package/dist/reasoningbank/migration/migrate.js +0 -178
- package/dist/reasoningbank/migration/migrate.js.map +0 -1
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +0 -37
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/context-synthesizer.js +0 -114
- package/dist/reasoningbank/reasoning/context-synthesizer.js.map +0 -1
- package/dist/reasoningbank/reasoning/experience-curator.d.ts +0 -39
- package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/experience-curator.js +0 -98
- package/dist/reasoningbank/reasoning/experience-curator.js.map +0 -1
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +0 -44
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/memory-optimizer.js +0 -184
- package/dist/reasoningbank/reasoning/memory-optimizer.js.map +0 -1
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +0 -40
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +0 -1
- package/dist/reasoningbank/reasoning/pattern-matcher.js +0 -87
- package/dist/reasoningbank/reasoning/pattern-matcher.js.map +0 -1
- package/dist/reasoningbank/sync/quic-sync.d.ts +0 -77
- package/dist/reasoningbank/sync/quic-sync.d.ts.map +0 -1
- package/dist/reasoningbank/sync/quic-sync.js +0 -165
- package/dist/reasoningbank/sync/quic-sync.js.map +0 -1
- package/dist/sync/conflict.d.ts +0 -78
- package/dist/sync/conflict.d.ts.map +0 -1
- package/dist/sync/conflict.js +0 -202
- package/dist/sync/conflict.js.map +0 -1
- package/dist/sync/conflict.mjs +0 -196
- package/dist/sync/coordinator.d.ts +0 -111
- package/dist/sync/coordinator.d.ts.map +0 -1
- package/dist/sync/coordinator.js +0 -256
- package/dist/sync/coordinator.js.map +0 -1
- package/dist/sync/coordinator.mjs +0 -250
- package/dist/sync/delta.d.ts +0 -81
- package/dist/sync/delta.d.ts.map +0 -1
- package/dist/sync/delta.js +0 -245
- package/dist/sync/delta.js.map +0 -1
- package/dist/sync/delta.mjs +0 -238
- package/dist/sync/index.d.ts +0 -11
- package/dist/sync/index.d.ts.map +0 -1
- package/dist/sync/index.js +0 -22
- package/dist/sync/index.js.map +0 -1
- package/dist/sync/index.mjs +0 -9
- package/dist/sync/quic-sync.d.ts +0 -81
- package/dist/sync/quic-sync.d.ts.map +0 -1
- package/dist/sync/quic-sync.js +0 -329
- package/dist/sync/quic-sync.js.map +0 -1
- package/dist/sync/quic-sync.mjs +0 -323
- package/dist/sync/types.d.ts +0 -168
- package/dist/sync/types.d.ts.map +0 -1
- package/dist/sync/types.js +0 -8
- package/dist/sync/types.js.map +0 -1
- package/dist/sync/types.mjs +0 -6
- package/dist/types/index.d.ts +0 -117
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -6
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -4
- package/dist/wasm/sql-wasm-debug.js +0 -6989
- package/dist/wasm/sql-wasm-debug.wasm +0 -0
- package/dist/wasm/sql-wasm.js +0 -188
- package/dist/wasm/sql-wasm.wasm +0 -0
- package/dist/wasm-loader.d.ts +0 -32
- package/dist/wasm-loader.d.ts.map +0 -1
- package/dist/wasm-loader.js +0 -78
- package/dist/wasm-loader.js.map +0 -1
- package/dist/wasm-loader.mjs +0 -67
- package/examples/adaptive-learning.ts +0 -284
- package/examples/browser/README.md +0 -732
- package/examples/browser/adaptive-recommendations/index.html +0 -427
- package/examples/browser/collaborative-filtering/index.html +0 -310
- package/examples/browser/continual-learning/index.html +0 -736
- package/examples/browser/experience-replay/index.html +0 -616
- package/examples/browser/index.html +0 -369
- package/examples/browser/meta-learning/index.html +0 -789
- package/examples/browser/neuro-symbolic/index.html +0 -692
- package/examples/browser/pattern-learning/index.html +0 -620
- package/examples/browser/quantum-inspired/index.html +0 -728
- package/examples/browser/rag/index.html +0 -624
- package/examples/browser/swarm-intelligence/index.html +0 -811
- package/examples/browser-basic.html +0 -170
- package/examples/browser-wasm-real.html +0 -231
- package/examples/hnsw-example.ts +0 -148
- package/examples/mcp-learning-example.ts +0 -220
- package/examples/node-basic.js +0 -70
- package/examples/quic-sync-example.ts +0 -310
- package/examples/quick-start.js +0 -68
- package/examples/test-v1.0.7-cdn.html +0 -190
- package/examples/wasm-example.ts +0 -222
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nightly Learner - Automated Causal Discovery and Consolidation
|
|
3
|
+
*
|
|
4
|
+
* Runs as a background job to:
|
|
5
|
+
* 1. Discover new causal edges from episode patterns
|
|
6
|
+
* 2. Run A/B experiments on promising hypotheses
|
|
7
|
+
* 3. Calculate uplift for completed experiments
|
|
8
|
+
* 4. Prune low-confidence edges
|
|
9
|
+
* 5. Update rerank weights based on performance
|
|
10
|
+
*
|
|
11
|
+
* Based on doubly robust learner:
|
|
12
|
+
* τ̂(x) = μ1(x) − μ0(x) + [a*(y−μ1(x)) / e(x)] − [(1−a)*(y−μ0(x)) / (1−e(x))]
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { Database } from 'better-sqlite3';
|
|
16
|
+
import { CausalMemoryGraph, CausalEdge } from './CausalMemoryGraph.js';
|
|
17
|
+
import { ReflexionMemory } from './ReflexionMemory.js';
|
|
18
|
+
import { SkillLibrary } from './SkillLibrary.js';
|
|
19
|
+
import { EmbeddingService } from './EmbeddingService.js';
|
|
20
|
+
|
|
21
|
+
export interface LearnerConfig {
|
|
22
|
+
minSimilarity: number; // Min similarity to consider for causal edge (default: 0.7)
|
|
23
|
+
minSampleSize: number; // Min observations for uplift calculation (default: 30)
|
|
24
|
+
confidenceThreshold: number; // Min confidence to keep edge (default: 0.6)
|
|
25
|
+
upliftThreshold: number; // Min absolute uplift to consider significant (default: 0.05)
|
|
26
|
+
pruneOldEdges: boolean; // Remove edges older than X days (default: true)
|
|
27
|
+
edgeMaxAgeDays: number; // Max age for edges (default: 90)
|
|
28
|
+
autoExperiments: boolean; // Automatically create A/B experiments (default: true)
|
|
29
|
+
experimentBudget: number; // Max experiments to run concurrently (default: 10)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface LearnerReport {
|
|
33
|
+
timestamp: number;
|
|
34
|
+
executionTimeMs: number;
|
|
35
|
+
edgesDiscovered: number;
|
|
36
|
+
edgesPruned: number;
|
|
37
|
+
experimentsCompleted: number;
|
|
38
|
+
experimentsCreated: number;
|
|
39
|
+
avgUplift: number;
|
|
40
|
+
avgConfidence: number;
|
|
41
|
+
recommendations: string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class NightlyLearner {
|
|
45
|
+
private db: Database;
|
|
46
|
+
private causalGraph: CausalMemoryGraph;
|
|
47
|
+
private reflexion: ReflexionMemory;
|
|
48
|
+
private skillLibrary: SkillLibrary;
|
|
49
|
+
|
|
50
|
+
constructor(
|
|
51
|
+
db: Database,
|
|
52
|
+
embedder: EmbeddingService,
|
|
53
|
+
private config: LearnerConfig = {
|
|
54
|
+
minSimilarity: 0.7,
|
|
55
|
+
minSampleSize: 30,
|
|
56
|
+
confidenceThreshold: 0.6,
|
|
57
|
+
upliftThreshold: 0.05,
|
|
58
|
+
pruneOldEdges: true,
|
|
59
|
+
edgeMaxAgeDays: 90,
|
|
60
|
+
autoExperiments: true,
|
|
61
|
+
experimentBudget: 10
|
|
62
|
+
}
|
|
63
|
+
) {
|
|
64
|
+
this.db = db;
|
|
65
|
+
this.causalGraph = new CausalMemoryGraph(db);
|
|
66
|
+
this.reflexion = new ReflexionMemory(db, embedder);
|
|
67
|
+
this.skillLibrary = new SkillLibrary(db, embedder);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Main learning job - runs all discovery and consolidation tasks
|
|
72
|
+
*/
|
|
73
|
+
async run(): Promise<LearnerReport> {
|
|
74
|
+
console.log('\n🌙 Nightly Learner Starting...\n');
|
|
75
|
+
const startTime = Date.now();
|
|
76
|
+
|
|
77
|
+
const report: LearnerReport = {
|
|
78
|
+
timestamp: startTime,
|
|
79
|
+
executionTimeMs: 0,
|
|
80
|
+
edgesDiscovered: 0,
|
|
81
|
+
edgesPruned: 0,
|
|
82
|
+
experimentsCompleted: 0,
|
|
83
|
+
experimentsCreated: 0,
|
|
84
|
+
avgUplift: 0,
|
|
85
|
+
avgConfidence: 0,
|
|
86
|
+
recommendations: []
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
// Step 1: Discover new causal edges
|
|
91
|
+
console.log('📊 Discovering causal edges from episode patterns...');
|
|
92
|
+
report.edgesDiscovered = await this.discoverCausalEdges();
|
|
93
|
+
console.log(` ✓ Discovered ${report.edgesDiscovered} new edges\n`);
|
|
94
|
+
|
|
95
|
+
// Step 2: Complete running experiments
|
|
96
|
+
console.log('🧪 Completing A/B experiments...');
|
|
97
|
+
report.experimentsCompleted = await this.completeExperiments();
|
|
98
|
+
console.log(` ✓ Completed ${report.experimentsCompleted} experiments\n`);
|
|
99
|
+
|
|
100
|
+
// Step 3: Create new experiments (if enabled)
|
|
101
|
+
if (this.config.autoExperiments) {
|
|
102
|
+
console.log('🔬 Creating new A/B experiments...');
|
|
103
|
+
report.experimentsCreated = await this.createExperiments();
|
|
104
|
+
console.log(` ✓ Created ${report.experimentsCreated} new experiments\n`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Step 4: Prune low-confidence edges
|
|
108
|
+
if (this.config.pruneOldEdges) {
|
|
109
|
+
console.log('🧹 Pruning low-confidence edges...');
|
|
110
|
+
report.edgesPruned = await this.pruneEdges();
|
|
111
|
+
console.log(` ✓ Pruned ${report.edgesPruned} edges\n`);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Step 5: Calculate statistics
|
|
115
|
+
const stats = this.calculateStats();
|
|
116
|
+
report.avgUplift = stats.avgUplift;
|
|
117
|
+
report.avgConfidence = stats.avgConfidence;
|
|
118
|
+
|
|
119
|
+
// Step 6: Generate recommendations
|
|
120
|
+
report.recommendations = this.generateRecommendations(report);
|
|
121
|
+
|
|
122
|
+
report.executionTimeMs = Date.now() - startTime;
|
|
123
|
+
|
|
124
|
+
console.log('✅ Nightly Learner Completed\n');
|
|
125
|
+
this.printReport(report);
|
|
126
|
+
|
|
127
|
+
return report;
|
|
128
|
+
} catch (error) {
|
|
129
|
+
console.error('❌ Nightly Learner Failed:', error);
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Discover causal edges using doubly robust learner
|
|
136
|
+
*
|
|
137
|
+
* τ̂(x) = μ1(x) − μ0(x) + [a*(y−μ1(x)) / e(x)] − [(1−a)*(y−μ0(x)) / (1−e(x))]
|
|
138
|
+
*
|
|
139
|
+
* Where:
|
|
140
|
+
* - μ1(x) = outcome model for treatment
|
|
141
|
+
* - μ0(x) = outcome model for control
|
|
142
|
+
* - e(x) = propensity score (probability of treatment)
|
|
143
|
+
* - a = treatment indicator
|
|
144
|
+
* - y = observed outcome
|
|
145
|
+
*/
|
|
146
|
+
async discover(config: {
|
|
147
|
+
minAttempts?: number;
|
|
148
|
+
minSuccessRate?: number;
|
|
149
|
+
minConfidence?: number;
|
|
150
|
+
dryRun?: boolean;
|
|
151
|
+
}): Promise<CausalEdge[]> {
|
|
152
|
+
return this.discoverCausalEdges();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
private async discoverCausalEdges(): Promise<number> {
|
|
156
|
+
let discovered = 0;
|
|
157
|
+
|
|
158
|
+
// Find episode pairs with high similarity and temporal sequence
|
|
159
|
+
const candidatePairs = this.db.prepare(`
|
|
160
|
+
SELECT
|
|
161
|
+
e1.id as from_id,
|
|
162
|
+
e1.task as from_task,
|
|
163
|
+
e1.reward as from_reward,
|
|
164
|
+
e2.id as to_id,
|
|
165
|
+
e2.task as to_task,
|
|
166
|
+
e2.reward as to_reward,
|
|
167
|
+
e2.ts - e1.ts as time_diff
|
|
168
|
+
FROM episodes e1
|
|
169
|
+
JOIN episodes e2 ON e1.session_id = e2.session_id
|
|
170
|
+
WHERE e1.id != e2.id
|
|
171
|
+
AND e2.ts > e1.ts
|
|
172
|
+
AND e2.ts - e1.ts < 3600 -- Within 1 hour
|
|
173
|
+
ORDER BY e1.id, e2.ts
|
|
174
|
+
LIMIT 1000
|
|
175
|
+
`).all() as any[];
|
|
176
|
+
|
|
177
|
+
for (const pair of candidatePairs) {
|
|
178
|
+
// Check if edge already exists
|
|
179
|
+
const existing = this.db.prepare(`
|
|
180
|
+
SELECT id FROM causal_edges
|
|
181
|
+
WHERE from_memory_id = ? AND to_memory_id = ?
|
|
182
|
+
`).get(pair.from_id, pair.to_id);
|
|
183
|
+
|
|
184
|
+
if (existing) continue;
|
|
185
|
+
|
|
186
|
+
// Calculate propensity score e(x) - probability of treatment
|
|
187
|
+
// Simplified: use frequency of from_task in session
|
|
188
|
+
const propensity = this.calculatePropensity(pair.from_id);
|
|
189
|
+
|
|
190
|
+
// Calculate outcome models μ1(x) and μ0(x)
|
|
191
|
+
const mu1 = this.calculateOutcomeModel(pair.from_task, true); // With treatment
|
|
192
|
+
const mu0 = this.calculateOutcomeModel(pair.from_task, false); // Without treatment
|
|
193
|
+
|
|
194
|
+
// Calculate doubly robust estimator
|
|
195
|
+
const a = 1; // This is a treated observation
|
|
196
|
+
const y = pair.to_reward;
|
|
197
|
+
const doublyRobustEstimate = (mu1 - mu0) + (a * (y - mu1) / propensity);
|
|
198
|
+
|
|
199
|
+
// Calculate confidence based on sample size and variance
|
|
200
|
+
const sampleSize = this.getSampleSize(pair.from_task);
|
|
201
|
+
const confidence = this.calculateConfidence(sampleSize, doublyRobustEstimate);
|
|
202
|
+
|
|
203
|
+
// Only add if meets thresholds
|
|
204
|
+
if (Math.abs(doublyRobustEstimate) >= this.config.upliftThreshold && confidence >= this.config.confidenceThreshold) {
|
|
205
|
+
const edge: CausalEdge = {
|
|
206
|
+
fromMemoryId: pair.from_id,
|
|
207
|
+
fromMemoryType: 'episode',
|
|
208
|
+
toMemoryId: pair.to_id,
|
|
209
|
+
toMemoryType: 'episode',
|
|
210
|
+
similarity: 0.8, // Simplified - would use embedding similarity in production
|
|
211
|
+
uplift: doublyRobustEstimate,
|
|
212
|
+
confidence,
|
|
213
|
+
sampleSize,
|
|
214
|
+
mechanism: `${pair.from_task} → ${pair.to_task} (doubly robust)`,
|
|
215
|
+
metadata: {
|
|
216
|
+
propensity,
|
|
217
|
+
mu1,
|
|
218
|
+
mu0,
|
|
219
|
+
discoveredAt: Date.now()
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
this.causalGraph.addCausalEdge(edge);
|
|
224
|
+
discovered++;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return discovered;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Calculate propensity score e(x) - probability of treatment given context
|
|
233
|
+
*/
|
|
234
|
+
private calculatePropensity(episodeId: number): number {
|
|
235
|
+
const episode = this.db.prepare('SELECT task, session_id FROM episodes WHERE id = ?').get(episodeId) as any;
|
|
236
|
+
|
|
237
|
+
// Count occurrences of this task type in session
|
|
238
|
+
const counts = this.db.prepare(`
|
|
239
|
+
SELECT
|
|
240
|
+
COUNT(*) as total,
|
|
241
|
+
SUM(CASE WHEN task = ? THEN 1 ELSE 0 END) as task_count
|
|
242
|
+
FROM episodes
|
|
243
|
+
WHERE session_id = ?
|
|
244
|
+
`).get(episode.task, episode.session_id) as any;
|
|
245
|
+
|
|
246
|
+
const propensity = counts.task_count / Math.max(counts.total, 1);
|
|
247
|
+
|
|
248
|
+
// Clip to avoid division by zero
|
|
249
|
+
return Math.max(0.01, Math.min(0.99, propensity));
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Calculate outcome model μ(x) - expected outcome given treatment status
|
|
254
|
+
*/
|
|
255
|
+
private calculateOutcomeModel(task: string, treated: boolean): number {
|
|
256
|
+
// Get average reward for episodes with/without this task in their history
|
|
257
|
+
const avgReward = this.db.prepare(`
|
|
258
|
+
SELECT AVG(reward) as avg_reward
|
|
259
|
+
FROM episodes
|
|
260
|
+
WHERE ${treated ? '' : 'NOT'} EXISTS (
|
|
261
|
+
SELECT 1 FROM episodes e2
|
|
262
|
+
WHERE e2.session_id = episodes.session_id
|
|
263
|
+
AND e2.task = ?
|
|
264
|
+
AND e2.ts < episodes.ts
|
|
265
|
+
)
|
|
266
|
+
`).get(task) as any;
|
|
267
|
+
|
|
268
|
+
return avgReward?.avg_reward || 0.5;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Get sample size for a task type
|
|
273
|
+
*/
|
|
274
|
+
private getSampleSize(task: string): number {
|
|
275
|
+
const count = this.db.prepare(`
|
|
276
|
+
SELECT COUNT(*) as count
|
|
277
|
+
FROM episodes
|
|
278
|
+
WHERE task = ?
|
|
279
|
+
`).get(task) as any;
|
|
280
|
+
|
|
281
|
+
return count.count;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Calculate confidence based on sample size and effect size
|
|
286
|
+
*/
|
|
287
|
+
private calculateConfidence(sampleSize: number, uplift: number): number {
|
|
288
|
+
// Simplified confidence calculation
|
|
289
|
+
// In production, use proper statistical methods (bootstrap, etc.)
|
|
290
|
+
|
|
291
|
+
const sampleFactor = Math.min(sampleSize / 100, 1.0); // Max at 100 samples
|
|
292
|
+
const effectSizeFactor = Math.min(Math.abs(uplift) / 0.5, 1.0); // Max at 0.5 uplift
|
|
293
|
+
|
|
294
|
+
return sampleFactor * effectSizeFactor;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Complete running A/B experiments and calculate uplift
|
|
299
|
+
*/
|
|
300
|
+
private async completeExperiments(): Promise<number> {
|
|
301
|
+
const runningExperiments = this.db.prepare(`
|
|
302
|
+
SELECT id, start_time, sample_size
|
|
303
|
+
FROM causal_experiments
|
|
304
|
+
WHERE status = 'running'
|
|
305
|
+
AND sample_size >= ?
|
|
306
|
+
`).all(this.config.minSampleSize) as any[];
|
|
307
|
+
|
|
308
|
+
let completed = 0;
|
|
309
|
+
|
|
310
|
+
for (const exp of runningExperiments) {
|
|
311
|
+
try {
|
|
312
|
+
this.causalGraph.calculateUplift(exp.id);
|
|
313
|
+
completed++;
|
|
314
|
+
} catch (error) {
|
|
315
|
+
console.error(` ⚠ Failed to calculate uplift for experiment ${exp.id}:`, error);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
return completed;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Create new A/B experiments for promising hypotheses
|
|
324
|
+
*/
|
|
325
|
+
private async createExperiments(): Promise<number> {
|
|
326
|
+
const currentExperiments = this.db.prepare(`
|
|
327
|
+
SELECT COUNT(*) as count
|
|
328
|
+
FROM causal_experiments
|
|
329
|
+
WHERE status = 'running'
|
|
330
|
+
`).get() as any;
|
|
331
|
+
|
|
332
|
+
const available = this.config.experimentBudget - currentExperiments.count;
|
|
333
|
+
if (available <= 0) {
|
|
334
|
+
return 0;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// Find promising task pairs that don't have experiments yet
|
|
338
|
+
const candidates = this.db.prepare(`
|
|
339
|
+
SELECT DISTINCT
|
|
340
|
+
e1.task as treatment_task,
|
|
341
|
+
e1.id as treatment_id,
|
|
342
|
+
COUNT(e2.id) as potential_outcomes
|
|
343
|
+
FROM episodes e1
|
|
344
|
+
JOIN episodes e2 ON e1.session_id = e2.session_id
|
|
345
|
+
WHERE e2.ts > e1.ts
|
|
346
|
+
AND NOT EXISTS (
|
|
347
|
+
SELECT 1 FROM causal_experiments
|
|
348
|
+
WHERE treatment_id = e1.id
|
|
349
|
+
)
|
|
350
|
+
GROUP BY e1.task, e1.id
|
|
351
|
+
HAVING COUNT(e2.id) >= ?
|
|
352
|
+
ORDER BY COUNT(e2.id) DESC
|
|
353
|
+
LIMIT ?
|
|
354
|
+
`).all(this.config.minSampleSize, available) as any[];
|
|
355
|
+
|
|
356
|
+
let created = 0;
|
|
357
|
+
|
|
358
|
+
for (const candidate of candidates) {
|
|
359
|
+
const expId = this.causalGraph.createExperiment({
|
|
360
|
+
name: `Auto: ${candidate.treatment_task} Impact`,
|
|
361
|
+
hypothesis: `${candidate.treatment_task} affects downstream outcomes`,
|
|
362
|
+
treatmentId: candidate.treatment_id,
|
|
363
|
+
treatmentType: 'episode',
|
|
364
|
+
startTime: Date.now(),
|
|
365
|
+
sampleSize: 0,
|
|
366
|
+
status: 'running',
|
|
367
|
+
metadata: {
|
|
368
|
+
autoGenerated: true,
|
|
369
|
+
potentialOutcomes: candidate.potential_outcomes
|
|
370
|
+
}
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
created++;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return created;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Prune old or low-confidence edges
|
|
381
|
+
*/
|
|
382
|
+
private async pruneEdges(): Promise<number> {
|
|
383
|
+
const maxAgeMs = this.config.edgeMaxAgeDays * 24 * 60 * 60 * 1000;
|
|
384
|
+
const cutoffTime = Date.now() / 1000 - maxAgeMs / 1000;
|
|
385
|
+
|
|
386
|
+
const result = this.db.prepare(`
|
|
387
|
+
DELETE FROM causal_edges
|
|
388
|
+
WHERE confidence < ?
|
|
389
|
+
OR created_at < ?
|
|
390
|
+
`).run(this.config.confidenceThreshold, cutoffTime);
|
|
391
|
+
|
|
392
|
+
return result.changes;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Calculate overall statistics
|
|
397
|
+
*/
|
|
398
|
+
private calculateStats(): { avgUplift: number; avgConfidence: number } {
|
|
399
|
+
const stats = this.db.prepare(`
|
|
400
|
+
SELECT
|
|
401
|
+
AVG(ABS(uplift)) as avg_uplift,
|
|
402
|
+
AVG(confidence) as avg_confidence
|
|
403
|
+
FROM causal_edges
|
|
404
|
+
WHERE uplift IS NOT NULL
|
|
405
|
+
`).get() as any;
|
|
406
|
+
|
|
407
|
+
return {
|
|
408
|
+
avgUplift: stats?.avg_uplift || 0,
|
|
409
|
+
avgConfidence: stats?.avg_confidence || 0
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Generate recommendations based on learning results
|
|
415
|
+
*/
|
|
416
|
+
private generateRecommendations(report: LearnerReport): string[] {
|
|
417
|
+
const recommendations: string[] = [];
|
|
418
|
+
|
|
419
|
+
if (report.edgesDiscovered === 0) {
|
|
420
|
+
recommendations.push('No new causal edges discovered. Consider collecting more diverse episode data.');
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (report.avgUplift < 0.1) {
|
|
424
|
+
recommendations.push('Average uplift is low. Review task sequences for optimization opportunities.');
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (report.avgConfidence < 0.7) {
|
|
428
|
+
recommendations.push('Average confidence is below target. Increase sample sizes or refine hypothesis selection.');
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
if (report.experimentsCompleted > 0) {
|
|
432
|
+
recommendations.push(`${report.experimentsCompleted} experiments completed. Review results for actionable insights.`);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
if (report.edgesPruned > report.edgesDiscovered) {
|
|
436
|
+
recommendations.push('More edges pruned than discovered. Consider adjusting confidence thresholds.');
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
return recommendations;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Print report to console
|
|
444
|
+
*/
|
|
445
|
+
private printReport(report: LearnerReport): void {
|
|
446
|
+
console.log('═══════════════════════════════════════════════════════════');
|
|
447
|
+
console.log(' Nightly Learner Report');
|
|
448
|
+
console.log('═══════════════════════════════════════════════════════════\n');
|
|
449
|
+
console.log(` Execution Time: ${report.executionTimeMs}ms`);
|
|
450
|
+
console.log(` Timestamp: ${new Date(report.timestamp).toISOString()}\n`);
|
|
451
|
+
console.log(' Results:');
|
|
452
|
+
console.log(` • Edges Discovered: ${report.edgesDiscovered}`);
|
|
453
|
+
console.log(` • Edges Pruned: ${report.edgesPruned}`);
|
|
454
|
+
console.log(` • Experiments Completed: ${report.experimentsCompleted}`);
|
|
455
|
+
console.log(` • Experiments Created: ${report.experimentsCreated}\n`);
|
|
456
|
+
console.log(' Statistics:');
|
|
457
|
+
console.log(` • Avg Uplift: ${report.avgUplift.toFixed(3)}`);
|
|
458
|
+
console.log(` • Avg Confidence: ${report.avgConfidence.toFixed(3)}\n`);
|
|
459
|
+
|
|
460
|
+
if (report.recommendations.length > 0) {
|
|
461
|
+
console.log(' Recommendations:');
|
|
462
|
+
report.recommendations.forEach(rec => console.log(` • ${rec}`));
|
|
463
|
+
console.log('');
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
console.log('═══════════════════════════════════════════════════════════\n');
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
/**
|
|
470
|
+
* Update learner configuration
|
|
471
|
+
*/
|
|
472
|
+
updateConfig(config: Partial<LearnerConfig>): void {
|
|
473
|
+
this.config = { ...this.config, ...config };
|
|
474
|
+
}
|
|
475
|
+
}
|