agentdb 1.0.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/LICENSE +38 -0
- package/LICENSE-APACHE +190 -0
- package/LICENSE-MIT +21 -0
- package/README.md +953 -0
- package/bin/agentdb.js +485 -0
- package/bin/plugin-cli-wrapper.mjs +21 -0
- package/dist/cache/query-cache.d.ts +105 -0
- package/dist/cache/query-cache.d.ts.map +1 -0
- package/dist/cache/query-cache.js +224 -0
- package/dist/cache/query-cache.js.map +1 -0
- package/dist/cache/query-cache.mjs +219 -0
- package/dist/cli/cache/query-cache.d.ts +104 -0
- package/dist/cli/cache/query-cache.js +244 -0
- package/dist/cli/cli/db-commands.d.ts +48 -0
- package/dist/cli/cli/db-commands.js +613 -0
- package/dist/cli/commands.d.ts +7 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +113 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/commands.mjs +104 -0
- package/dist/cli/core/backend-interface.d.ts +70 -0
- package/dist/cli/core/backend-interface.js +15 -0
- package/dist/cli/core/native-backend.d.ts +140 -0
- package/dist/cli/core/native-backend.js +432 -0
- package/dist/cli/core/vector-db.d.ts +126 -0
- package/dist/cli/core/vector-db.js +338 -0
- package/dist/cli/core/wasm-backend.d.ts +95 -0
- package/dist/cli/core/wasm-backend.js +418 -0
- package/dist/cli/db-commands.d.ts +49 -0
- package/dist/cli/db-commands.d.ts.map +1 -0
- package/dist/cli/db-commands.js +533 -0
- package/dist/cli/db-commands.js.map +1 -0
- package/dist/cli/db-commands.mjs +522 -0
- package/dist/cli/generator.d.ts +11 -0
- package/dist/cli/generator.d.ts.map +1 -0
- package/dist/cli/generator.js +567 -0
- package/dist/cli/generator.js.map +1 -0
- package/dist/cli/generator.mjs +527 -0
- package/dist/cli/help.d.ts +18 -0
- package/dist/cli/help.d.ts.map +1 -0
- package/dist/cli/help.js +676 -0
- package/dist/cli/help.js.map +1 -0
- package/dist/cli/help.mjs +667 -0
- package/dist/cli/index/hnsw.d.ts +164 -0
- package/dist/cli/index/hnsw.js +558 -0
- package/dist/cli/plugin-cli.d.ts +7 -0
- package/dist/cli/plugin-cli.d.ts.map +1 -0
- package/dist/cli/plugin-cli.js +295 -0
- package/dist/cli/plugin-cli.js.map +1 -0
- package/dist/cli/plugin-cli.mjs +289 -0
- package/dist/cli/quantization/product-quantization.d.ts +108 -0
- package/dist/cli/quantization/product-quantization.js +350 -0
- package/dist/cli/query/query-builder.d.ts +322 -0
- package/dist/cli/query/query-builder.js +600 -0
- package/dist/cli/templates.d.ts +14 -0
- package/dist/cli/templates.d.ts.map +1 -0
- package/dist/cli/templates.js +182 -0
- package/dist/cli/templates.js.map +1 -0
- package/dist/cli/templates.mjs +176 -0
- package/dist/cli/types/index.d.ts +116 -0
- package/dist/cli/types/index.js +5 -0
- package/dist/cli/types.d.ts +91 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +6 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/types.mjs +4 -0
- package/dist/cli/wizard/index.d.ts +6 -0
- package/dist/cli/wizard/index.d.ts.map +1 -0
- package/dist/cli/wizard/index.js +138 -0
- package/dist/cli/wizard/index.js.map +1 -0
- package/dist/cli/wizard/index.mjs +131 -0
- package/dist/cli/wizard/prompts.d.ts +11 -0
- package/dist/cli/wizard/prompts.d.ts.map +1 -0
- package/dist/cli/wizard/prompts.js +482 -0
- package/dist/cli/wizard/prompts.js.map +1 -0
- package/dist/cli/wizard/prompts.mjs +470 -0
- package/dist/cli/wizard/validator.d.ts +13 -0
- package/dist/cli/wizard/validator.d.ts.map +1 -0
- package/dist/cli/wizard/validator.js +234 -0
- package/dist/cli/wizard/validator.js.map +1 -0
- package/dist/cli/wizard/validator.mjs +224 -0
- package/dist/core/backend-interface.d.ts +71 -0
- package/dist/core/backend-interface.d.ts.map +1 -0
- package/dist/core/backend-interface.js +16 -0
- package/dist/core/backend-interface.js.map +1 -0
- package/dist/core/backend-interface.mjs +12 -0
- package/dist/core/native-backend.d.ts +141 -0
- package/dist/core/native-backend.d.ts.map +1 -0
- package/dist/core/native-backend.js +457 -0
- package/dist/core/native-backend.js.map +1 -0
- package/dist/core/native-backend.mjs +449 -0
- package/dist/core/vector-db.d.ts +127 -0
- package/dist/core/vector-db.d.ts.map +1 -0
- package/dist/core/vector-db.js +266 -0
- package/dist/core/vector-db.js.map +1 -0
- package/dist/core/vector-db.mjs +261 -0
- package/dist/core/wasm-backend.d.ts +96 -0
- package/dist/core/wasm-backend.d.ts.map +1 -0
- package/dist/core/wasm-backend.js +393 -0
- package/dist/core/wasm-backend.js.map +1 -0
- package/dist/core/wasm-backend.mjs +385 -0
- package/dist/index/hnsw-optimized.d.ts +75 -0
- package/dist/index/hnsw-optimized.d.ts.map +1 -0
- package/dist/index/hnsw-optimized.js +412 -0
- package/dist/index/hnsw-optimized.js.map +1 -0
- package/dist/index/hnsw-optimized.mjs +407 -0
- package/dist/index/hnsw.d.ts +165 -0
- package/dist/index/hnsw.d.ts.map +1 -0
- package/dist/index/hnsw.js +521 -0
- package/dist/index/hnsw.js.map +1 -0
- package/dist/index/hnsw.mjs +516 -0
- package/dist/index.d.ts +57 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +82 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -0
- package/dist/mcp-server.d.ts +27 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +789 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/mcp-server.mjs +784 -0
- package/dist/plugins/base-plugin.d.ts +114 -0
- package/dist/plugins/base-plugin.d.ts.map +1 -0
- package/dist/plugins/base-plugin.js +313 -0
- package/dist/plugins/base-plugin.js.map +1 -0
- package/dist/plugins/base-plugin.mjs +275 -0
- package/dist/plugins/implementations/active-learning.d.ts +135 -0
- package/dist/plugins/implementations/active-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/active-learning.js +372 -0
- package/dist/plugins/implementations/active-learning.js.map +1 -0
- package/dist/plugins/implementations/active-learning.mjs +367 -0
- package/dist/plugins/implementations/actor-critic.d.ts +64 -0
- package/dist/plugins/implementations/actor-critic.d.ts.map +1 -0
- package/dist/plugins/implementations/actor-critic.js +363 -0
- package/dist/plugins/implementations/actor-critic.js.map +1 -0
- package/dist/plugins/implementations/actor-critic.mjs +358 -0
- package/dist/plugins/implementations/adversarial-training.d.ts +133 -0
- package/dist/plugins/implementations/adversarial-training.d.ts.map +1 -0
- package/dist/plugins/implementations/adversarial-training.js +409 -0
- package/dist/plugins/implementations/adversarial-training.js.map +1 -0
- package/dist/plugins/implementations/adversarial-training.mjs +404 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts +132 -0
- package/dist/plugins/implementations/curriculum-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.js +354 -0
- package/dist/plugins/implementations/curriculum-learning.js.map +1 -0
- package/dist/plugins/implementations/curriculum-learning.mjs +349 -0
- package/dist/plugins/implementations/decision-transformer.d.ts +77 -0
- package/dist/plugins/implementations/decision-transformer.d.ts.map +1 -0
- package/dist/plugins/implementations/decision-transformer.js +422 -0
- package/dist/plugins/implementations/decision-transformer.js.map +1 -0
- package/dist/plugins/implementations/decision-transformer.mjs +417 -0
- package/dist/plugins/implementations/federated-learning.d.ts +126 -0
- package/dist/plugins/implementations/federated-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/federated-learning.js +436 -0
- package/dist/plugins/implementations/federated-learning.js.map +1 -0
- package/dist/plugins/implementations/federated-learning.mjs +431 -0
- package/dist/plugins/implementations/index.d.ts +30 -0
- package/dist/plugins/implementations/index.d.ts.map +1 -0
- package/dist/plugins/implementations/index.js +45 -0
- package/dist/plugins/implementations/index.js.map +1 -0
- package/dist/plugins/implementations/index.mjs +31 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts +115 -0
- package/dist/plugins/implementations/multi-task-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.js +369 -0
- package/dist/plugins/implementations/multi-task-learning.js.map +1 -0
- package/dist/plugins/implementations/multi-task-learning.mjs +364 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts +148 -0
- package/dist/plugins/implementations/neural-architecture-search.d.ts.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.js +379 -0
- package/dist/plugins/implementations/neural-architecture-search.js.map +1 -0
- package/dist/plugins/implementations/neural-architecture-search.mjs +374 -0
- package/dist/plugins/implementations/q-learning.d.ts +98 -0
- package/dist/plugins/implementations/q-learning.d.ts.map +1 -0
- package/dist/plugins/implementations/q-learning.js +435 -0
- package/dist/plugins/implementations/q-learning.js.map +1 -0
- package/dist/plugins/implementations/q-learning.mjs +430 -0
- package/dist/plugins/implementations/sarsa.d.ts +103 -0
- package/dist/plugins/implementations/sarsa.d.ts.map +1 -0
- package/dist/plugins/implementations/sarsa.js +347 -0
- package/dist/plugins/implementations/sarsa.js.map +1 -0
- package/dist/plugins/implementations/sarsa.mjs +342 -0
- package/dist/plugins/index.d.ts +107 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +179 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/index.mjs +168 -0
- package/dist/plugins/interface.d.ts +439 -0
- package/dist/plugins/interface.d.ts.map +1 -0
- package/dist/plugins/interface.js +12 -0
- package/dist/plugins/interface.js.map +1 -0
- package/dist/plugins/interface.mjs +10 -0
- package/dist/plugins/learning-plugin.interface.d.ts +257 -0
- package/dist/plugins/learning-plugin.interface.d.ts.map +1 -0
- package/dist/plugins/learning-plugin.interface.js +7 -0
- package/dist/plugins/learning-plugin.interface.js.map +1 -0
- package/dist/plugins/learning-plugin.interface.mjs +5 -0
- package/dist/plugins/plugin-exports.d.ts +71 -0
- package/dist/plugins/plugin-exports.d.ts.map +1 -0
- package/dist/plugins/plugin-exports.js +78 -0
- package/dist/plugins/plugin-exports.js.map +1 -0
- package/dist/plugins/plugin-exports.mjs +69 -0
- package/dist/plugins/registry.d.ts +206 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +365 -0
- package/dist/plugins/registry.js.map +1 -0
- package/dist/plugins/registry.mjs +356 -0
- package/dist/plugins/validator.d.ts +63 -0
- package/dist/plugins/validator.d.ts.map +1 -0
- package/dist/plugins/validator.js +464 -0
- package/dist/plugins/validator.js.map +1 -0
- package/dist/plugins/validator.mjs +458 -0
- package/dist/quantization/binary-quantization.d.ts +104 -0
- package/dist/quantization/binary-quantization.d.ts.map +1 -0
- package/dist/quantization/binary-quantization.js +246 -0
- package/dist/quantization/binary-quantization.js.map +1 -0
- package/dist/quantization/binary-quantization.mjs +240 -0
- package/dist/quantization/optimized-pq.d.ts +138 -0
- package/dist/quantization/optimized-pq.d.ts.map +1 -0
- package/dist/quantization/optimized-pq.js +320 -0
- package/dist/quantization/optimized-pq.js.map +1 -0
- package/dist/quantization/optimized-pq.mjs +313 -0
- package/dist/quantization/product-quantization.d.ts +109 -0
- package/dist/quantization/product-quantization.d.ts.map +1 -0
- package/dist/quantization/product-quantization.js +287 -0
- package/dist/quantization/product-quantization.js.map +1 -0
- package/dist/quantization/product-quantization.mjs +282 -0
- package/dist/quantization/scalar-quantization.d.ts +100 -0
- package/dist/quantization/scalar-quantization.d.ts.map +1 -0
- package/dist/quantization/scalar-quantization.js +324 -0
- package/dist/quantization/scalar-quantization.js.map +1 -0
- package/dist/quantization/scalar-quantization.mjs +319 -0
- package/dist/query/index.d.ts +6 -0
- package/dist/query/index.d.ts.map +1 -0
- package/dist/query/index.js +9 -0
- package/dist/query/index.js.map +1 -0
- package/dist/query/index.mjs +4 -0
- package/dist/query/query-builder.d.ts +323 -0
- package/dist/query/query-builder.d.ts.map +1 -0
- package/dist/query/query-builder.js +524 -0
- package/dist/query/query-builder.js.map +1 -0
- package/dist/query/query-builder.mjs +519 -0
- package/dist/reasoning/context-synthesizer.d.ts +57 -0
- package/dist/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoning/context-synthesizer.js +224 -0
- package/dist/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoning/context-synthesizer.mjs +219 -0
- package/dist/reasoning/experience-curator.d.ts +66 -0
- package/dist/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoning/experience-curator.js +288 -0
- package/dist/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoning/experience-curator.mjs +283 -0
- package/dist/reasoning/memory-optimizer.d.ts +69 -0
- package/dist/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoning/memory-optimizer.js +331 -0
- package/dist/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoning/memory-optimizer.mjs +326 -0
- package/dist/reasoning/pattern-matcher.d.ts +59 -0
- package/dist/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoning/pattern-matcher.js +229 -0
- package/dist/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoning/pattern-matcher.mjs +224 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts +118 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js +477 -0
- package/dist/reasoningbank/adapter/agentdb-adapter.js.map +1 -0
- package/dist/reasoningbank/adapter/types.d.ts +113 -0
- package/dist/reasoningbank/adapter/types.d.ts.map +1 -0
- package/dist/reasoningbank/adapter/types.js +9 -0
- package/dist/reasoningbank/adapter/types.js.map +1 -0
- package/dist/reasoningbank/cli/commands.d.ts +16 -0
- package/dist/reasoningbank/cli/commands.d.ts.map +1 -0
- package/dist/reasoningbank/cli/commands.js +272 -0
- package/dist/reasoningbank/cli/commands.js.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts +319 -0
- package/dist/reasoningbank/mcp/agentdb-tools.d.ts.map +1 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js +301 -0
- package/dist/reasoningbank/mcp/agentdb-tools.js.map +1 -0
- package/dist/reasoningbank/migration/migrate.d.ts +25 -0
- package/dist/reasoningbank/migration/migrate.d.ts.map +1 -0
- package/dist/reasoningbank/migration/migrate.js +178 -0
- package/dist/reasoningbank/migration/migrate.js.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts +37 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js +114 -0
- package/dist/reasoningbank/reasoning/context-synthesizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts +39 -0
- package/dist/reasoningbank/reasoning/experience-curator.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/experience-curator.js +98 -0
- package/dist/reasoningbank/reasoning/experience-curator.js.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts +44 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js +184 -0
- package/dist/reasoningbank/reasoning/memory-optimizer.js.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts +40 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.d.ts.map +1 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js +87 -0
- package/dist/reasoningbank/reasoning/pattern-matcher.js.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts +77 -0
- package/dist/reasoningbank/sync/quic-sync.d.ts.map +1 -0
- package/dist/reasoningbank/sync/quic-sync.js +165 -0
- package/dist/reasoningbank/sync/quic-sync.js.map +1 -0
- package/dist/sync/conflict.d.ts +78 -0
- package/dist/sync/conflict.d.ts.map +1 -0
- package/dist/sync/conflict.js +202 -0
- package/dist/sync/conflict.js.map +1 -0
- package/dist/sync/conflict.mjs +196 -0
- package/dist/sync/coordinator.d.ts +111 -0
- package/dist/sync/coordinator.d.ts.map +1 -0
- package/dist/sync/coordinator.js +256 -0
- package/dist/sync/coordinator.js.map +1 -0
- package/dist/sync/coordinator.mjs +250 -0
- package/dist/sync/delta.d.ts +81 -0
- package/dist/sync/delta.d.ts.map +1 -0
- package/dist/sync/delta.js +245 -0
- package/dist/sync/delta.js.map +1 -0
- package/dist/sync/delta.mjs +238 -0
- package/dist/sync/index.d.ts +11 -0
- package/dist/sync/index.d.ts.map +1 -0
- package/dist/sync/index.js +22 -0
- package/dist/sync/index.js.map +1 -0
- package/dist/sync/index.mjs +9 -0
- package/dist/sync/quic-sync.d.ts +81 -0
- package/dist/sync/quic-sync.d.ts.map +1 -0
- package/dist/sync/quic-sync.js +329 -0
- package/dist/sync/quic-sync.js.map +1 -0
- package/dist/sync/quic-sync.mjs +323 -0
- package/dist/sync/types.d.ts +168 -0
- package/dist/sync/types.d.ts.map +1 -0
- package/dist/sync/types.js +8 -0
- package/dist/sync/types.js.map +1 -0
- package/dist/sync/types.mjs +6 -0
- package/dist/types/index.d.ts +117 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/index.mjs +4 -0
- package/dist/wasm-loader.d.ts +32 -0
- package/dist/wasm-loader.d.ts.map +1 -0
- package/dist/wasm-loader.js +75 -0
- package/dist/wasm-loader.js.map +1 -0
- package/dist/wasm-loader.mjs +64 -0
- package/examples/adaptive-learning.ts +284 -0
- package/examples/browser/README.md +732 -0
- package/examples/browser/adaptive-recommendations/index.html +427 -0
- package/examples/browser/collaborative-filtering/index.html +310 -0
- package/examples/browser/continual-learning/index.html +736 -0
- package/examples/browser/experience-replay/index.html +616 -0
- package/examples/browser/index.html +369 -0
- package/examples/browser/meta-learning/index.html +789 -0
- package/examples/browser/neuro-symbolic/index.html +692 -0
- package/examples/browser/pattern-learning/index.html +620 -0
- package/examples/browser/quantum-inspired/index.html +728 -0
- package/examples/browser/rag/index.html +624 -0
- package/examples/browser/swarm-intelligence/index.html +811 -0
- package/examples/browser-basic.html +170 -0
- package/examples/hnsw-example.ts +148 -0
- package/examples/node-basic.js +70 -0
- package/examples/quic-sync-example.ts +310 -0
- package/examples/quick-start.js +68 -0
- package/examples/wasm-example.ts +222 -0
- package/package.json +118 -0
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Curriculum Learning Plugin
|
|
3
|
+
*
|
|
4
|
+
* Implements structured learning where the model progressively tackles
|
|
5
|
+
* increasingly difficult tasks, mimicking human learning.
|
|
6
|
+
*
|
|
7
|
+
* Key features:
|
|
8
|
+
* - Automatic difficulty estimation
|
|
9
|
+
* - Dynamic curriculum generation
|
|
10
|
+
* - Self-paced learning
|
|
11
|
+
* - Task sequencing based on prerequisites
|
|
12
|
+
* - Competence-based progression
|
|
13
|
+
*/
|
|
14
|
+
import { BasePlugin } from '../base-plugin.mjs';
|
|
15
|
+
/**
|
|
16
|
+
* Curriculum Learning Plugin Implementation
|
|
17
|
+
*/
|
|
18
|
+
export class CurriculumLearningPlugin extends BasePlugin {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
super();
|
|
21
|
+
this.name = 'curriculum-learning';
|
|
22
|
+
this.version = '1.0.0';
|
|
23
|
+
this.experiences = [];
|
|
24
|
+
this.curriculum = [];
|
|
25
|
+
this.currentStage = 0;
|
|
26
|
+
this.taskDifficulties = new Map();
|
|
27
|
+
this.competence = new Map();
|
|
28
|
+
this.strategy = 'automatic';
|
|
29
|
+
// Learning parameters
|
|
30
|
+
this.minSuccessRate = 0.7;
|
|
31
|
+
this.competenceThreshold = 0.8;
|
|
32
|
+
this.difficultyWindow = 0.2;
|
|
33
|
+
if (config) {
|
|
34
|
+
this.strategy = config.strategy || 'automatic';
|
|
35
|
+
this.minSuccessRate = config.minSuccessRate || 0.7;
|
|
36
|
+
this.competenceThreshold = config.competenceThreshold || 0.8;
|
|
37
|
+
}
|
|
38
|
+
this.initializeCurriculum();
|
|
39
|
+
// Mark as initialized for in-memory operation
|
|
40
|
+
this.initialized = true;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Override to skip initialization check for in-memory operation
|
|
44
|
+
*/
|
|
45
|
+
checkInitialized() {
|
|
46
|
+
// No-op for curriculum learning - operates in-memory
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Override selectAction to provide base implementation
|
|
50
|
+
*/
|
|
51
|
+
async selectAction(state, context) {
|
|
52
|
+
// Simple default action selection
|
|
53
|
+
const stateSum = state.reduce((a, b) => a + b, 0);
|
|
54
|
+
const value = Math.tanh(stateSum / state.length);
|
|
55
|
+
return {
|
|
56
|
+
id: String(Math.floor(Math.abs(value) * 10)),
|
|
57
|
+
embedding: state,
|
|
58
|
+
confidence: Math.abs(value),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Override to store experiences in-memory without vectorDB
|
|
63
|
+
*/
|
|
64
|
+
async storeExperience(experience) {
|
|
65
|
+
this.experiences.push(experience);
|
|
66
|
+
const taskId = experience.metadata?.taskId || 'unknown';
|
|
67
|
+
const success = experience.reward > 0;
|
|
68
|
+
// Update competence
|
|
69
|
+
this.updateCompetence(taskId, experience.reward, success);
|
|
70
|
+
// Update task difficulty estimate using local experiences
|
|
71
|
+
const taskExps = this.experiences.filter(e => e.metadata?.taskId === taskId);
|
|
72
|
+
const difficulty = this.estimateTaskDifficulty(taskId, taskExps);
|
|
73
|
+
this.taskDifficulties.set(taskId, difficulty);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Override to retrieve from local experiences
|
|
77
|
+
*/
|
|
78
|
+
async retrieveSimilar(state, k) {
|
|
79
|
+
return this.experiences.slice(0, k).map((exp, idx) => ({
|
|
80
|
+
id: exp.id || `exp-${idx}`,
|
|
81
|
+
embedding: exp.state,
|
|
82
|
+
metadata: exp,
|
|
83
|
+
score: 1.0 - (idx * 0.1),
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Initialize curriculum stages
|
|
88
|
+
*/
|
|
89
|
+
initializeCurriculum() {
|
|
90
|
+
this.curriculum = [
|
|
91
|
+
{
|
|
92
|
+
stage: 0,
|
|
93
|
+
name: 'Foundation',
|
|
94
|
+
minCompetence: 0.0,
|
|
95
|
+
tasks: ['basic_actions', 'simple_rewards'],
|
|
96
|
+
completed: false,
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
stage: 1,
|
|
100
|
+
name: 'Intermediate',
|
|
101
|
+
minCompetence: 0.7,
|
|
102
|
+
tasks: ['sequential_actions', 'delayed_rewards'],
|
|
103
|
+
completed: false,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
stage: 2,
|
|
107
|
+
name: 'Advanced',
|
|
108
|
+
minCompetence: 0.8,
|
|
109
|
+
tasks: ['complex_strategies', 'multi_step_planning'],
|
|
110
|
+
completed: false,
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
stage: 3,
|
|
114
|
+
name: 'Expert',
|
|
115
|
+
minCompetence: 0.9,
|
|
116
|
+
tasks: ['optimal_policies', 'transfer_learning'],
|
|
117
|
+
completed: false,
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Estimate task difficulty from experiences
|
|
123
|
+
*/
|
|
124
|
+
estimateTaskDifficulty(taskId, experiences) {
|
|
125
|
+
if (experiences.length === 0) {
|
|
126
|
+
return {
|
|
127
|
+
taskId,
|
|
128
|
+
complexity: 0.5,
|
|
129
|
+
estimatedLoss: 1.0,
|
|
130
|
+
successRate: 0.0,
|
|
131
|
+
prerequisites: [],
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
// Calculate metrics
|
|
135
|
+
const successes = experiences.filter(e => e.reward > 0).length;
|
|
136
|
+
const successRate = successes / experiences.length;
|
|
137
|
+
const avgReward = experiences.reduce((sum, e) => sum + e.reward, 0) / experiences.length;
|
|
138
|
+
const rewardVariance = experiences.reduce((sum, e) => sum + Math.pow(e.reward - avgReward, 2), 0) / experiences.length;
|
|
139
|
+
// Complexity based on state dimensionality and reward variance
|
|
140
|
+
const stateDim = experiences[0].state.length;
|
|
141
|
+
const complexity = Math.min(1.0, (stateDim / 256 + Math.sqrt(rewardVariance)) / 2);
|
|
142
|
+
return {
|
|
143
|
+
taskId,
|
|
144
|
+
complexity,
|
|
145
|
+
estimatedLoss: 1.0 - successRate,
|
|
146
|
+
successRate,
|
|
147
|
+
prerequisites: this.inferPrerequisites(taskId, complexity),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Infer prerequisite tasks based on complexity
|
|
152
|
+
*/
|
|
153
|
+
inferPrerequisites(taskId, complexity) {
|
|
154
|
+
const prerequisites = [];
|
|
155
|
+
this.taskDifficulties.forEach((difficulty, id) => {
|
|
156
|
+
if (id !== taskId && difficulty.complexity < complexity - 0.2) {
|
|
157
|
+
prerequisites.push(id);
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
return prerequisites.slice(0, 3); // Max 3 prerequisites
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Select next task based on current competence
|
|
164
|
+
*/
|
|
165
|
+
selectNextTask() {
|
|
166
|
+
const currentCompetence = this.getCurrentCompetence();
|
|
167
|
+
// Self-paced: Choose task slightly above current competence
|
|
168
|
+
if (this.strategy === 'self_paced') {
|
|
169
|
+
return this.selectSelfPacedTask(currentCompetence);
|
|
170
|
+
}
|
|
171
|
+
// Automatic: Estimate difficulty and choose optimally
|
|
172
|
+
if (this.strategy === 'automatic') {
|
|
173
|
+
return this.selectAutomaticTask(currentCompetence);
|
|
174
|
+
}
|
|
175
|
+
// Predefined: Follow curriculum stages
|
|
176
|
+
return this.selectCurriculumTask();
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Self-paced task selection
|
|
180
|
+
*/
|
|
181
|
+
selectSelfPacedTask(competence) {
|
|
182
|
+
const targetDifficulty = competence + this.difficultyWindow;
|
|
183
|
+
let bestTask = null;
|
|
184
|
+
let bestDiff = Infinity;
|
|
185
|
+
this.taskDifficulties.forEach((difficulty, taskId) => {
|
|
186
|
+
const diff = Math.abs(difficulty.complexity - targetDifficulty);
|
|
187
|
+
if (diff < bestDiff && this.arePrerequisitesMet(taskId)) {
|
|
188
|
+
bestTask = taskId;
|
|
189
|
+
bestDiff = diff;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
return bestTask;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Automatic task selection using competence-based heuristic
|
|
196
|
+
*/
|
|
197
|
+
selectAutomaticTask(competence) {
|
|
198
|
+
const candidates = [];
|
|
199
|
+
this.taskDifficulties.forEach((difficulty, taskId) => {
|
|
200
|
+
if (!this.arePrerequisitesMet(taskId)) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
// Score combines difficulty match and learning progress potential
|
|
204
|
+
const difficultyMatch = 1.0 - Math.abs(difficulty.complexity - competence);
|
|
205
|
+
const learningPotential = 1.0 - difficulty.successRate;
|
|
206
|
+
const score = difficultyMatch * 0.7 + learningPotential * 0.3;
|
|
207
|
+
candidates.push({ taskId, score });
|
|
208
|
+
});
|
|
209
|
+
if (candidates.length === 0) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
// Select best scoring task
|
|
213
|
+
candidates.sort((a, b) => b.score - a.score);
|
|
214
|
+
return candidates[0].taskId;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Curriculum-based task selection
|
|
218
|
+
*/
|
|
219
|
+
selectCurriculumTask() {
|
|
220
|
+
const stage = this.curriculum[this.currentStage];
|
|
221
|
+
if (!stage || stage.completed) {
|
|
222
|
+
// Move to next stage
|
|
223
|
+
if (this.currentStage < this.curriculum.length - 1) {
|
|
224
|
+
this.currentStage++;
|
|
225
|
+
return this.selectCurriculumTask();
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
// Select random task from current stage
|
|
230
|
+
const uncompletedTasks = stage.tasks.filter(taskId => (this.competence.get(taskId) || 0) < this.competenceThreshold);
|
|
231
|
+
if (uncompletedTasks.length === 0) {
|
|
232
|
+
stage.completed = true;
|
|
233
|
+
return this.selectCurriculumTask();
|
|
234
|
+
}
|
|
235
|
+
return uncompletedTasks[Math.floor(Math.random() * uncompletedTasks.length)];
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Check if task prerequisites are met
|
|
239
|
+
*/
|
|
240
|
+
arePrerequisitesMet(taskId) {
|
|
241
|
+
const difficulty = this.taskDifficulties.get(taskId);
|
|
242
|
+
if (!difficulty) {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
return difficulty.prerequisites.every(prereqId => {
|
|
246
|
+
const competence = this.competence.get(prereqId) || 0;
|
|
247
|
+
return competence >= this.minSuccessRate;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Get current overall competence
|
|
252
|
+
*/
|
|
253
|
+
getCurrentCompetence() {
|
|
254
|
+
if (this.competence.size === 0) {
|
|
255
|
+
return 0.0;
|
|
256
|
+
}
|
|
257
|
+
const sum = Array.from(this.competence.values()).reduce((a, b) => a + b, 0);
|
|
258
|
+
return sum / this.competence.size;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Update competence for a task
|
|
262
|
+
*/
|
|
263
|
+
updateCompetence(taskId, reward, success) {
|
|
264
|
+
const currentCompetence = this.competence.get(taskId) || 0;
|
|
265
|
+
// Exponential moving average
|
|
266
|
+
const alpha = 0.1;
|
|
267
|
+
const newCompetence = success ? 1.0 : 0.0;
|
|
268
|
+
const updated = (1 - alpha) * currentCompetence + alpha * newCompetence;
|
|
269
|
+
this.competence.set(taskId, updated);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Train with curriculum learning
|
|
273
|
+
*/
|
|
274
|
+
async train(options) {
|
|
275
|
+
const startTime = Date.now();
|
|
276
|
+
const epochs = options?.epochs || 50;
|
|
277
|
+
let totalLoss = 0;
|
|
278
|
+
let experiencesProcessed = 0;
|
|
279
|
+
for (let epoch = 0; epoch < epochs; epoch++) {
|
|
280
|
+
// Select next task based on curriculum
|
|
281
|
+
const taskId = this.selectNextTask();
|
|
282
|
+
if (!taskId) {
|
|
283
|
+
// Curriculum completed
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
// Retrieve experiences for this task from local storage
|
|
287
|
+
const allExperiences = await this.retrieveSimilar(new Array(128).fill(0), options?.batchSize || 32);
|
|
288
|
+
const experiences = this.experiences
|
|
289
|
+
.filter(e => e.metadata?.taskId === taskId)
|
|
290
|
+
.slice(0, options?.batchSize || 32);
|
|
291
|
+
// Train on task
|
|
292
|
+
for (const exp of experiences) {
|
|
293
|
+
const prediction = await this.selectAction(exp.state);
|
|
294
|
+
const loss = Math.pow(prediction.confidence - exp.reward, 2);
|
|
295
|
+
totalLoss += loss;
|
|
296
|
+
experiencesProcessed++;
|
|
297
|
+
}
|
|
298
|
+
// Check if we should advance curriculum stage
|
|
299
|
+
if (this.strategy === 'predefined') {
|
|
300
|
+
const currentCompetence = this.getCurrentCompetence();
|
|
301
|
+
const nextStage = this.curriculum[this.currentStage + 1];
|
|
302
|
+
if (nextStage && currentCompetence >= nextStage.minCompetence) {
|
|
303
|
+
this.currentStage++;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
const duration = Math.max(1, Date.now() - startTime);
|
|
308
|
+
return {
|
|
309
|
+
loss: totalLoss / Math.max(1, experiencesProcessed),
|
|
310
|
+
experiencesProcessed,
|
|
311
|
+
duration,
|
|
312
|
+
currentStage: this.currentStage,
|
|
313
|
+
currentCompetence: this.getCurrentCompetence(),
|
|
314
|
+
tasksCompleted: Array.from(this.competence.entries())
|
|
315
|
+
.filter(([, comp]) => comp >= this.competenceThreshold)
|
|
316
|
+
.length,
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Get curriculum progress
|
|
321
|
+
*/
|
|
322
|
+
getCurriculumProgress() {
|
|
323
|
+
const totalTasks = this.curriculum.reduce((sum, stage) => sum + stage.tasks.length, 0);
|
|
324
|
+
const completed = Array.from(this.competence.values())
|
|
325
|
+
.filter(c => c >= this.competenceThreshold).length;
|
|
326
|
+
return {
|
|
327
|
+
currentStage: this.currentStage,
|
|
328
|
+
totalStages: this.curriculum.length,
|
|
329
|
+
competence: this.getCurrentCompetence(),
|
|
330
|
+
tasksCompleted: completed,
|
|
331
|
+
totalTasks,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Add custom curriculum stage
|
|
336
|
+
*/
|
|
337
|
+
addCurriculumStage(stage) {
|
|
338
|
+
this.curriculum.push({
|
|
339
|
+
...stage,
|
|
340
|
+
completed: false,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Get task difficulties
|
|
345
|
+
*/
|
|
346
|
+
getTaskDifficulties() {
|
|
347
|
+
return new Map(this.taskDifficulties);
|
|
348
|
+
}
|
|
349
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decision Transformer Plugin
|
|
3
|
+
*
|
|
4
|
+
* Implements the Decision Transformer algorithm with 3-tier action selection:
|
|
5
|
+
* - Tier 1: Exact retrieval (99% similarity)
|
|
6
|
+
* - Tier 2: k-NN interpolation (95% similarity)
|
|
7
|
+
* - Tier 3: Neural network generation
|
|
8
|
+
*
|
|
9
|
+
* Based on "Decision Transformer: Reinforcement Learning via Sequence Modeling"
|
|
10
|
+
* https://arxiv.org/abs/2106.01345
|
|
11
|
+
*/
|
|
12
|
+
import { BasePlugin } from '../base-plugin';
|
|
13
|
+
import { Action, Context, TrainOptions, TrainingMetrics } from '../learning-plugin.interface';
|
|
14
|
+
/**
|
|
15
|
+
* Decision Transformer Plugin Implementation
|
|
16
|
+
*/
|
|
17
|
+
export declare class DecisionTransformerPlugin extends BasePlugin {
|
|
18
|
+
name: string;
|
|
19
|
+
version: string;
|
|
20
|
+
private decisionLayer;
|
|
21
|
+
private tier1Threshold;
|
|
22
|
+
private tier2Threshold;
|
|
23
|
+
private kNeighbors;
|
|
24
|
+
/**
|
|
25
|
+
* Initialize the Decision Transformer plugin
|
|
26
|
+
*/
|
|
27
|
+
protected onInitialize(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Select action using 3-tier strategy
|
|
30
|
+
*
|
|
31
|
+
* @param state - Current state vector
|
|
32
|
+
* @param context - Optional context including desired return
|
|
33
|
+
* @returns Selected action
|
|
34
|
+
*/
|
|
35
|
+
selectAction(state: number[], context?: Context): Promise<Action>;
|
|
36
|
+
/**
|
|
37
|
+
* Tier 1: Try exact retrieval
|
|
38
|
+
*/
|
|
39
|
+
private tryExactRetrieval;
|
|
40
|
+
/**
|
|
41
|
+
* Tier 2: Try k-NN interpolation
|
|
42
|
+
*/
|
|
43
|
+
private tryKNNInterpolation;
|
|
44
|
+
/**
|
|
45
|
+
* Tier 3: Use neural network generation
|
|
46
|
+
*/
|
|
47
|
+
private useNeuralGeneration;
|
|
48
|
+
/**
|
|
49
|
+
* Train the decision layer on stored experiences
|
|
50
|
+
*/
|
|
51
|
+
train(options?: TrainOptions): Promise<TrainingMetrics>;
|
|
52
|
+
/**
|
|
53
|
+
* Compute return-to-go from experience metadata
|
|
54
|
+
*/
|
|
55
|
+
private computeReturnToGo;
|
|
56
|
+
/**
|
|
57
|
+
* Encode history as average of recent states
|
|
58
|
+
*/
|
|
59
|
+
private encodeHistory;
|
|
60
|
+
/**
|
|
61
|
+
* Get all experiences (helper method)
|
|
62
|
+
*/
|
|
63
|
+
private getAllExperiences;
|
|
64
|
+
/**
|
|
65
|
+
* Group experiences by episode
|
|
66
|
+
*/
|
|
67
|
+
private groupByEpisode;
|
|
68
|
+
/**
|
|
69
|
+
* Save model weights
|
|
70
|
+
*/
|
|
71
|
+
protected onSave(path: string): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Load model weights
|
|
74
|
+
*/
|
|
75
|
+
protected onLoad(path: string): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=decision-transformer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision-transformer.d.ts","sourceRoot":"","sources":["../../../src/plugins/implementations/decision-transformer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,MAAM,EACN,OAAO,EAEP,YAAY,EACZ,eAAe,EAChB,MAAM,8BAA8B,CAAC;AA+OtC;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,UAAU;IAChD,IAAI,SAA0B;IAC9B,OAAO,SAAW;IAEzB,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,UAAU,CAAa;IAE/B;;OAEG;cACa,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAa7C;;;;;;OAMG;IACG,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAgCvE;;OAEG;YACW,iBAAiB;IA2B/B;;OAEG;YACW,mBAAmB;IAqCjC;;OAEG;YACW,mBAAmB;IAsBjC;;OAEG;IACG,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,eAAe,CAAC;IAiD7D;;OAEG;IACH,OAAO,CAAC,iBAAiB;IAIzB;;OAEG;IACH,OAAO,CAAC,aAAa;IAqBrB;;OAEG;YACW,iBAAiB;IAU/B;;OAEG;IACH,OAAO,CAAC,cAAc;IAqBtB;;OAEG;cACa,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMnD;;OAEG;cACa,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAKpD"}
|