@agentic-robotics/mcp 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/benchmark.d.ts +97 -0
- package/dist/benchmark.d.ts.map +1 -0
- package/dist/benchmark.js +330 -0
- package/dist/benchmark.js.map +1 -0
- package/dist/cli.d.ts +6 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +79 -0
- package/dist/cli.js.map +1 -0
- package/dist/enhanced-memory.d.ts +118 -0
- package/dist/enhanced-memory.d.ts.map +1 -0
- package/dist/enhanced-memory.js +296 -0
- package/dist/enhanced-memory.js.map +1 -0
- package/dist/enhanced-server.d.ts +122 -0
- package/dist/enhanced-server.d.ts.map +1 -0
- package/dist/enhanced-server.js +361 -0
- package/dist/enhanced-server.js.map +1 -0
- package/dist/flow-orchestrator.d.ts +75 -0
- package/dist/flow-orchestrator.d.ts.map +1 -0
- package/dist/flow-orchestrator.js +350 -0
- package/dist/flow-orchestrator.js.map +1 -0
- package/dist/hybrid-benchmark.d.ts +44 -0
- package/dist/hybrid-benchmark.d.ts.map +1 -0
- package/dist/hybrid-benchmark.js +232 -0
- package/dist/hybrid-benchmark.js.map +1 -0
- package/dist/hybrid-memory.d.ts +81 -0
- package/dist/hybrid-memory.d.ts.map +1 -0
- package/dist/hybrid-memory.js +296 -0
- package/dist/hybrid-memory.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/{src/index.ts → dist/index.js} +1 -1
- package/dist/index.js.map +1 -0
- package/dist/interface.d.ts +38 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/interface.js +75 -0
- package/dist/interface.js.map +1 -0
- package/dist/memory.d.ts +52 -0
- package/dist/memory.d.ts.map +1 -0
- package/dist/memory.js +230 -0
- package/dist/memory.js.map +1 -0
- package/dist/server.d.ts +55 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +147 -0
- package/dist/server.js.map +1 -0
- package/package.json +3 -2
- package/src/benchmark.ts +0 -434
- package/src/cli.ts +0 -89
- package/src/enhanced-memory.ts +0 -437
- package/src/enhanced-server.ts +0 -523
- package/src/flow-orchestrator.ts +0 -415
- package/src/hybrid-benchmark.ts +0 -291
- package/src/hybrid-memory.ts +0 -401
- package/src/interface.ts +0 -118
- package/src/memory.ts +0 -196
- package/src/optimized-benchmark.ts +0 -302
- package/src/optimized-memory.ts +0 -271
- package/src/server.ts +0 -213
- package/tsconfig.json +0 -20
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Optimized Benchmark Suite
|
|
3
|
-
*
|
|
4
|
-
* Uses JavaScript APIs directly for accurate performance measurement
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { OptimizedAgentDBMemory } from './optimized-memory.js';
|
|
8
|
-
import type { Episode } from './memory.js';
|
|
9
|
-
|
|
10
|
-
interface BenchmarkResult {
|
|
11
|
-
name: string;
|
|
12
|
-
iterations: number;
|
|
13
|
-
totalTime: number;
|
|
14
|
-
avgTime: number;
|
|
15
|
-
minTime: number;
|
|
16
|
-
maxTime: number;
|
|
17
|
-
opsPerSec: number;
|
|
18
|
-
p50: number;
|
|
19
|
-
p95: number;
|
|
20
|
-
p99: number;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface BenchmarkSuite {
|
|
24
|
-
agentdb: {
|
|
25
|
-
storeEpisode: BenchmarkResult;
|
|
26
|
-
retrieveMemories: BenchmarkResult;
|
|
27
|
-
queryWithContext: BenchmarkResult;
|
|
28
|
-
consolidateSkills: BenchmarkResult;
|
|
29
|
-
searchSkills: BenchmarkResult;
|
|
30
|
-
};
|
|
31
|
-
overall: {
|
|
32
|
-
totalTime: number;
|
|
33
|
-
timestamp: string;
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export class OptimizedBenchmark {
|
|
38
|
-
private memory: OptimizedAgentDBMemory;
|
|
39
|
-
|
|
40
|
-
constructor() {
|
|
41
|
-
this.memory = new OptimizedAgentDBMemory('./optimized-benchmark.db');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async initialize(): Promise<void> {
|
|
45
|
-
console.log('🏁 Initializing optimized benchmark suite...\n');
|
|
46
|
-
await this.memory.initialize();
|
|
47
|
-
console.log('✅ Benchmark suite ready\n');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Run complete benchmark suite
|
|
52
|
-
*/
|
|
53
|
-
async runAll(): Promise<BenchmarkSuite> {
|
|
54
|
-
const suiteStartTime = Date.now();
|
|
55
|
-
|
|
56
|
-
console.log('┌─────────────────────────────────────────────────────────┐');
|
|
57
|
-
console.log('│ Optimized Integration Benchmark Suite │');
|
|
58
|
-
console.log('│ AgentDB JavaScript API Performance Test │');
|
|
59
|
-
console.log('└─────────────────────────────────────────────────────────┘\n');
|
|
60
|
-
|
|
61
|
-
// AgentDB Benchmarks with JS API
|
|
62
|
-
console.log('📊 AGENTDB BENCHMARKS (JS API)\n');
|
|
63
|
-
|
|
64
|
-
const storeEpisode = await this.benchmarkStoreEpisode(1000);
|
|
65
|
-
this.printResult('Store Episode', storeEpisode);
|
|
66
|
-
|
|
67
|
-
const retrieveMemories = await this.benchmarkRetrieveMemories(500);
|
|
68
|
-
this.printResult('Retrieve Memories', retrieveMemories);
|
|
69
|
-
|
|
70
|
-
const queryWithContext = await this.benchmarkQueryWithContext(300);
|
|
71
|
-
this.printResult('Query with Context', queryWithContext);
|
|
72
|
-
|
|
73
|
-
const consolidateSkills = await this.benchmarkConsolidateSkills(10);
|
|
74
|
-
this.printResult('Consolidate Skills', consolidateSkills);
|
|
75
|
-
|
|
76
|
-
const searchSkills = await this.benchmarkSearchSkills(200);
|
|
77
|
-
this.printResult('Search Skills', searchSkills);
|
|
78
|
-
|
|
79
|
-
const totalTime = Date.now() - suiteStartTime;
|
|
80
|
-
|
|
81
|
-
console.log('\n┌─────────────────────────────────────────────────────────┐');
|
|
82
|
-
console.log('│ BENCHMARK COMPLETE │');
|
|
83
|
-
console.log(`│ Total Time: ${(totalTime / 1000).toFixed(2)}s │`);
|
|
84
|
-
console.log('└─────────────────────────────────────────────────────────┘\n');
|
|
85
|
-
|
|
86
|
-
// Print performance metrics
|
|
87
|
-
const metrics = this.memory.getMetrics();
|
|
88
|
-
console.log('📈 PERFORMANCE METRICS\n');
|
|
89
|
-
console.log(` Store Operations: ${metrics.storeCount}`);
|
|
90
|
-
console.log(` Avg Store Time: ${metrics.avgStoreTime.toFixed(3)}ms`);
|
|
91
|
-
console.log(` Retrieve Operations: ${metrics.retrieveCount}`);
|
|
92
|
-
console.log(` Avg Retrieve Time: ${metrics.avgRetrieveTime.toFixed(3)}ms\n`);
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
agentdb: {
|
|
96
|
-
storeEpisode,
|
|
97
|
-
retrieveMemories,
|
|
98
|
-
queryWithContext,
|
|
99
|
-
consolidateSkills,
|
|
100
|
-
searchSkills,
|
|
101
|
-
},
|
|
102
|
-
overall: {
|
|
103
|
-
totalTime,
|
|
104
|
-
timestamp: new Date().toISOString(),
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Benchmark: Store Episode (JS API)
|
|
111
|
-
*/
|
|
112
|
-
private async benchmarkStoreEpisode(iterations: number): Promise<BenchmarkResult> {
|
|
113
|
-
const times: number[] = [];
|
|
114
|
-
|
|
115
|
-
for (let i = 0; i < iterations; i++) {
|
|
116
|
-
const episode: Episode = {
|
|
117
|
-
sessionId: `bench-${i}`,
|
|
118
|
-
taskName: 'navigation',
|
|
119
|
-
confidence: Math.random(),
|
|
120
|
-
success: Math.random() > 0.3,
|
|
121
|
-
outcome: 'Completed navigation task',
|
|
122
|
-
strategy: 'adaptive_planning',
|
|
123
|
-
metadata: { x: i, y: i * 2, latency: Math.random() * 100 },
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const start = performance.now();
|
|
127
|
-
await this.memory.storeEpisode(episode);
|
|
128
|
-
times.push(performance.now() - start);
|
|
129
|
-
|
|
130
|
-
if (i % 100 === 0 && i > 0) {
|
|
131
|
-
process.stderr.write(` Progress: ${i}/${iterations}\r`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return this.calculateStats('Store Episode', times);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* Benchmark: Retrieve Memories (JS API)
|
|
140
|
-
*/
|
|
141
|
-
private async benchmarkRetrieveMemories(iterations: number): Promise<BenchmarkResult> {
|
|
142
|
-
const times: number[] = [];
|
|
143
|
-
|
|
144
|
-
const queries = [
|
|
145
|
-
'navigation task',
|
|
146
|
-
'object detection',
|
|
147
|
-
'path planning',
|
|
148
|
-
'sensor fusion',
|
|
149
|
-
'motor control',
|
|
150
|
-
];
|
|
151
|
-
|
|
152
|
-
for (let i = 0; i < iterations; i++) {
|
|
153
|
-
const query = queries[i % queries.length];
|
|
154
|
-
|
|
155
|
-
const start = performance.now();
|
|
156
|
-
await this.memory.retrieveMemories(query, 5, {
|
|
157
|
-
onlySuccesses: true,
|
|
158
|
-
synthesizeContext: true,
|
|
159
|
-
});
|
|
160
|
-
times.push(performance.now() - start);
|
|
161
|
-
|
|
162
|
-
if (i % 50 === 0 && i > 0) {
|
|
163
|
-
process.stderr.write(` Progress: ${i}/${iterations}\r`);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return this.calculateStats('Retrieve Memories', times);
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Benchmark: Query with Context (JS API)
|
|
172
|
-
*/
|
|
173
|
-
private async benchmarkQueryWithContext(iterations: number): Promise<BenchmarkResult> {
|
|
174
|
-
const times: number[] = [];
|
|
175
|
-
|
|
176
|
-
for (let i = 0; i < iterations; i++) {
|
|
177
|
-
const start = performance.now();
|
|
178
|
-
await this.memory.queryWithContext('warehouse navigation', {
|
|
179
|
-
k: 10,
|
|
180
|
-
minConfidence: 0.5,
|
|
181
|
-
synthesizeReasoning: true,
|
|
182
|
-
});
|
|
183
|
-
times.push(performance.now() - start);
|
|
184
|
-
|
|
185
|
-
if (i % 30 === 0 && i > 0) {
|
|
186
|
-
process.stderr.write(` Progress: ${i}/${iterations}\r`);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
return this.calculateStats('Query with Context', times);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/**
|
|
194
|
-
* Benchmark: Consolidate Skills (JS API)
|
|
195
|
-
*/
|
|
196
|
-
private async benchmarkConsolidateSkills(iterations: number): Promise<BenchmarkResult> {
|
|
197
|
-
const times: number[] = [];
|
|
198
|
-
|
|
199
|
-
for (let i = 0; i < iterations; i++) {
|
|
200
|
-
const start = performance.now();
|
|
201
|
-
await this.memory.consolidateSkills({
|
|
202
|
-
minAttempts: 3,
|
|
203
|
-
minReward: 0.7,
|
|
204
|
-
timeWindowDays: 7,
|
|
205
|
-
enablePruning: true,
|
|
206
|
-
});
|
|
207
|
-
times.push(performance.now() - start);
|
|
208
|
-
|
|
209
|
-
if (i % 2 === 0 && i > 0) {
|
|
210
|
-
process.stderr.write(` Progress: ${i}/${iterations}\r`);
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return this.calculateStats('Consolidate Skills', times);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
/**
|
|
218
|
-
* Benchmark: Search Skills (JS API)
|
|
219
|
-
*/
|
|
220
|
-
private async benchmarkSearchSkills(iterations: number): Promise<BenchmarkResult> {
|
|
221
|
-
const times: number[] = [];
|
|
222
|
-
|
|
223
|
-
for (let i = 0; i < iterations; i++) {
|
|
224
|
-
const start = performance.now();
|
|
225
|
-
await this.memory.searchSkills('navigation', {
|
|
226
|
-
k: 5,
|
|
227
|
-
minSuccessRate: 0.5,
|
|
228
|
-
sortBy: 'success_rate',
|
|
229
|
-
});
|
|
230
|
-
times.push(performance.now() - start);
|
|
231
|
-
|
|
232
|
-
if (i % 20 === 0 && i > 0) {
|
|
233
|
-
process.stderr.write(` Progress: ${i}/${iterations}\r`);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return this.calculateStats('Search Skills', times);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
/**
|
|
241
|
-
* Calculate statistics from timing data
|
|
242
|
-
*/
|
|
243
|
-
private calculateStats(name: string, times: number[]): BenchmarkResult {
|
|
244
|
-
const sorted = [...times].sort((a, b) => a - b);
|
|
245
|
-
const total = times.reduce((a, b) => a + b, 0);
|
|
246
|
-
|
|
247
|
-
return {
|
|
248
|
-
name,
|
|
249
|
-
iterations: times.length,
|
|
250
|
-
totalTime: total,
|
|
251
|
-
avgTime: total / times.length,
|
|
252
|
-
minTime: sorted[0],
|
|
253
|
-
maxTime: sorted[sorted.length - 1],
|
|
254
|
-
opsPerSec: (times.length / total) * 1000,
|
|
255
|
-
p50: sorted[Math.floor(sorted.length * 0.50)],
|
|
256
|
-
p95: sorted[Math.floor(sorted.length * 0.95)],
|
|
257
|
-
p99: sorted[Math.floor(sorted.length * 0.99)],
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* Print benchmark result
|
|
263
|
-
*/
|
|
264
|
-
private printResult(name: string, result: BenchmarkResult): void {
|
|
265
|
-
console.log(`${name}:`);
|
|
266
|
-
console.log(` Iterations: ${result.iterations.toLocaleString()}`);
|
|
267
|
-
console.log(` Avg Time: ${result.avgTime.toFixed(3)}ms`);
|
|
268
|
-
console.log(` Min/Max: ${result.minTime.toFixed(3)}ms / ${result.maxTime.toFixed(3)}ms`);
|
|
269
|
-
console.log(` p50/p95/p99: ${result.p50.toFixed(3)}ms / ${result.p95.toFixed(3)}ms / ${result.p99.toFixed(3)}ms`);
|
|
270
|
-
console.log(` Ops/sec: ${result.opsPerSec.toFixed(0)}`);
|
|
271
|
-
console.log('');
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Export results to JSON
|
|
276
|
-
*/
|
|
277
|
-
async exportResults(suite: BenchmarkSuite, filename: string): Promise<void> {
|
|
278
|
-
const fs = await import('fs/promises');
|
|
279
|
-
await fs.writeFile(filename, JSON.stringify(suite, null, 2));
|
|
280
|
-
console.log(`📁 Results exported to ${filename}`);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
async close(): Promise<void> {
|
|
284
|
-
await this.memory.close();
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
// CLI entry point
|
|
289
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
290
|
-
const benchmark = new OptimizedBenchmark();
|
|
291
|
-
|
|
292
|
-
try {
|
|
293
|
-
await benchmark.initialize();
|
|
294
|
-
const results = await benchmark.runAll();
|
|
295
|
-
await benchmark.exportResults(results, './optimized-benchmark-results.json');
|
|
296
|
-
} catch (error) {
|
|
297
|
-
console.error('❌ Benchmark failed:', error);
|
|
298
|
-
process.exit(1);
|
|
299
|
-
} finally {
|
|
300
|
-
await benchmark.close();
|
|
301
|
-
}
|
|
302
|
-
}
|
package/src/optimized-memory.ts
DELETED
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Optimized AgentDB Memory Integration
|
|
3
|
-
*
|
|
4
|
-
* Uses AgentDB JavaScript API directly for maximum performance
|
|
5
|
-
* Eliminates CLI process spawning overhead (100x+ faster)
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { ReflexionMemory, SkillLibrary, ReasoningBank, CausalMemoryGraph } from 'agentdb';
|
|
9
|
-
import type { Episode, Memory } from './memory.js';
|
|
10
|
-
|
|
11
|
-
export interface Skill {
|
|
12
|
-
name: string;
|
|
13
|
-
description: string;
|
|
14
|
-
successRate: number;
|
|
15
|
-
avgReward: number;
|
|
16
|
-
attempts: number;
|
|
17
|
-
lastUsed: number;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface CausalReasoning {
|
|
21
|
-
cause: string;
|
|
22
|
-
effect: string;
|
|
23
|
-
confidence: number;
|
|
24
|
-
evidence: string[];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class OptimizedAgentDBMemory {
|
|
28
|
-
private reflexion: ReflexionMemory;
|
|
29
|
-
private skills: SkillLibrary;
|
|
30
|
-
private reasoning: ReasoningBank;
|
|
31
|
-
private causal: CausalMemoryGraph;
|
|
32
|
-
private dbPath: string;
|
|
33
|
-
private performanceMetrics: {
|
|
34
|
-
storeCount: number;
|
|
35
|
-
retrieveCount: number;
|
|
36
|
-
avgStoreTime: number;
|
|
37
|
-
avgRetrieveTime: number;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
constructor(dbPath: string) {
|
|
41
|
-
this.dbPath = dbPath;
|
|
42
|
-
this.performanceMetrics = {
|
|
43
|
-
storeCount: 0,
|
|
44
|
-
retrieveCount: 0,
|
|
45
|
-
avgStoreTime: 0,
|
|
46
|
-
avgRetrieveTime: 0,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async initialize(): Promise<void> {
|
|
51
|
-
const startTime = Date.now();
|
|
52
|
-
|
|
53
|
-
// Initialize AgentDB components with JS API
|
|
54
|
-
// These classes handle their own database initialization
|
|
55
|
-
this.reflexion = new ReflexionMemory();
|
|
56
|
-
this.skills = new SkillLibrary();
|
|
57
|
-
this.reasoning = new ReasoningBank();
|
|
58
|
-
this.causal = new CausalMemoryGraph();
|
|
59
|
-
|
|
60
|
-
const elapsed = Date.now() - startTime;
|
|
61
|
-
console.error(`✅ AgentDB initialized: ${this.dbPath}`);
|
|
62
|
-
console.error(`⚡ Initialization time: ${elapsed}ms`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Store episode using JS API (100x faster than CLI)
|
|
67
|
-
*/
|
|
68
|
-
async storeEpisode(episode: Episode): Promise<void> {
|
|
69
|
-
const startTime = Date.now();
|
|
70
|
-
|
|
71
|
-
await this.reflexion.store({
|
|
72
|
-
sessionId: episode.sessionId,
|
|
73
|
-
taskName: episode.taskName,
|
|
74
|
-
confidence: episode.confidence,
|
|
75
|
-
success: episode.success,
|
|
76
|
-
outcome: episode.outcome,
|
|
77
|
-
strategy: episode.strategy,
|
|
78
|
-
metadata: episode.metadata,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
const elapsed = Date.now() - startTime;
|
|
82
|
-
this.updateStoreMetrics(elapsed);
|
|
83
|
-
|
|
84
|
-
if (this.performanceMetrics.storeCount % 100 === 0) {
|
|
85
|
-
console.error(`💾 Stored episode: ${episode.taskName} (${elapsed}ms)`);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Retrieve memories using JS API (150x faster than CLI)
|
|
91
|
-
*/
|
|
92
|
-
async retrieveMemories(
|
|
93
|
-
query: string,
|
|
94
|
-
k: number = 5,
|
|
95
|
-
options: {
|
|
96
|
-
minReward?: number;
|
|
97
|
-
onlySuccesses?: boolean;
|
|
98
|
-
onlyFailures?: boolean;
|
|
99
|
-
synthesizeContext?: boolean;
|
|
100
|
-
} = {}
|
|
101
|
-
): Promise<Memory[]> {
|
|
102
|
-
const startTime = Date.now();
|
|
103
|
-
|
|
104
|
-
const results = await this.reflexion.retrieve(query, k, {
|
|
105
|
-
minReward: options.minReward,
|
|
106
|
-
onlySuccesses: options.onlySuccesses,
|
|
107
|
-
onlyFailures: options.onlyFailures,
|
|
108
|
-
synthesizeContext: options.synthesizeContext,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const elapsed = Date.now() - startTime;
|
|
112
|
-
this.updateRetrieveMetrics(elapsed);
|
|
113
|
-
|
|
114
|
-
return results.map((r: any) => ({
|
|
115
|
-
task: r.taskName || r.task,
|
|
116
|
-
confidence: r.confidence,
|
|
117
|
-
success: r.success,
|
|
118
|
-
outcome: r.outcome,
|
|
119
|
-
strategy: r.strategy,
|
|
120
|
-
timestamp: r.timestamp,
|
|
121
|
-
}));
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Query with causal reasoning and context synthesis
|
|
126
|
-
*/
|
|
127
|
-
async queryWithContext(
|
|
128
|
-
query: string,
|
|
129
|
-
options: {
|
|
130
|
-
k?: number;
|
|
131
|
-
minConfidence?: number;
|
|
132
|
-
synthesizeReasoning?: boolean;
|
|
133
|
-
} = {}
|
|
134
|
-
): Promise<{
|
|
135
|
-
memories: Memory[];
|
|
136
|
-
context?: string;
|
|
137
|
-
reasoning?: CausalReasoning[];
|
|
138
|
-
}> {
|
|
139
|
-
const { k = 5, minConfidence = 0.0, synthesizeReasoning = false } = options;
|
|
140
|
-
|
|
141
|
-
const memories = await this.retrieveMemories(query, k, {
|
|
142
|
-
minReward: minConfidence,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
let context: string | undefined;
|
|
146
|
-
let reasoning: CausalReasoning[] | undefined;
|
|
147
|
-
|
|
148
|
-
if (synthesizeReasoning && memories.length > 0) {
|
|
149
|
-
// Use ReasoningBank to synthesize insights
|
|
150
|
-
const insights = await this.reasoning.synthesize(
|
|
151
|
-
memories.map((m) => m.outcome)
|
|
152
|
-
);
|
|
153
|
-
context = insights.summary;
|
|
154
|
-
|
|
155
|
-
// Extract causal relationships
|
|
156
|
-
const causalLinks = await this.causal.query(query, { k: 3 });
|
|
157
|
-
reasoning = causalLinks.map((link: any) => ({
|
|
158
|
-
cause: link.cause,
|
|
159
|
-
effect: link.effect,
|
|
160
|
-
confidence: link.confidence,
|
|
161
|
-
evidence: link.evidence || [],
|
|
162
|
-
}));
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return { memories, context, reasoning };
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Consolidate skills from successful episodes
|
|
170
|
-
*/
|
|
171
|
-
async consolidateSkills(options: {
|
|
172
|
-
minAttempts?: number;
|
|
173
|
-
minReward?: number;
|
|
174
|
-
timeWindowDays?: number;
|
|
175
|
-
enablePruning?: boolean;
|
|
176
|
-
} = {}): Promise<void> {
|
|
177
|
-
const {
|
|
178
|
-
minAttempts = 3,
|
|
179
|
-
minReward = 0.7,
|
|
180
|
-
timeWindowDays = 7,
|
|
181
|
-
enablePruning = true,
|
|
182
|
-
} = options;
|
|
183
|
-
|
|
184
|
-
await this.skills.consolidate({
|
|
185
|
-
minAttempts,
|
|
186
|
-
minReward,
|
|
187
|
-
timeWindow: timeWindowDays * 24 * 60 * 60 * 1000,
|
|
188
|
-
enablePruning,
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Search skill library with semantic search
|
|
194
|
-
*/
|
|
195
|
-
async searchSkills(
|
|
196
|
-
query: string,
|
|
197
|
-
options: {
|
|
198
|
-
k?: number;
|
|
199
|
-
minSuccessRate?: number;
|
|
200
|
-
sortBy?: 'success_rate' | 'avg_reward' | 'attempts';
|
|
201
|
-
} = {}
|
|
202
|
-
): Promise<Skill[]> {
|
|
203
|
-
const { k = 5, minSuccessRate = 0.0, sortBy = 'success_rate' } = options;
|
|
204
|
-
|
|
205
|
-
const results = await this.skills.search(query, k, {
|
|
206
|
-
minSuccessRate,
|
|
207
|
-
sortBy,
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
return results.map((skill: any) => ({
|
|
211
|
-
name: skill.name,
|
|
212
|
-
description: skill.description,
|
|
213
|
-
successRate: skill.successRate,
|
|
214
|
-
avgReward: skill.avgReward,
|
|
215
|
-
attempts: skill.attempts,
|
|
216
|
-
lastUsed: skill.lastUsed,
|
|
217
|
-
}));
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Optimize database (vacuum, reindex, compact)
|
|
222
|
-
*/
|
|
223
|
-
async optimize(): Promise<void> {
|
|
224
|
-
await this.reflexion.vacuum();
|
|
225
|
-
await this.skills.reindex();
|
|
226
|
-
console.error('🔧 Database optimized');
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Get performance metrics
|
|
231
|
-
*/
|
|
232
|
-
getMetrics() {
|
|
233
|
-
return { ...this.performanceMetrics };
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Get database statistics
|
|
238
|
-
*/
|
|
239
|
-
async getStats(): Promise<any> {
|
|
240
|
-
const reflexionStats = await this.reflexion.getStats();
|
|
241
|
-
const skillStats = await this.skills.getStats();
|
|
242
|
-
|
|
243
|
-
return {
|
|
244
|
-
reflexion: reflexionStats,
|
|
245
|
-
skills: skillStats,
|
|
246
|
-
performance: this.performanceMetrics,
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
async close(): Promise<void> {
|
|
251
|
-
await this.reflexion.close();
|
|
252
|
-
await this.skills.close();
|
|
253
|
-
await this.reasoning.close();
|
|
254
|
-
await this.causal.close();
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// Private helper methods
|
|
258
|
-
private updateStoreMetrics(elapsed: number): void {
|
|
259
|
-
const { storeCount, avgStoreTime } = this.performanceMetrics;
|
|
260
|
-
this.performanceMetrics.storeCount = storeCount + 1;
|
|
261
|
-
this.performanceMetrics.avgStoreTime =
|
|
262
|
-
(avgStoreTime * storeCount + elapsed) / (storeCount + 1);
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
private updateRetrieveMetrics(elapsed: number): void {
|
|
266
|
-
const { retrieveCount, avgRetrieveTime } = this.performanceMetrics;
|
|
267
|
-
this.performanceMetrics.retrieveCount = retrieveCount + 1;
|
|
268
|
-
this.performanceMetrics.avgRetrieveTime =
|
|
269
|
-
(avgRetrieveTime * retrieveCount + elapsed) / (retrieveCount + 1);
|
|
270
|
-
}
|
|
271
|
-
}
|