agentdb 2.0.0-alpha.1 → 2.0.0-alpha.2
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/dist/agentdb.min.js +4 -4
- package/dist/simulation/cli.js +0 -0
- package/dist/src/cli/lib/config-manager.d.ts.map +1 -1
- package/dist/src/cli/lib/config-manager.js.map +1 -1
- package/dist/src/cli/lib/history-tracker.d.ts.map +1 -1
- package/dist/src/cli/lib/history-tracker.js +7 -1
- package/dist/src/cli/lib/history-tracker.js.map +1 -1
- package/examples/README.md +105 -0
- package/examples/quickstart.js +43 -0
- package/package.json +6 -2
- package/simulation/.claude-flow/metrics/agent-metrics.json +1 -0
- package/simulation/.claude-flow/metrics/performance.json +87 -0
- package/simulation/.claude-flow/metrics/task-metrics.json +10 -0
- package/simulation/COMPLETION-STATUS.md +139 -0
- package/simulation/FINAL-RESULTS.md +414 -0
- package/simulation/FINAL-STATUS.md +281 -0
- package/simulation/INTEGRATION-COMPLETE.md +452 -0
- package/simulation/MIGRATION-STATUS.md +231 -0
- package/simulation/OPTIMIZATION-RESULTS.md +397 -0
- package/simulation/PHASE1-COMPLETE.md +163 -0
- package/simulation/README.md +848 -0
- package/simulation/SIMULATION-RESULTS.md +239 -0
- package/simulation/cli.ts +78 -0
- package/simulation/configs/default.json +37 -0
- package/simulation/data/advanced/aidefence.graph +0 -0
- package/simulation/data/advanced/bmssp.graph +0 -0
- package/simulation/data/advanced/consciousness.graph +0 -0
- package/simulation/data/advanced/goalie.graph +0 -0
- package/simulation/data/advanced/psycho-symbolic.graph +0 -0
- package/simulation/data/advanced/research-swarm.graph +0 -0
- package/simulation/data/advanced/sublinear.graph +0 -0
- package/simulation/data/advanced/temporal.graph +0 -0
- package/simulation/data/causal.graph +0 -0
- package/simulation/data/graph-traversal.graph +0 -0
- package/simulation/data/lean-agentic.graph +0 -0
- package/simulation/data/reflexion.graph +0 -0
- package/simulation/data/skills.graph +0 -0
- package/simulation/data/stock-market.graph +0 -0
- package/simulation/data/strange-loops.graph +0 -0
- package/simulation/data/swarm.graph +0 -0
- package/simulation/data/voting-consensus.graph +0 -0
- package/simulation/docs/CLI-INTEGRATION-PLAN.md +1038 -0
- package/simulation/docs/COMPREHENSIVE-LATENT-SPACE-COMPLETION.md +354 -0
- package/simulation/docs/DOCUMENTATION-INDEX.md +226 -0
- package/simulation/docs/IMPLEMENTATION-COMPLETE.md +521 -0
- package/simulation/docs/OPTIMIZATION-SUMMARY.md +279 -0
- package/simulation/docs/README.md +229 -0
- package/simulation/docs/SWARM-5-INTEGRATION-SUMMARY.md +528 -0
- package/simulation/docs/TESTING-SUMMARY.md +304 -0
- package/simulation/docs/architecture/EXTENSION-API.md +868 -0
- package/simulation/docs/architecture/INTEGRATION-ARCHITECTURE.md +1138 -0
- package/simulation/docs/architecture/OPTIMIZATION-STRATEGY.md +778 -0
- package/simulation/docs/architecture/SIMULATION-ARCHITECTURE.md +892 -0
- package/simulation/docs/guides/CLI-REFERENCE.md +896 -0
- package/simulation/docs/guides/CUSTOM-SIMULATIONS.md +931 -0
- package/simulation/docs/guides/DEPLOYMENT.md +832 -0
- package/simulation/docs/guides/IMPLEMENTATION-SUMMARY.md +544 -0
- package/simulation/docs/guides/MIGRATION-GUIDE.md +591 -0
- package/simulation/docs/guides/QUICK-START.md +361 -0
- package/simulation/docs/guides/README.md +736 -0
- package/simulation/docs/guides/TROUBLESHOOTING.md +817 -0
- package/simulation/docs/guides/WIZARD-GUIDE.md +869 -0
- package/simulation/docs/reports/latent-space/MASTER-SYNTHESIS.md +345 -0
- package/simulation/docs/reports/latent-space/README.md +132 -0
- package/simulation/docs/reports/latent-space/attention-analysis-RESULTS.md +238 -0
- package/simulation/docs/reports/latent-space/clustering-analysis-RESULTS.md +210 -0
- package/simulation/docs/reports/latent-space/hnsw-exploration-RESULTS.md +332 -0
- package/simulation/docs/reports/latent-space/hypergraph-exploration-RESULTS.md +37 -0
- package/simulation/docs/reports/latent-space/neural-augmentation-RESULTS.md +69 -0
- package/simulation/docs/reports/latent-space/quantum-hybrid-RESULTS.md +91 -0
- package/simulation/docs/reports/latent-space/self-organizing-hnsw-RESULTS.md +51 -0
- package/simulation/docs/reports/latent-space/traversal-optimization-RESULTS.md +238 -0
- package/simulation/reports/README.md +397 -0
- package/simulation/reports/advanced-simulations-performance.md +1241 -0
- package/simulation/reports/aidefence-integration-2025-11-30T01-36-53-486Z.json +30 -0
- package/simulation/reports/architecture-analysis.md +1396 -0
- package/simulation/reports/basic-scenarios-performance.md +1840 -0
- package/simulation/reports/bmssp-integration-2025-11-30T01-36-27-193Z.json +30 -0
- package/simulation/reports/bmssp-integration-2025-11-30T03-38-12-887Z.json +30 -0
- package/simulation/reports/causal-reasoning-2025-11-29T23-35-21-795Z.json +36 -0
- package/simulation/reports/causal-reasoning-2025-11-30T00-58-42-862Z.json +30 -0
- package/simulation/reports/causal-reasoning-2025-11-30T00-59-12-546Z.json +40 -0
- package/simulation/reports/consciousness-explorer-2025-11-30T01-36-51-269Z.json +31 -0
- package/simulation/reports/core-benchmarks.md +727 -0
- package/simulation/reports/goalie-integration-2025-11-30T01-36-52-377Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-29T23-35-35-279Z.json +78 -0
- package/simulation/reports/graph-traversal-2025-11-29T23-37-36-697Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-03-59-716Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-05-10-984Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-06-16-334Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-06-53-312Z.json +30 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-07-51-075Z.json +24 -0
- package/simulation/reports/graph-traversal-2025-11-30T01-08-22-179Z.json +42 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-29T23-37-23-804Z.json +148 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-30T01-31-24-401Z.json +31 -0
- package/simulation/reports/lean-agentic-swarm-2025-11-30T03-38-01-470Z.json +31 -0
- package/simulation/reports/multi-agent-swarm-2025-11-29T23-35-28-093Z.json +78 -0
- package/simulation/reports/multi-agent-swarm-2025-11-30T01-03-54-062Z.json +42 -0
- package/simulation/reports/multi-agent-swarm-2025-11-30T01-05-06-092Z.json +42 -0
- package/simulation/reports/psycho-symbolic-reasoner-2025-11-30T01-36-50-180Z.json +30 -0
- package/simulation/reports/quality-metrics.md +727 -0
- package/simulation/reports/reflexion-learning-2025-11-29T23-35-09-774Z.json +48 -0
- package/simulation/reports/reflexion-learning-2025-11-29T23-37-16-934Z.json +36 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-07-49-259Z.json +30 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-09-29-319Z.json +51 -0
- package/simulation/reports/reflexion-learning-2025-11-30T00-28-37-659Z.json +51 -0
- package/simulation/reports/reflexion-learning-2025-11-30T01-31-30-690Z.json +29 -0
- package/simulation/reports/reflexion-learning-2025-11-30T03-38-06-937Z.json +29 -0
- package/simulation/reports/research-foundations.md +2004 -0
- package/simulation/reports/research-swarm-2025-11-30T01-36-54-647Z.json +30 -0
- package/simulation/reports/scalability-deployment.md +2404 -0
- package/simulation/reports/skill-evolution-2025-11-29T23-35-15-945Z.json +36 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-03-17-995Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-03-48-441Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-05-00-554Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-06-11-436Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-06-51-979Z.json +30 -0
- package/simulation/reports/skill-evolution-2025-11-30T01-07-32-695Z.json +40 -0
- package/simulation/reports/stock-market-emergence-2025-11-30T00-11-43-865Z.json +56 -0
- package/simulation/reports/stock-market-emergence-2025-11-30T00-28-57-495Z.json +56 -0
- package/simulation/reports/strange-loops-2025-11-29T23-37-30-621Z.json +78 -0
- package/simulation/reports/strange-loops-2025-11-30T00-07-55-415Z.json +30 -0
- package/simulation/reports/strange-loops-2025-11-30T00-09-35-133Z.json +30 -0
- package/simulation/reports/strange-loops-2025-11-30T00-48-50-744Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-54-48-044Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-57-27-633Z.json +24 -0
- package/simulation/reports/strange-loops-2025-11-30T00-57-59-135Z.json +42 -0
- package/simulation/reports/sublinear-solver-2025-11-30T01-36-33-134Z.json +30 -0
- package/simulation/reports/temporal-lead-solver-2025-11-30T01-36-38-628Z.json +30 -0
- package/simulation/reports/use-cases-applications.md +2212 -0
- package/simulation/reports/voting-system-consensus-2025-11-30T00-11-37-199Z.json +58 -0
- package/simulation/reports/voting-system-consensus-2025-11-30T00-28-47-735Z.json +58 -0
- package/simulation/runner.ts +300 -0
- package/simulation/scenarios/README-advanced/aidefence-integration.md +63 -0
- package/simulation/scenarios/README-advanced/bmssp-integration.md +58 -0
- package/simulation/scenarios/README-advanced/consciousness-explorer.md +53 -0
- package/simulation/scenarios/README-advanced/goalie-integration.md +61 -0
- package/simulation/scenarios/README-advanced/psycho-symbolic-reasoner.md +55 -0
- package/simulation/scenarios/README-advanced/research-swarm.md +63 -0
- package/simulation/scenarios/README-advanced/sublinear-solver.md +58 -0
- package/simulation/scenarios/README-advanced/temporal-lead-solver.md +55 -0
- package/simulation/scenarios/README-basic/causal-reasoning.md +39 -0
- package/simulation/scenarios/README-basic/graph-traversal.md +41 -0
- package/simulation/scenarios/README-basic/lean-agentic-swarm.md +122 -0
- package/simulation/scenarios/README-basic/multi-agent-swarm.md +34 -0
- package/simulation/scenarios/README-basic/reflexion-learning.md +41 -0
- package/simulation/scenarios/README-basic/skill-evolution.md +38 -0
- package/simulation/scenarios/README-basic/stock-market-emergence.md +28 -0
- package/simulation/scenarios/README-basic/strange-loops.md +36 -0
- package/simulation/scenarios/README-basic/voting-system-consensus.md +28 -0
- package/simulation/scenarios/README.md +438 -0
- package/simulation/scenarios/aidefence-integration.ts +165 -0
- package/simulation/scenarios/bmssp-integration.ts +137 -0
- package/simulation/scenarios/causal-reasoning.ts +143 -0
- package/simulation/scenarios/consciousness-explorer.ts +139 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/agent-metrics.json +1 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/performance.json +87 -0
- package/simulation/scenarios/domain-examples/.claude-flow/metrics/task-metrics.json +10 -0
- package/simulation/scenarios/domain-examples/README.md +525 -0
- package/simulation/scenarios/domain-examples/e-commerce-recommendations.ts +220 -0
- package/simulation/scenarios/domain-examples/index.ts +81 -0
- package/simulation/scenarios/domain-examples/iot-sensor-networks.ts +290 -0
- package/simulation/scenarios/domain-examples/medical-imaging.ts +181 -0
- package/simulation/scenarios/domain-examples/robotics-navigation.ts +214 -0
- package/simulation/scenarios/domain-examples/scientific-research.ts +250 -0
- package/simulation/scenarios/domain-examples/trading-systems.ts +138 -0
- package/simulation/scenarios/goalie-integration.ts +161 -0
- package/simulation/scenarios/graph-traversal.ts +129 -0
- package/simulation/scenarios/latent-space/OPTIMIZATION-COMPLETE.md +287 -0
- package/simulation/scenarios/latent-space/README-attention-analysis.md +170 -0
- package/simulation/scenarios/latent-space/README-clustering-analysis.md +239 -0
- package/simulation/scenarios/latent-space/README-hnsw-exploration.md +199 -0
- package/simulation/scenarios/latent-space/README-hypergraph-exploration.md +279 -0
- package/simulation/scenarios/latent-space/README-neural-augmentation.md +267 -0
- package/simulation/scenarios/latent-space/README-quantum-hybrid.md +276 -0
- package/simulation/scenarios/latent-space/README-self-organizing-hnsw.md +244 -0
- package/simulation/scenarios/latent-space/README-traversal-optimization.md +212 -0
- package/simulation/scenarios/latent-space/attention-analysis.ts +598 -0
- package/simulation/scenarios/latent-space/clustering-analysis.ts +796 -0
- package/simulation/scenarios/latent-space/hnsw-exploration.ts +526 -0
- package/simulation/scenarios/latent-space/hypergraph-exploration.ts +706 -0
- package/simulation/scenarios/latent-space/index.ts +47 -0
- package/simulation/scenarios/latent-space/neural-augmentation.ts +604 -0
- package/simulation/scenarios/latent-space/quantum-hybrid.ts +508 -0
- package/simulation/scenarios/latent-space/self-organizing-hnsw.ts +680 -0
- package/simulation/scenarios/latent-space/traversal-optimization.ts +782 -0
- package/simulation/scenarios/lean-agentic-swarm.ts +182 -0
- package/simulation/scenarios/multi-agent-swarm.ts +146 -0
- package/simulation/scenarios/psycho-symbolic-reasoner.ts +136 -0
- package/simulation/scenarios/reflexion-learning.ts +132 -0
- package/simulation/scenarios/research-swarm.ts +187 -0
- package/simulation/scenarios/skill-evolution.ts +135 -0
- package/simulation/scenarios/stock-market-emergence.ts +323 -0
- package/simulation/scenarios/strange-loops.ts +175 -0
- package/simulation/scenarios/sublinear-solver.ts +108 -0
- package/simulation/scenarios/temporal-lead-solver.ts +121 -0
- package/simulation/scenarios/voting-system-consensus.ts +251 -0
- package/simulation/tests/latent-space/attention-analysis.test.ts +204 -0
- package/simulation/tests/latent-space/clustering-analysis.test.ts +281 -0
- package/simulation/tests/latent-space/hnsw-exploration.test.ts +253 -0
- package/simulation/tests/latent-space/hypergraph-exploration.test.ts +295 -0
- package/simulation/tests/latent-space/neural-augmentation.test.ts +326 -0
- package/simulation/tests/latent-space/quantum-hybrid.test.ts +307 -0
- package/simulation/tests/latent-space/self-organizing-hnsw.test.ts +291 -0
- package/simulation/tests/latent-space/traversal-optimization.test.ts +261 -0
- package/simulation/types.ts +177 -0
- package/simulation/utils/PerformanceOptimizer.ts +269 -0
- package/src/cli/lib/history-tracker.ts +7 -1
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Trading Systems: Ultra-Low Latency Vector Search
|
|
3
|
+
*
|
|
4
|
+
* Use Case: High-frequency trading systems need sub-microsecond
|
|
5
|
+
* similarity search for pattern matching and strategy execution.
|
|
6
|
+
*
|
|
7
|
+
* Optimization Priority: LATENCY (quality trade-off acceptable)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { UnifiedMetrics } from '../../types';
|
|
11
|
+
|
|
12
|
+
export const TRADING_ATTENTION_CONFIG = {
|
|
13
|
+
heads: 4, // Fewer heads = faster (vs 8-head optimal)
|
|
14
|
+
forwardPassTargetUs: 500, // Sub-millisecond target (500μs)
|
|
15
|
+
batchSize: 1, // Single-query latency critical
|
|
16
|
+
precision: 'float16' as const, // Reduced precision for speed
|
|
17
|
+
cachingStrategy: 'aggressive' as const, // Pre-compute common patterns
|
|
18
|
+
|
|
19
|
+
// Dynamic-k optimized for market conditions
|
|
20
|
+
dynamicK: {
|
|
21
|
+
min: 3, // Minimum candidates (fast fallback)
|
|
22
|
+
max: 10, // Maximum candidates (volatile markets)
|
|
23
|
+
adaptationStrategy: 'market-volatility' as const
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
// MPC self-healing for 24/7 operation
|
|
27
|
+
selfHealing: {
|
|
28
|
+
enabled: true,
|
|
29
|
+
adaptationIntervalMs: 50, // 50ms response (vs 100ms general)
|
|
30
|
+
degradationThreshold: 0.02 // 2% tolerance (vs 5% general)
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// Trading-specific metrics
|
|
35
|
+
export interface TradingMetrics extends UnifiedMetrics {
|
|
36
|
+
executionLatencyUs: number; // Order execution latency
|
|
37
|
+
marketDataLatencyUs: number; // Market data processing latency
|
|
38
|
+
strategyMatchAccuracy: number; // Pattern match accuracy
|
|
39
|
+
falsePositiveRate: number; // False signal rate (critical for trading)
|
|
40
|
+
uptime99_99: number; // 99.99% uptime requirement
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Trading signal interface
|
|
44
|
+
export interface TradingSignal {
|
|
45
|
+
strategy: string;
|
|
46
|
+
confidence: number;
|
|
47
|
+
executionTimeUs: number;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Example: Pattern matching for trading strategies
|
|
51
|
+
export async function matchTradingPattern(
|
|
52
|
+
marketData: Float32Array,
|
|
53
|
+
strategyDatabase: any, // HNSWGraph type
|
|
54
|
+
getCurrentVolatility: () => number,
|
|
55
|
+
applyAttention: (data: Float32Array, config: any) => Promise<Float32Array>,
|
|
56
|
+
adaptKToVolatility: (volatility: number) => number
|
|
57
|
+
): Promise<TradingSignal[]> {
|
|
58
|
+
const config = TRADING_ATTENTION_CONFIG;
|
|
59
|
+
|
|
60
|
+
// 4-head attention for fast pattern matching
|
|
61
|
+
const enhanced = await applyAttention(marketData, config);
|
|
62
|
+
|
|
63
|
+
// Dynamic-k based on market volatility
|
|
64
|
+
const k = adaptKToVolatility(getCurrentVolatility());
|
|
65
|
+
|
|
66
|
+
// Search for matching strategies
|
|
67
|
+
const matches = await strategyDatabase.search(enhanced, k);
|
|
68
|
+
|
|
69
|
+
return matches.map((m: any) => ({
|
|
70
|
+
strategy: m.id,
|
|
71
|
+
confidence: m.score,
|
|
72
|
+
executionTimeUs: m.latencyUs // Track latency for each match
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Performance targets for trading
|
|
77
|
+
export const TRADING_PERFORMANCE_TARGETS = {
|
|
78
|
+
p50LatencyUs: 500, // 500μs median latency
|
|
79
|
+
p99LatencyUs: 2000, // 2ms p99 latency
|
|
80
|
+
throughputQPS: 100000, // 100K queries/sec
|
|
81
|
+
accuracy: 0.92, // 92% pattern match accuracy (vs 96.8% general)
|
|
82
|
+
uptimePercent: 99.99 // 99.99% uptime (4 nines)
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// Example configuration variations
|
|
86
|
+
export const TRADING_CONFIG_VARIATIONS = {
|
|
87
|
+
// Ultra-low latency (300μs target)
|
|
88
|
+
ultraLowLatency: {
|
|
89
|
+
...TRADING_ATTENTION_CONFIG,
|
|
90
|
+
heads: 2, // Even fewer heads
|
|
91
|
+
forwardPassTargetUs: 300,
|
|
92
|
+
precision: 'int8' as const // Quantized for speed
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
// Balanced (1ms target, better accuracy)
|
|
96
|
+
balanced: {
|
|
97
|
+
...TRADING_ATTENTION_CONFIG,
|
|
98
|
+
heads: 6,
|
|
99
|
+
forwardPassTargetUs: 1000,
|
|
100
|
+
precision: 'float32' as const
|
|
101
|
+
},
|
|
102
|
+
|
|
103
|
+
// High-frequency scalping (extreme speed)
|
|
104
|
+
scalping: {
|
|
105
|
+
...TRADING_ATTENTION_CONFIG,
|
|
106
|
+
heads: 2,
|
|
107
|
+
forwardPassTargetUs: 200,
|
|
108
|
+
batchSize: 1,
|
|
109
|
+
precision: 'int8' as const,
|
|
110
|
+
cachingStrategy: 'precompute' as const
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// Market condition adaptations
|
|
115
|
+
export function adaptConfigToMarket(
|
|
116
|
+
baseConfig: typeof TRADING_ATTENTION_CONFIG,
|
|
117
|
+
marketCondition: 'calm' | 'volatile' | 'trending'
|
|
118
|
+
): typeof TRADING_ATTENTION_CONFIG {
|
|
119
|
+
switch (marketCondition) {
|
|
120
|
+
case 'calm':
|
|
121
|
+
return {
|
|
122
|
+
...baseConfig,
|
|
123
|
+
dynamicK: { ...baseConfig.dynamicK, min: 3, max: 7 }
|
|
124
|
+
};
|
|
125
|
+
case 'volatile':
|
|
126
|
+
return {
|
|
127
|
+
...baseConfig,
|
|
128
|
+
dynamicK: { ...baseConfig.dynamicK, min: 5, max: 15 },
|
|
129
|
+
selfHealing: { ...baseConfig.selfHealing, adaptationIntervalMs: 25 }
|
|
130
|
+
};
|
|
131
|
+
case 'trending':
|
|
132
|
+
return {
|
|
133
|
+
...baseConfig,
|
|
134
|
+
heads: 6, // More heads for pattern recognition
|
|
135
|
+
dynamicK: { ...baseConfig.dynamicK, min: 7, max: 12 }
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Goalie Integration (Goal-Oriented AI Learning Engine)
|
|
3
|
+
*
|
|
4
|
+
* Goal-tracking graph DB with achievement trees
|
|
5
|
+
* Integration with goalie package
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - Hierarchical goal decomposition
|
|
9
|
+
* - Subgoal dependency tracking
|
|
10
|
+
* - Achievement progress monitoring
|
|
11
|
+
* - Adaptive goal prioritization
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { createUnifiedDatabase } from '../../src/db-unified.js';
|
|
15
|
+
import { ReflexionMemory } from '../../src/controllers/ReflexionMemory.js';
|
|
16
|
+
import { CausalMemoryGraph } from '../../src/controllers/CausalMemoryGraph.js';
|
|
17
|
+
import { SkillLibrary } from '../../src/controllers/SkillLibrary.js';
|
|
18
|
+
import { EmbeddingService } from '../../src/controllers/EmbeddingService.js';
|
|
19
|
+
import * as path from 'path';
|
|
20
|
+
|
|
21
|
+
export default {
|
|
22
|
+
description: 'Goalie goal-oriented learning with achievement tree tracking',
|
|
23
|
+
|
|
24
|
+
async run(config: any) {
|
|
25
|
+
const { verbosity = 2 } = config;
|
|
26
|
+
|
|
27
|
+
if (verbosity >= 2) {
|
|
28
|
+
console.log(' 🎯 Initializing Goalie Integration (Goal-Oriented Learning)');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Initialize goal-tracking graph database
|
|
32
|
+
const embedder = new EmbeddingService({
|
|
33
|
+
model: 'Xenova/all-MiniLM-L6-v2',
|
|
34
|
+
dimension: 384,
|
|
35
|
+
provider: 'transformers'
|
|
36
|
+
});
|
|
37
|
+
await embedder.initialize();
|
|
38
|
+
|
|
39
|
+
const db = await createUnifiedDatabase(
|
|
40
|
+
path.join(process.cwd(), 'simulation', 'data', 'advanced', 'goalie.graph'),
|
|
41
|
+
embedder,
|
|
42
|
+
{ forceMode: 'graph' }
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const reflexion = new ReflexionMemory(
|
|
46
|
+
db.getGraphDatabase() as any,
|
|
47
|
+
embedder,
|
|
48
|
+
undefined,
|
|
49
|
+
undefined,
|
|
50
|
+
db.getGraphDatabase() as any
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const causal = new CausalMemoryGraph(
|
|
54
|
+
db.getGraphDatabase() as any,
|
|
55
|
+
db.getGraphDatabase() as any
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const skills = new SkillLibrary(
|
|
59
|
+
db.getGraphDatabase() as any,
|
|
60
|
+
embedder,
|
|
61
|
+
undefined,
|
|
62
|
+
db.getGraphDatabase() as any
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const results = {
|
|
66
|
+
primaryGoals: 0,
|
|
67
|
+
subgoals: 0,
|
|
68
|
+
achievements: 0,
|
|
69
|
+
avgProgress: 0,
|
|
70
|
+
totalTime: 0
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const startTime = performance.now();
|
|
74
|
+
|
|
75
|
+
// Primary Goals
|
|
76
|
+
const primaryGoals = [
|
|
77
|
+
{ goal: 'build_production_system', priority: 0.95 },
|
|
78
|
+
{ goal: 'achieve_90_percent_test_coverage', priority: 0.88 },
|
|
79
|
+
{ goal: 'optimize_performance_10x', priority: 0.92 }
|
|
80
|
+
];
|
|
81
|
+
|
|
82
|
+
const goalIds: number[] = [];
|
|
83
|
+
for (const goal of primaryGoals) {
|
|
84
|
+
const id = await reflexion.storeEpisode({
|
|
85
|
+
sessionId: 'goalie-primary',
|
|
86
|
+
task: goal.goal,
|
|
87
|
+
reward: goal.priority,
|
|
88
|
+
success: false, // Not yet achieved
|
|
89
|
+
input: 'goal_definition',
|
|
90
|
+
output: 'in_progress'
|
|
91
|
+
});
|
|
92
|
+
goalIds.push(id);
|
|
93
|
+
results.primaryGoals++;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Subgoals (decomposition)
|
|
97
|
+
const subgoalHierarchy = [
|
|
98
|
+
{ parent: 0, subgoals: ['setup_ci_cd', 'implement_logging', 'add_monitoring'] },
|
|
99
|
+
{ parent: 1, subgoals: ['write_unit_tests', 'write_integration_tests', 'add_e2e_tests'] },
|
|
100
|
+
{ parent: 2, subgoals: ['profile_bottlenecks', 'optimize_queries', 'add_caching'] }
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
for (const hierarchy of subgoalHierarchy) {
|
|
104
|
+
for (const subgoal of hierarchy.subgoals) {
|
|
105
|
+
const subgoalId = await reflexion.storeEpisode({
|
|
106
|
+
sessionId: 'goalie-subgoal',
|
|
107
|
+
task: subgoal,
|
|
108
|
+
reward: 0.70, // Partial progress
|
|
109
|
+
success: false,
|
|
110
|
+
input: `parent_goal_${hierarchy.parent}`,
|
|
111
|
+
output: 'started'
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Link subgoal to parent goal
|
|
115
|
+
await causal.addCausalEdge({
|
|
116
|
+
fromMemoryId: subgoalId,
|
|
117
|
+
fromMemoryType: 'episode',
|
|
118
|
+
toMemoryId: goalIds[hierarchy.parent],
|
|
119
|
+
toMemoryType: 'episode',
|
|
120
|
+
similarity: 0.90,
|
|
121
|
+
uplift: 0.30, // Completing subgoal improves parent goal
|
|
122
|
+
confidence: 0.95,
|
|
123
|
+
sampleSize: 100,
|
|
124
|
+
mechanism: 'subgoal_contributes_to_parent'
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
results.subgoals++;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// Achievements (completed subgoals)
|
|
132
|
+
const achievements = ['setup_ci_cd', 'write_unit_tests', 'profile_bottlenecks'];
|
|
133
|
+
for (const achievement of achievements) {
|
|
134
|
+
await skills.createSkill({
|
|
135
|
+
name: achievement,
|
|
136
|
+
description: 'Completed subgoal',
|
|
137
|
+
code: `// Achievement unlocked: ${achievement}`,
|
|
138
|
+
successRate: 1.0 // 100% completed
|
|
139
|
+
});
|
|
140
|
+
results.achievements++;
|
|
141
|
+
results.avgProgress += 1.0;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
results.avgProgress /= results.subgoals;
|
|
145
|
+
|
|
146
|
+
const endTime = performance.now();
|
|
147
|
+
results.totalTime = endTime - startTime;
|
|
148
|
+
|
|
149
|
+
db.close();
|
|
150
|
+
|
|
151
|
+
if (verbosity >= 2) {
|
|
152
|
+
console.log(` 📊 Primary Goals: ${results.primaryGoals}`);
|
|
153
|
+
console.log(` 📊 Subgoals: ${results.subgoals}`);
|
|
154
|
+
console.log(` 📊 Achievements: ${results.achievements}`);
|
|
155
|
+
console.log(` 📊 Avg Progress: ${(results.avgProgress * 100).toFixed(1)}%`);
|
|
156
|
+
console.log(` ⏱️ Duration: ${results.totalTime.toFixed(2)}ms`);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return results;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph Traversal Simulation
|
|
3
|
+
*
|
|
4
|
+
* Tests Cypher queries and graph operations
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { createUnifiedDatabase } from '../../src/db-unified.js';
|
|
8
|
+
import { EmbeddingService } from '../../src/controllers/EmbeddingService.js';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
description: 'Graph database traversal and Cypher query performance',
|
|
13
|
+
|
|
14
|
+
async run(config: any) {
|
|
15
|
+
const { verbosity = 2 } = config;
|
|
16
|
+
|
|
17
|
+
if (verbosity >= 2) {
|
|
18
|
+
console.log(' 📊 Initializing Graph Traversal Simulation');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Initialize AgentDB
|
|
22
|
+
const embedder = new EmbeddingService({
|
|
23
|
+
model: 'Xenova/all-MiniLM-L6-v2',
|
|
24
|
+
dimension: 384,
|
|
25
|
+
provider: 'transformers'
|
|
26
|
+
});
|
|
27
|
+
await embedder.initialize();
|
|
28
|
+
|
|
29
|
+
const db = await createUnifiedDatabase(
|
|
30
|
+
path.join(process.cwd(), 'simulation', 'data', 'graph-traversal.graph'),
|
|
31
|
+
embedder,
|
|
32
|
+
{ forceMode: 'graph' }
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
// Get GraphDatabaseAdapter (not raw graph database)
|
|
36
|
+
const graphDb = db.getGraphDatabase()!;
|
|
37
|
+
|
|
38
|
+
// Check if we have GraphDatabaseAdapter methods
|
|
39
|
+
if (!('createNode' in graphDb)) {
|
|
40
|
+
throw new Error('Graph database does not support GraphDatabaseAdapter API. Use RuVector graph mode.');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const results = {
|
|
44
|
+
nodesCreated: 0,
|
|
45
|
+
edgesCreated: 0,
|
|
46
|
+
queriesExecuted: 0,
|
|
47
|
+
avgQueryTime: 0,
|
|
48
|
+
totalTime: 0
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const startTime = performance.now();
|
|
52
|
+
|
|
53
|
+
// Create graph nodes using GraphDatabaseAdapter API
|
|
54
|
+
const nodeIds: string[] = [];
|
|
55
|
+
for (let i = 0; i < 50; i++) {
|
|
56
|
+
const embedding = new Float32Array(384).map(() => Math.random());
|
|
57
|
+
|
|
58
|
+
// Use GraphDatabaseAdapter.createNode API
|
|
59
|
+
const id = await (graphDb as any).createNode({
|
|
60
|
+
id: `test-node-${i}`,
|
|
61
|
+
embedding,
|
|
62
|
+
labels: ['TestNode'],
|
|
63
|
+
properties: {
|
|
64
|
+
nodeIndex: i.toString(), // "index" is a reserved keyword in Cypher
|
|
65
|
+
type: i % 2 === 0 ? 'even' : 'odd'
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
nodeIds.push(id);
|
|
70
|
+
results.nodesCreated++;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Create edges using GraphDatabaseAdapter API
|
|
74
|
+
for (let i = 0; i < 45; i++) {
|
|
75
|
+
const embedding = new Float32Array(384).map(() => Math.random());
|
|
76
|
+
|
|
77
|
+
await (graphDb as any).createEdge({
|
|
78
|
+
from: nodeIds[i],
|
|
79
|
+
to: nodeIds[i + 1],
|
|
80
|
+
description: 'NEXT',
|
|
81
|
+
embedding,
|
|
82
|
+
confidence: 0.9
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
results.edgesCreated++;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Execute Cypher queries
|
|
89
|
+
const queries = [
|
|
90
|
+
'MATCH (n:TestNode) RETURN n LIMIT 10',
|
|
91
|
+
'MATCH (n:TestNode) WHERE n.type = "even" RETURN n LIMIT 10',
|
|
92
|
+
'MATCH (n:TestNode)-[r:NEXT]->(m) RETURN n, r, m LIMIT 10',
|
|
93
|
+
'MATCH (n:TestNode) RETURN count(n)',
|
|
94
|
+
'MATCH (n:TestNode) WHERE n.nodeIndex > "20" RETURN n LIMIT 10' // "index" is a reserved keyword
|
|
95
|
+
];
|
|
96
|
+
|
|
97
|
+
let totalQueryTime = 0;
|
|
98
|
+
for (const query of queries) {
|
|
99
|
+
const queryStart = performance.now();
|
|
100
|
+
const result = await (graphDb as any).query(query);
|
|
101
|
+
const queryEnd = performance.now();
|
|
102
|
+
|
|
103
|
+
totalQueryTime += (queryEnd - queryStart);
|
|
104
|
+
results.queriesExecuted++;
|
|
105
|
+
|
|
106
|
+
if (verbosity >= 3) {
|
|
107
|
+
console.log(` ✅ Query: ${query.substring(0, 50)}... (${(queryEnd - queryStart).toFixed(2)}ms)`);
|
|
108
|
+
console.log(` Results: ${result.nodes?.length || 0} nodes`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
results.avgQueryTime = totalQueryTime / queries.length;
|
|
113
|
+
|
|
114
|
+
const endTime = performance.now();
|
|
115
|
+
results.totalTime = endTime - startTime;
|
|
116
|
+
|
|
117
|
+
db.close();
|
|
118
|
+
|
|
119
|
+
if (verbosity >= 2) {
|
|
120
|
+
console.log(` 📊 Nodes Created: ${results.nodesCreated}`);
|
|
121
|
+
console.log(` 📊 Edges Created: ${results.edgesCreated}`);
|
|
122
|
+
console.log(` 📊 Queries Executed: ${results.queriesExecuted}`);
|
|
123
|
+
console.log(` 📊 Avg Query Time: ${results.avgQueryTime.toFixed(2)}ms`);
|
|
124
|
+
console.log(` ⏱️ Duration: ${results.totalTime.toFixed(2)}ms`);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return results;
|
|
128
|
+
}
|
|
129
|
+
};
|