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,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SARSA Plugin
|
|
3
|
+
*
|
|
4
|
+
* Implements the SARSA (State-Action-Reward-State-Action) algorithm
|
|
5
|
+
* with eligibility traces (SARSA(λ)).
|
|
6
|
+
*
|
|
7
|
+
* SARSA is an on-policy TD control algorithm that learns from the
|
|
8
|
+
* actual actions taken by the current policy, unlike Q-Learning which
|
|
9
|
+
* is off-policy.
|
|
10
|
+
*
|
|
11
|
+
* Key features:
|
|
12
|
+
* - On-policy learning
|
|
13
|
+
* - Eligibility traces for faster learning
|
|
14
|
+
* - Epsilon-greedy exploration
|
|
15
|
+
* - More conservative than Q-Learning
|
|
16
|
+
*/
|
|
17
|
+
import { BasePlugin } from '../base-plugin.mjs';
|
|
18
|
+
/**
|
|
19
|
+
* Eligibility trace for state-action pairs
|
|
20
|
+
*/
|
|
21
|
+
class EligibilityTrace {
|
|
22
|
+
constructor(lambda = 0.9, gamma = 0.99) {
|
|
23
|
+
this.traces = new Map();
|
|
24
|
+
this.lambda = lambda;
|
|
25
|
+
this.gamma = gamma;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Get trace value for state-action pair
|
|
29
|
+
*/
|
|
30
|
+
get(stateKey, actionKey) {
|
|
31
|
+
return this.traces.get(stateKey)?.get(actionKey) || 0;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Update trace for state-action pair
|
|
35
|
+
*/
|
|
36
|
+
update(stateKey, actionKey, value = 1) {
|
|
37
|
+
if (!this.traces.has(stateKey)) {
|
|
38
|
+
this.traces.set(stateKey, new Map());
|
|
39
|
+
}
|
|
40
|
+
this.traces.get(stateKey).set(actionKey, value);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Decay all traces
|
|
44
|
+
*/
|
|
45
|
+
decay() {
|
|
46
|
+
const decayFactor = this.gamma * this.lambda;
|
|
47
|
+
for (const [stateKey, actions] of this.traces.entries()) {
|
|
48
|
+
for (const [actionKey, value] of actions.entries()) {
|
|
49
|
+
const newValue = value * decayFactor;
|
|
50
|
+
if (newValue < 1e-6) {
|
|
51
|
+
actions.delete(actionKey);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
actions.set(actionKey, newValue);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (actions.size === 0) {
|
|
58
|
+
this.traces.delete(stateKey);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Reset all traces
|
|
64
|
+
*/
|
|
65
|
+
reset() {
|
|
66
|
+
this.traces.clear();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get all non-zero traces
|
|
70
|
+
*/
|
|
71
|
+
getAllTraces() {
|
|
72
|
+
const result = [];
|
|
73
|
+
for (const [stateKey, actions] of this.traces.entries()) {
|
|
74
|
+
for (const [actionKey, value] of actions.entries()) {
|
|
75
|
+
result.push({ stateKey, actionKey, value });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* SARSA Plugin Implementation
|
|
83
|
+
*/
|
|
84
|
+
export class SARSAPlugin extends BasePlugin {
|
|
85
|
+
constructor() {
|
|
86
|
+
super(...arguments);
|
|
87
|
+
this.name = 'sarsa';
|
|
88
|
+
this.version = '1.0.0';
|
|
89
|
+
this.qTable = new Map();
|
|
90
|
+
this.epsilon = 1.0;
|
|
91
|
+
this.epsilonMin = 0.01;
|
|
92
|
+
this.epsilonDecay = 0.995;
|
|
93
|
+
this.lambda = 0.9;
|
|
94
|
+
this.lastState = null;
|
|
95
|
+
this.lastAction = null;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Initialize SARSA plugin
|
|
99
|
+
*/
|
|
100
|
+
async onInitialize() {
|
|
101
|
+
// Initialize epsilon
|
|
102
|
+
this.epsilon = this.config.algorithm.epsilonStart || 1.0;
|
|
103
|
+
this.epsilonMin = this.config.algorithm.epsilonEnd || 0.01;
|
|
104
|
+
this.epsilonDecay = this.config.algorithm.epsilonDecay || 0.995;
|
|
105
|
+
// Initialize lambda (eligibility trace decay)
|
|
106
|
+
this.lambda = this.config.algorithm.lambda || 0.9;
|
|
107
|
+
// Initialize eligibility traces
|
|
108
|
+
const gamma = this.config.algorithm.discountFactor || 0.99;
|
|
109
|
+
this.eligibilityTraces = new EligibilityTrace(this.lambda, gamma);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Select action using epsilon-greedy policy
|
|
113
|
+
*
|
|
114
|
+
* @param state - Current state vector
|
|
115
|
+
* @param context - Optional context
|
|
116
|
+
* @returns Selected action
|
|
117
|
+
*/
|
|
118
|
+
async selectAction(state, context) {
|
|
119
|
+
this.checkInitialized();
|
|
120
|
+
// Epsilon-greedy exploration
|
|
121
|
+
if (Math.random() < this.epsilon) {
|
|
122
|
+
return this.randomAction(state);
|
|
123
|
+
}
|
|
124
|
+
// Exploit: Select action with highest Q-value
|
|
125
|
+
return this.greedyAction(state);
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Select random action (exploration)
|
|
129
|
+
*/
|
|
130
|
+
async randomAction(state) {
|
|
131
|
+
// Find similar states to get action space
|
|
132
|
+
const similar = await this.retrieveSimilar(state, 10);
|
|
133
|
+
if (similar.length === 0) {
|
|
134
|
+
// No similar states, return random embedding
|
|
135
|
+
return {
|
|
136
|
+
id: 'random',
|
|
137
|
+
embedding: Array.from({ length: 768 }, () => Math.random() * 2 - 1),
|
|
138
|
+
source: 'policy',
|
|
139
|
+
confidence: 0,
|
|
140
|
+
metadata: { exploration: true },
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
// Random action from similar states
|
|
144
|
+
const randomIdx = Math.floor(Math.random() * similar.length);
|
|
145
|
+
const randomExp = similar[randomIdx];
|
|
146
|
+
if (!randomExp.metadata) {
|
|
147
|
+
// Fallback to random embedding
|
|
148
|
+
return {
|
|
149
|
+
id: 'random',
|
|
150
|
+
embedding: Array.from({ length: 768 }, () => Math.random() * 2 - 1),
|
|
151
|
+
source: 'policy',
|
|
152
|
+
confidence: 0,
|
|
153
|
+
metadata: { exploration: true },
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
id: randomExp.id,
|
|
158
|
+
embedding: randomExp.metadata.action,
|
|
159
|
+
source: 'policy',
|
|
160
|
+
confidence: 0,
|
|
161
|
+
metadata: { exploration: true },
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Select greedy action (exploitation)
|
|
166
|
+
*/
|
|
167
|
+
async greedyAction(state) {
|
|
168
|
+
const stateKey = this.hashState(state);
|
|
169
|
+
// Get Q-values for this state
|
|
170
|
+
const qValues = this.qTable.get(stateKey);
|
|
171
|
+
if (!qValues || qValues.size === 0) {
|
|
172
|
+
// No Q-values yet, explore similar states
|
|
173
|
+
const similar = await this.retrieveSimilar(state, 1);
|
|
174
|
+
if (similar.length > 0 && similar[0].metadata) {
|
|
175
|
+
return {
|
|
176
|
+
id: similar[0].id,
|
|
177
|
+
embedding: similar[0].metadata.action,
|
|
178
|
+
source: 'policy',
|
|
179
|
+
confidence: similar[0].score,
|
|
180
|
+
metadata: { exploration: false },
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
// Fallback to random
|
|
184
|
+
return this.randomAction(state);
|
|
185
|
+
}
|
|
186
|
+
// Find action with maximum Q-value
|
|
187
|
+
let maxQ = -Infinity;
|
|
188
|
+
let bestAction = '';
|
|
189
|
+
for (const [action, qValue] of qValues.entries()) {
|
|
190
|
+
if (qValue > maxQ) {
|
|
191
|
+
maxQ = qValue;
|
|
192
|
+
bestAction = action;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// Retrieve action embedding from storage
|
|
196
|
+
const actionData = await this.getActionEmbedding(bestAction);
|
|
197
|
+
return {
|
|
198
|
+
id: bestAction,
|
|
199
|
+
embedding: actionData,
|
|
200
|
+
source: 'policy',
|
|
201
|
+
confidence: this.normalizeQValue(maxQ),
|
|
202
|
+
metadata: { exploration: false, qValue: maxQ },
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Store experience and perform SARSA update
|
|
207
|
+
*
|
|
208
|
+
* SARSA uses the actual next action taken, not the max Q-value
|
|
209
|
+
*/
|
|
210
|
+
async onStoreExperience(experience) {
|
|
211
|
+
// SARSA requires knowing the next action (on-policy)
|
|
212
|
+
if (this.lastState !== null && this.lastAction !== null) {
|
|
213
|
+
await this.sarsaUpdate(this.lastState, this.lastAction, experience.reward, experience.state, experience.action, experience.done);
|
|
214
|
+
}
|
|
215
|
+
// Store current state and action for next update
|
|
216
|
+
this.lastState = experience.state;
|
|
217
|
+
this.lastAction = experience.action;
|
|
218
|
+
// Reset on episode end
|
|
219
|
+
if (experience.done) {
|
|
220
|
+
this.lastState = null;
|
|
221
|
+
this.lastAction = null;
|
|
222
|
+
this.eligibilityTraces.reset();
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Perform SARSA(λ) update with eligibility traces
|
|
227
|
+
*/
|
|
228
|
+
async sarsaUpdate(state, action, reward, nextState, nextAction, done) {
|
|
229
|
+
const learningRate = this.config.algorithm.learningRate || 0.001;
|
|
230
|
+
const gamma = this.config.algorithm.discountFactor || 0.99;
|
|
231
|
+
const stateKey = this.hashState(state);
|
|
232
|
+
const actionKey = this.hashAction(action);
|
|
233
|
+
const nextStateKey = this.hashState(nextState);
|
|
234
|
+
const nextActionKey = this.hashAction(nextAction);
|
|
235
|
+
// Get current Q-values
|
|
236
|
+
const currentQ = this.getQValue(stateKey, actionKey);
|
|
237
|
+
const nextQ = done ? 0 : this.getQValue(nextStateKey, nextActionKey);
|
|
238
|
+
// Compute TD error
|
|
239
|
+
const tdError = reward + gamma * nextQ - currentQ;
|
|
240
|
+
// Update eligibility trace for current state-action
|
|
241
|
+
this.eligibilityTraces.update(stateKey, actionKey, 1);
|
|
242
|
+
// Update all Q-values proportional to their eligibility traces
|
|
243
|
+
const traces = this.eligibilityTraces.getAllTraces();
|
|
244
|
+
for (const { stateKey: sKey, actionKey: aKey, value: trace } of traces) {
|
|
245
|
+
const oldQ = this.getQValue(sKey, aKey);
|
|
246
|
+
const newQ = oldQ + learningRate * tdError * trace;
|
|
247
|
+
this.setQValue(sKey, aKey, newQ);
|
|
248
|
+
}
|
|
249
|
+
// Decay eligibility traces
|
|
250
|
+
this.eligibilityTraces.decay();
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Train SARSA on stored experiences
|
|
254
|
+
*
|
|
255
|
+
* For online learning, this is called after each experience.
|
|
256
|
+
* For offline learning, this processes batches of episodes.
|
|
257
|
+
*/
|
|
258
|
+
async train(options) {
|
|
259
|
+
this.checkInitialized();
|
|
260
|
+
// SARSA is typically online, so training happens during experience storage
|
|
261
|
+
// However, we can still compute metrics here
|
|
262
|
+
let avgQValue = 0;
|
|
263
|
+
let qCount = 0;
|
|
264
|
+
for (const [_, actions] of this.qTable.entries()) {
|
|
265
|
+
for (const qValue of actions.values()) {
|
|
266
|
+
avgQValue += qValue;
|
|
267
|
+
qCount++;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
avgQValue = qCount > 0 ? avgQValue / qCount : 0;
|
|
271
|
+
// Decay epsilon
|
|
272
|
+
this.epsilon = Math.max(this.epsilonMin, this.epsilon * this.epsilonDecay);
|
|
273
|
+
return {
|
|
274
|
+
loss: 0, // Not computed in online SARSA
|
|
275
|
+
avgQValue,
|
|
276
|
+
epsilon: this.epsilon,
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Get Q-value for state-action pair
|
|
281
|
+
*/
|
|
282
|
+
getQValue(stateKey, actionKey) {
|
|
283
|
+
const qValues = this.qTable.get(stateKey);
|
|
284
|
+
return qValues?.get(actionKey) || 0;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Set Q-value for state-action pair
|
|
288
|
+
*/
|
|
289
|
+
setQValue(stateKey, actionKey, value) {
|
|
290
|
+
if (!this.qTable.has(stateKey)) {
|
|
291
|
+
this.qTable.set(stateKey, new Map());
|
|
292
|
+
}
|
|
293
|
+
this.qTable.get(stateKey).set(actionKey, value);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Hash state vector to string key
|
|
297
|
+
*/
|
|
298
|
+
hashState(state) {
|
|
299
|
+
// Simple hash - in production, use better hashing or clustering
|
|
300
|
+
return state.slice(0, 10).map((x) => x.toFixed(2)).join(',');
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Hash action to string key
|
|
304
|
+
*/
|
|
305
|
+
hashAction(action) {
|
|
306
|
+
if (typeof action === 'string') {
|
|
307
|
+
return action;
|
|
308
|
+
}
|
|
309
|
+
if (Array.isArray(action)) {
|
|
310
|
+
return action.slice(0, 10).map((x) => x.toFixed(2)).join(',');
|
|
311
|
+
}
|
|
312
|
+
return String(action);
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get action embedding from ID
|
|
316
|
+
*/
|
|
317
|
+
async getActionEmbedding(actionId) {
|
|
318
|
+
// In production, retrieve from database
|
|
319
|
+
// For now, return random embedding
|
|
320
|
+
return Array.from({ length: 768 }, () => Math.random() * 2 - 1);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Normalize Q-value to 0-1 confidence
|
|
324
|
+
*/
|
|
325
|
+
normalizeQValue(qValue) {
|
|
326
|
+
return 1 / (1 + Math.exp(-qValue)); // Sigmoid
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Save Q-table and eligibility traces
|
|
330
|
+
*/
|
|
331
|
+
async onSave(path) {
|
|
332
|
+
console.log(`Saving SARSA model to ${path}`);
|
|
333
|
+
// In production, serialize Q-table and traces to file
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Load Q-table and eligibility traces
|
|
337
|
+
*/
|
|
338
|
+
async onLoad(path) {
|
|
339
|
+
console.log(`Loading SARSA model from ${path}`);
|
|
340
|
+
// In production, deserialize Q-table and traces from file
|
|
341
|
+
}
|
|
342
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SQLite Vector Learning Plugins
|
|
3
|
+
*
|
|
4
|
+
* Extensible plugin system for custom learning methodologies using vector databases.
|
|
5
|
+
*
|
|
6
|
+
* This module provides:
|
|
7
|
+
* - Plugin interface definitions
|
|
8
|
+
* - Plugin registry for discovery and management
|
|
9
|
+
* - Base plugin implementation
|
|
10
|
+
* - Configuration validation
|
|
11
|
+
*
|
|
12
|
+
* @module plugins
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import {
|
|
18
|
+
* getRegistry,
|
|
19
|
+
* registerPlugin,
|
|
20
|
+
* loadPlugin,
|
|
21
|
+
* BasePlugin,
|
|
22
|
+
* type LearningPlugin,
|
|
23
|
+
* type PluginConfig
|
|
24
|
+
* } from '@agentdb/plugins';
|
|
25
|
+
*
|
|
26
|
+
* // Register a plugin
|
|
27
|
+
* registerPlugin({
|
|
28
|
+
* name: 'my-q-learning',
|
|
29
|
+
* version: '1.0.0',
|
|
30
|
+
* description: 'Custom Q-Learning implementation',
|
|
31
|
+
* baseAlgorithm: 'q_learning',
|
|
32
|
+
* factory: (config) => new MyQLearningPlugin(config)
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* // Load and use plugin
|
|
36
|
+
* const plugin = await loadPlugin('my-q-learning', {
|
|
37
|
+
* config: {
|
|
38
|
+
* training: { batchSize: 64 }
|
|
39
|
+
* },
|
|
40
|
+
* initialize: true
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Use plugin for learning
|
|
44
|
+
* const action = await plugin.selectAction(stateVector);
|
|
45
|
+
* await plugin.storeExperience({
|
|
46
|
+
* state: stateVector,
|
|
47
|
+
* action,
|
|
48
|
+
* reward: 1.0,
|
|
49
|
+
* nextState: nextStateVector,
|
|
50
|
+
* done: false
|
|
51
|
+
* });
|
|
52
|
+
* await plugin.train();
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export { type LearningPlugin, type PluginConfig, type AlgorithmConfig, type StateConfig, type ActionConfig, type RewardConfig, type ExperienceReplayConfig, type StorageConfig, type TrainingConfig, type MonitoringConfig, type ExtensionConfig, type Vector, type Experience, type Action, type Context, type Outcome, type TrainOptions, type TrainingCallback, type TrainingMetrics, type PluginMetrics, type PluginFactory, type PluginMetadata } from './interface';
|
|
56
|
+
export { PluginRegistry, getRegistry, registerPlugin, loadPlugin, type PluginLoadOptions, type PluginSearchCriteria, PluginError } from './registry';
|
|
57
|
+
export { BasePlugin } from './base-plugin';
|
|
58
|
+
export { validatePluginConfig, validateRequired, getErrorSummary, type ValidationResult, type ValidationError } from './validator';
|
|
59
|
+
/**
|
|
60
|
+
* Plugin system version
|
|
61
|
+
*/
|
|
62
|
+
export declare const PLUGIN_SYSTEM_VERSION = "1.0.0";
|
|
63
|
+
/**
|
|
64
|
+
* Supported plugin API version
|
|
65
|
+
*/
|
|
66
|
+
export declare const PLUGIN_API_VERSION = "1.0.0";
|
|
67
|
+
/**
|
|
68
|
+
* Create a plugin configuration with defaults
|
|
69
|
+
*
|
|
70
|
+
* @param overrides - Configuration overrides
|
|
71
|
+
* @returns Plugin configuration with defaults
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const config = createDefaultConfig({
|
|
76
|
+
* name: 'my-plugin',
|
|
77
|
+
* version: '1.0.0',
|
|
78
|
+
* description: 'My custom plugin',
|
|
79
|
+
* baseAlgorithm: 'q_learning'
|
|
80
|
+
* });
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
import type { PluginConfig as IPluginConfig } from './interface';
|
|
84
|
+
export declare function createDefaultConfig(overrides: Partial<IPluginConfig>): IPluginConfig;
|
|
85
|
+
/**
|
|
86
|
+
* Check if plugin system is initialized
|
|
87
|
+
*
|
|
88
|
+
* @returns Whether registry has plugins
|
|
89
|
+
*/
|
|
90
|
+
export declare function isInitialized(): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Get plugin system information
|
|
93
|
+
*
|
|
94
|
+
* @returns System information
|
|
95
|
+
*/
|
|
96
|
+
export declare function getSystemInfo(): {
|
|
97
|
+
systemVersion: string;
|
|
98
|
+
apiVersion: string;
|
|
99
|
+
totalPlugins: number;
|
|
100
|
+
activePlugins: number;
|
|
101
|
+
availablePlugins: {
|
|
102
|
+
name: any;
|
|
103
|
+
version: any;
|
|
104
|
+
baseAlgorithm: any;
|
|
105
|
+
}[];
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AAIH,OAAO,EAEL,KAAK,cAAc,EAGnB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC3B,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EAGpB,KAAK,MAAM,EACX,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,OAAO,EACZ,KAAK,OAAO,EAGZ,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,aAAa,EAGlB,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AAIrB,OAAO,EAEL,cAAc,EAGd,WAAW,EACX,cAAc,EACd,UAAU,EAGV,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EAGzB,WAAW,EACZ,MAAM,YAAY,CAAC;AAIpB,OAAO,EAEL,UAAU,EACX,MAAM,eAAe,CAAC;AAIvB,OAAO,EAEL,oBAAoB,EACpB,gBAAgB,EAChB,eAAe,EAGf,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,aAAa,CAAC;AAIrB;;GAEG;AACH,eAAO,MAAM,qBAAqB,UAAU,CAAC;AAE7C;;GAEG;AACH,eAAO,MAAM,kBAAkB,UAAU,CAAC;AAI1C;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,EAAE,YAAY,IAAI,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjE,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CAkEpF;AAID;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAGvC;AAED;;;;GAIG;AACH,wBAAgB,aAAa;;;;;;;;;;EAgB5B"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SQLite Vector Learning Plugins
|
|
4
|
+
*
|
|
5
|
+
* Extensible plugin system for custom learning methodologies using vector databases.
|
|
6
|
+
*
|
|
7
|
+
* This module provides:
|
|
8
|
+
* - Plugin interface definitions
|
|
9
|
+
* - Plugin registry for discovery and management
|
|
10
|
+
* - Base plugin implementation
|
|
11
|
+
* - Configuration validation
|
|
12
|
+
*
|
|
13
|
+
* @module plugins
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import {
|
|
19
|
+
* getRegistry,
|
|
20
|
+
* registerPlugin,
|
|
21
|
+
* loadPlugin,
|
|
22
|
+
* BasePlugin,
|
|
23
|
+
* type LearningPlugin,
|
|
24
|
+
* type PluginConfig
|
|
25
|
+
* } from '@agentdb/plugins';
|
|
26
|
+
*
|
|
27
|
+
* // Register a plugin
|
|
28
|
+
* registerPlugin({
|
|
29
|
+
* name: 'my-q-learning',
|
|
30
|
+
* version: '1.0.0',
|
|
31
|
+
* description: 'Custom Q-Learning implementation',
|
|
32
|
+
* baseAlgorithm: 'q_learning',
|
|
33
|
+
* factory: (config) => new MyQLearningPlugin(config)
|
|
34
|
+
* });
|
|
35
|
+
*
|
|
36
|
+
* // Load and use plugin
|
|
37
|
+
* const plugin = await loadPlugin('my-q-learning', {
|
|
38
|
+
* config: {
|
|
39
|
+
* training: { batchSize: 64 }
|
|
40
|
+
* },
|
|
41
|
+
* initialize: true
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Use plugin for learning
|
|
45
|
+
* const action = await plugin.selectAction(stateVector);
|
|
46
|
+
* await plugin.storeExperience({
|
|
47
|
+
* state: stateVector,
|
|
48
|
+
* action,
|
|
49
|
+
* reward: 1.0,
|
|
50
|
+
* nextState: nextStateVector,
|
|
51
|
+
* done: false
|
|
52
|
+
* });
|
|
53
|
+
* await plugin.train();
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.PLUGIN_API_VERSION = exports.PLUGIN_SYSTEM_VERSION = exports.getErrorSummary = exports.validateRequired = exports.validatePluginConfig = exports.BasePlugin = exports.PluginError = exports.loadPlugin = exports.registerPlugin = exports.getRegistry = exports.PluginRegistry = void 0;
|
|
58
|
+
exports.createDefaultConfig = createDefaultConfig;
|
|
59
|
+
exports.isInitialized = isInitialized;
|
|
60
|
+
exports.getSystemInfo = getSystemInfo;
|
|
61
|
+
// ============ Plugin Registry ============
|
|
62
|
+
var registry_1 = require("./registry");
|
|
63
|
+
// Registry class
|
|
64
|
+
Object.defineProperty(exports, "PluginRegistry", { enumerable: true, get: function () { return registry_1.PluginRegistry; } });
|
|
65
|
+
// Registry functions
|
|
66
|
+
Object.defineProperty(exports, "getRegistry", { enumerable: true, get: function () { return registry_1.getRegistry; } });
|
|
67
|
+
Object.defineProperty(exports, "registerPlugin", { enumerable: true, get: function () { return registry_1.registerPlugin; } });
|
|
68
|
+
Object.defineProperty(exports, "loadPlugin", { enumerable: true, get: function () { return registry_1.loadPlugin; } });
|
|
69
|
+
// Errors
|
|
70
|
+
Object.defineProperty(exports, "PluginError", { enumerable: true, get: function () { return registry_1.PluginError; } });
|
|
71
|
+
// ============ Base Plugin ============
|
|
72
|
+
var base_plugin_1 = require("./base-plugin");
|
|
73
|
+
// Base plugin class
|
|
74
|
+
Object.defineProperty(exports, "BasePlugin", { enumerable: true, get: function () { return base_plugin_1.BasePlugin; } });
|
|
75
|
+
// ============ Validation ============
|
|
76
|
+
var validator_1 = require("./validator");
|
|
77
|
+
// Validation functions
|
|
78
|
+
Object.defineProperty(exports, "validatePluginConfig", { enumerable: true, get: function () { return validator_1.validatePluginConfig; } });
|
|
79
|
+
Object.defineProperty(exports, "validateRequired", { enumerable: true, get: function () { return validator_1.validateRequired; } });
|
|
80
|
+
Object.defineProperty(exports, "getErrorSummary", { enumerable: true, get: function () { return validator_1.getErrorSummary; } });
|
|
81
|
+
// ============ Version Information ============
|
|
82
|
+
/**
|
|
83
|
+
* Plugin system version
|
|
84
|
+
*/
|
|
85
|
+
exports.PLUGIN_SYSTEM_VERSION = '1.0.0';
|
|
86
|
+
/**
|
|
87
|
+
* Supported plugin API version
|
|
88
|
+
*/
|
|
89
|
+
exports.PLUGIN_API_VERSION = '1.0.0';
|
|
90
|
+
function createDefaultConfig(overrides) {
|
|
91
|
+
return {
|
|
92
|
+
name: overrides.name || 'unnamed-plugin',
|
|
93
|
+
version: overrides.version || '1.0.0',
|
|
94
|
+
description: overrides.description || 'A learning plugin',
|
|
95
|
+
baseAlgorithm: overrides.baseAlgorithm || 'custom',
|
|
96
|
+
algorithm: {
|
|
97
|
+
type: 'custom',
|
|
98
|
+
learningRate: 0.001,
|
|
99
|
+
discountFactor: 0.99,
|
|
100
|
+
...overrides.algorithm
|
|
101
|
+
},
|
|
102
|
+
state: {
|
|
103
|
+
dimension: 768,
|
|
104
|
+
preprocessing: ['normalize'],
|
|
105
|
+
...overrides.state
|
|
106
|
+
},
|
|
107
|
+
action: {
|
|
108
|
+
type: 'discrete',
|
|
109
|
+
spaceSize: 100,
|
|
110
|
+
selectionStrategy: 'epsilon_greedy',
|
|
111
|
+
...overrides.action
|
|
112
|
+
},
|
|
113
|
+
reward: {
|
|
114
|
+
type: 'success_based',
|
|
115
|
+
...overrides.reward
|
|
116
|
+
},
|
|
117
|
+
experienceReplay: overrides.experienceReplay || {
|
|
118
|
+
type: 'uniform',
|
|
119
|
+
capacity: 10000
|
|
120
|
+
},
|
|
121
|
+
storage: {
|
|
122
|
+
backend: 'agentdb',
|
|
123
|
+
path: './.rl/plugin.db',
|
|
124
|
+
hnsw: {
|
|
125
|
+
enabled: true,
|
|
126
|
+
M: 16,
|
|
127
|
+
efConstruction: 200
|
|
128
|
+
},
|
|
129
|
+
...overrides.storage
|
|
130
|
+
},
|
|
131
|
+
training: {
|
|
132
|
+
batchSize: 32,
|
|
133
|
+
epochs: 10,
|
|
134
|
+
minExperiences: 100,
|
|
135
|
+
trainEvery: 100,
|
|
136
|
+
...overrides.training
|
|
137
|
+
},
|
|
138
|
+
monitoring: {
|
|
139
|
+
trackMetrics: ['success_rate', 'avg_reward', 'loss'],
|
|
140
|
+
logInterval: 10,
|
|
141
|
+
saveCheckpoints: true,
|
|
142
|
+
checkpointInterval: 50,
|
|
143
|
+
...overrides.monitoring
|
|
144
|
+
},
|
|
145
|
+
extensions: overrides.extensions || []
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const registry_2 = require("./registry");
|
|
149
|
+
/**
|
|
150
|
+
* Check if plugin system is initialized
|
|
151
|
+
*
|
|
152
|
+
* @returns Whether registry has plugins
|
|
153
|
+
*/
|
|
154
|
+
function isInitialized() {
|
|
155
|
+
const registry = (0, registry_2.getRegistry)();
|
|
156
|
+
return registry.list().length > 0;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get plugin system information
|
|
160
|
+
*
|
|
161
|
+
* @returns System information
|
|
162
|
+
*/
|
|
163
|
+
function getSystemInfo() {
|
|
164
|
+
const registry = (0, registry_2.getRegistry)();
|
|
165
|
+
const plugins = registry.list();
|
|
166
|
+
const activePlugins = registry.listActive();
|
|
167
|
+
return {
|
|
168
|
+
systemVersion: exports.PLUGIN_SYSTEM_VERSION,
|
|
169
|
+
apiVersion: exports.PLUGIN_API_VERSION,
|
|
170
|
+
totalPlugins: plugins.length,
|
|
171
|
+
activePlugins: activePlugins.length,
|
|
172
|
+
availablePlugins: plugins.map((p) => ({
|
|
173
|
+
name: p.name,
|
|
174
|
+
version: p.version,
|
|
175
|
+
baseAlgorithm: p.baseAlgorithm
|
|
176
|
+
}))
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/plugins/index.ts"],"names":[],"mappings":"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"}
|