agentic-flow 1.7.0 → 1.7.3
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/.claude/agents/test-neural.md +5 -0
- package/.claude/settings.json +20 -19
- package/.claude/skills/agentdb-memory-patterns/SKILL.md +166 -0
- package/.claude/skills/agentdb-vector-search/SKILL.md +126 -0
- package/.claude/skills/agentic-flow/agentdb-memory-patterns/SKILL.md +166 -0
- package/.claude/skills/agentic-flow/agentdb-vector-search/SKILL.md +126 -0
- package/.claude/skills/agentic-flow/reasoningbank-intelligence/SKILL.md +201 -0
- package/.claude/skills/agentic-flow/swarm-orchestration/SKILL.md +179 -0
- package/.claude/skills/reasoningbank-intelligence/SKILL.md +201 -0
- package/.claude/skills/skill-builder/README.md +308 -0
- package/.claude/skills/skill-builder/SKILL.md +910 -0
- package/.claude/skills/skill-builder/docs/SPECIFICATION.md +358 -0
- package/.claude/skills/skill-builder/resources/schemas/skill-frontmatter.schema.json +41 -0
- package/.claude/skills/skill-builder/resources/templates/full-skill.template +118 -0
- package/.claude/skills/skill-builder/resources/templates/minimal-skill.template +38 -0
- package/.claude/skills/skill-builder/scripts/generate-skill.sh +334 -0
- package/.claude/skills/skill-builder/scripts/validate-skill.sh +198 -0
- package/.claude/skills/swarm-orchestration/SKILL.md +179 -0
- package/CHANGELOG.md +117 -0
- package/README.md +81 -17
- package/dist/cli-proxy.js +33 -2
- package/dist/mcp/standalone-stdio.js +4 -200
- package/dist/reasoningbank/index.js +4 -0
- package/dist/utils/cli.js +22 -0
- package/docs/AGENTDB_INTEGRATION.md +379 -0
- package/package.json +4 -4
- package/.claude/answer.md +0 -1
- package/dist/agentdb/benchmarks/comprehensive-benchmark.js +0 -664
- package/dist/agentdb/benchmarks/frontier-benchmark.js +0 -419
- package/dist/agentdb/benchmarks/reflexion-benchmark.js +0 -370
- package/dist/agentdb/cli/agentdb-cli.js +0 -717
- package/dist/agentdb/controllers/CausalMemoryGraph.js +0 -322
- package/dist/agentdb/controllers/CausalRecall.js +0 -281
- package/dist/agentdb/controllers/EmbeddingService.js +0 -118
- package/dist/agentdb/controllers/ExplainableRecall.js +0 -387
- package/dist/agentdb/controllers/NightlyLearner.js +0 -382
- package/dist/agentdb/controllers/ReflexionMemory.js +0 -239
- package/dist/agentdb/controllers/SkillLibrary.js +0 -276
- package/dist/agentdb/controllers/frontier-index.js +0 -9
- package/dist/agentdb/controllers/index.js +0 -8
- package/dist/agentdb/index.js +0 -32
- package/dist/agentdb/optimizations/BatchOperations.js +0 -198
- package/dist/agentdb/optimizations/QueryOptimizer.js +0 -225
- package/dist/agentdb/optimizations/index.js +0 -7
- package/dist/agentdb/tests/frontier-features.test.js +0 -665
- package/dist/memory/SharedMemoryPool.js +0 -211
- package/dist/memory/index.js +0 -6
- package/dist/reasoningbank/AdvancedMemory.js +0 -67
- package/dist/reasoningbank/HybridBackend.js +0 -91
- package/dist/reasoningbank/index-new.js +0 -87
- package/docs/AGENTDB_TESTING.md +0 -411
- package/scripts/run-validation.sh +0 -165
- package/scripts/test-agentdb.sh +0 -153
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared Memory Pool for AgentDB
|
|
3
|
-
*
|
|
4
|
-
* Provides a singleton memory pool that multiple agents can share:
|
|
5
|
-
* - Single SQLite database connection (reduces overhead)
|
|
6
|
-
* - Single embedding model instance (saves ~150MB per agent)
|
|
7
|
-
* - Shared query cache (LRU with TTL)
|
|
8
|
-
* - Shared embedding cache (deduplication)
|
|
9
|
-
*
|
|
10
|
-
* Memory savings: ~300-500MB for 4+ concurrent agents
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* import { SharedMemoryPool } from 'agentic-flow/memory';
|
|
15
|
-
*
|
|
16
|
-
* const pool = SharedMemoryPool.getInstance();
|
|
17
|
-
* const db = pool.getDatabase();
|
|
18
|
-
* const embedder = pool.getEmbedder();
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
import Database from 'better-sqlite3';
|
|
22
|
-
import { EmbeddingService } from 'agentdb/controllers';
|
|
23
|
-
import * as path from 'path';
|
|
24
|
-
import * as fs from 'fs';
|
|
25
|
-
export class SharedMemoryPool {
|
|
26
|
-
static instance;
|
|
27
|
-
db;
|
|
28
|
-
embedder;
|
|
29
|
-
queryCache;
|
|
30
|
-
embeddingCache;
|
|
31
|
-
config;
|
|
32
|
-
initialized = false;
|
|
33
|
-
constructor(config = {}) {
|
|
34
|
-
this.config = {
|
|
35
|
-
dbPath: config.dbPath || './agentdb.db',
|
|
36
|
-
cacheSize: config.cacheSize || 1000,
|
|
37
|
-
embeddingCacheSize: config.embeddingCacheSize || 10000,
|
|
38
|
-
embeddingModel: config.embeddingModel || 'Xenova/all-MiniLM-L6-v2',
|
|
39
|
-
embeddingDimension: config.embeddingDimension || 384
|
|
40
|
-
};
|
|
41
|
-
// Initialize SQLite with optimized settings
|
|
42
|
-
const dbDir = path.dirname(this.config.dbPath);
|
|
43
|
-
if (!fs.existsSync(dbDir)) {
|
|
44
|
-
fs.mkdirSync(dbDir, { recursive: true });
|
|
45
|
-
}
|
|
46
|
-
this.db = new Database(this.config.dbPath);
|
|
47
|
-
// Optimize SQLite for performance
|
|
48
|
-
this.db.pragma('journal_mode = WAL'); // Write-Ahead Logging
|
|
49
|
-
this.db.pragma('synchronous = NORMAL'); // Balanced safety/performance
|
|
50
|
-
this.db.pragma('cache_size = -65536'); // 64MB cache
|
|
51
|
-
this.db.pragma('mmap_size = 268435456'); // 256MB memory-mapped I/O
|
|
52
|
-
this.db.pragma('page_size = 8192'); // 8KB pages
|
|
53
|
-
this.db.pragma('temp_store = MEMORY'); // Keep temp tables in memory
|
|
54
|
-
// Initialize embedding service (will be lazy-loaded)
|
|
55
|
-
this.embedder = new EmbeddingService({
|
|
56
|
-
model: this.config.embeddingModel,
|
|
57
|
-
dimension: this.config.embeddingDimension,
|
|
58
|
-
provider: 'transformers'
|
|
59
|
-
});
|
|
60
|
-
// Initialize caches
|
|
61
|
-
this.queryCache = new Map();
|
|
62
|
-
this.embeddingCache = new Map();
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Get singleton instance of SharedMemoryPool
|
|
66
|
-
*/
|
|
67
|
-
static getInstance(config) {
|
|
68
|
-
if (!SharedMemoryPool.instance) {
|
|
69
|
-
SharedMemoryPool.instance = new SharedMemoryPool(config);
|
|
70
|
-
}
|
|
71
|
-
return SharedMemoryPool.instance;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Reset singleton instance (for testing)
|
|
75
|
-
*/
|
|
76
|
-
static resetInstance() {
|
|
77
|
-
if (SharedMemoryPool.instance) {
|
|
78
|
-
SharedMemoryPool.instance.close();
|
|
79
|
-
SharedMemoryPool.instance = null;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Ensure embedding service is initialized
|
|
84
|
-
*/
|
|
85
|
-
async ensureInitialized() {
|
|
86
|
-
if (!this.initialized) {
|
|
87
|
-
await this.embedder.initialize();
|
|
88
|
-
this.initialized = true;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Get shared database connection
|
|
93
|
-
*/
|
|
94
|
-
getDatabase() {
|
|
95
|
-
return this.db;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Get shared embedding service
|
|
99
|
-
*/
|
|
100
|
-
getEmbedder() {
|
|
101
|
-
return this.embedder;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* Get or compute embedding with caching
|
|
105
|
-
*
|
|
106
|
-
* @param text Text to embed
|
|
107
|
-
* @returns Cached or newly computed embedding
|
|
108
|
-
*/
|
|
109
|
-
async getCachedEmbedding(text) {
|
|
110
|
-
const cached = this.embeddingCache.get(text);
|
|
111
|
-
if (cached)
|
|
112
|
-
return cached;
|
|
113
|
-
await this.ensureInitialized();
|
|
114
|
-
const embedding = await this.embedder.embed(text);
|
|
115
|
-
// LRU eviction if cache too large
|
|
116
|
-
if (this.embeddingCache.size >= this.config.embeddingCacheSize) {
|
|
117
|
-
const firstKey = this.embeddingCache.keys().next().value;
|
|
118
|
-
if (firstKey) {
|
|
119
|
-
this.embeddingCache.delete(firstKey);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
this.embeddingCache.set(text, embedding);
|
|
123
|
-
return embedding;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Cache query result with TTL
|
|
127
|
-
*
|
|
128
|
-
* @param key Cache key
|
|
129
|
-
* @param result Result to cache
|
|
130
|
-
* @param ttl Time-to-live in milliseconds (default: 60s)
|
|
131
|
-
*/
|
|
132
|
-
cacheQuery(key, result, ttl = 60000) {
|
|
133
|
-
// LRU eviction if cache too large
|
|
134
|
-
if (this.queryCache.size >= this.config.cacheSize) {
|
|
135
|
-
const firstKey = this.queryCache.keys().next().value;
|
|
136
|
-
if (firstKey) {
|
|
137
|
-
this.queryCache.delete(firstKey);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
this.queryCache.set(key, {
|
|
141
|
-
result,
|
|
142
|
-
expires: Date.now() + ttl
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Get cached query result
|
|
147
|
-
*
|
|
148
|
-
* @param key Cache key
|
|
149
|
-
* @returns Cached result or null if expired/missing
|
|
150
|
-
*/
|
|
151
|
-
getCachedQuery(key) {
|
|
152
|
-
const cached = this.queryCache.get(key);
|
|
153
|
-
if (!cached)
|
|
154
|
-
return null;
|
|
155
|
-
if (Date.now() > cached.expires) {
|
|
156
|
-
this.queryCache.delete(key);
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
159
|
-
return cached.result;
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Clear all caches
|
|
163
|
-
*/
|
|
164
|
-
clearCaches() {
|
|
165
|
-
this.queryCache.clear();
|
|
166
|
-
this.embeddingCache.clear();
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Get memory pool statistics
|
|
170
|
-
*/
|
|
171
|
-
getStats() {
|
|
172
|
-
const dbStats = this.db.prepare(`
|
|
173
|
-
SELECT
|
|
174
|
-
(SELECT COUNT(*) FROM sqlite_master WHERE type='table') as tables,
|
|
175
|
-
(SELECT page_count * page_size FROM pragma_page_count(), pragma_page_size()) as dbSize
|
|
176
|
-
`).get();
|
|
177
|
-
return {
|
|
178
|
-
database: {
|
|
179
|
-
path: this.config.dbPath,
|
|
180
|
-
size: dbStats.dbSize,
|
|
181
|
-
tables: dbStats.tables,
|
|
182
|
-
walMode: this.db.pragma('journal_mode', { simple: true }),
|
|
183
|
-
},
|
|
184
|
-
cache: {
|
|
185
|
-
queryCacheSize: this.queryCache.size,
|
|
186
|
-
queryCacheMax: this.config.cacheSize,
|
|
187
|
-
embeddingCacheSize: this.embeddingCache.size,
|
|
188
|
-
embeddingCacheMax: this.config.embeddingCacheSize,
|
|
189
|
-
},
|
|
190
|
-
embedder: {
|
|
191
|
-
model: this.config.embeddingModel,
|
|
192
|
-
dimension: this.config.embeddingDimension,
|
|
193
|
-
initialized: this.initialized,
|
|
194
|
-
},
|
|
195
|
-
memory: {
|
|
196
|
-
heapUsed: Math.round(process.memoryUsage().heapUsed / 1024 / 1024),
|
|
197
|
-
external: Math.round(process.memoryUsage().external / 1024 / 1024),
|
|
198
|
-
}
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Close database connection and cleanup
|
|
203
|
-
*/
|
|
204
|
-
close() {
|
|
205
|
-
this.clearCaches();
|
|
206
|
-
this.db.close();
|
|
207
|
-
this.initialized = false;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
// Export singleton getter for convenience
|
|
211
|
-
export const getSharedMemoryPool = SharedMemoryPool.getInstance;
|
package/dist/memory/index.js
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Advanced Memory System (Simplified for v1.7.0)
|
|
3
|
-
*
|
|
4
|
-
* NOTE: This is a simplified version that compiles with agentdb v1.3.9.
|
|
5
|
-
* Full implementation requires additional API alignment work.
|
|
6
|
-
*
|
|
7
|
-
* TODO v1.7.1: Implement full advanced memory features
|
|
8
|
-
*/
|
|
9
|
-
import { HybridReasoningBank } from './HybridBackend.js';
|
|
10
|
-
import { NightlyLearner } from 'agentdb/controllers/NightlyLearner';
|
|
11
|
-
import { SharedMemoryPool } from '../memory/SharedMemoryPool.js';
|
|
12
|
-
export class AdvancedMemorySystem {
|
|
13
|
-
reasoning;
|
|
14
|
-
learner;
|
|
15
|
-
pool;
|
|
16
|
-
constructor(options = {}) {
|
|
17
|
-
this.reasoning = new HybridReasoningBank(options);
|
|
18
|
-
this.pool = SharedMemoryPool.getInstance();
|
|
19
|
-
const db = this.pool.getDatabase();
|
|
20
|
-
const embedder = this.pool.getEmbedder();
|
|
21
|
-
this.learner = new NightlyLearner(db, embedder);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Auto-consolidate successful patterns into skills
|
|
25
|
-
*/
|
|
26
|
-
async autoConsolidate(options = {}) {
|
|
27
|
-
// Use NightlyLearner.run() for consolidation
|
|
28
|
-
const report = await this.learner.run();
|
|
29
|
-
return {
|
|
30
|
-
skillsCreated: report.edgesDiscovered || 0,
|
|
31
|
-
causalEdgesCreated: report.edgesPruned || 0,
|
|
32
|
-
patternsAnalyzed: report.experimentsCompleted || 0
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Learn from past failures
|
|
37
|
-
*/
|
|
38
|
-
async replayFailures(task, k = 5) {
|
|
39
|
-
const failures = await this.reasoning.retrievePatterns(task, {
|
|
40
|
-
k,
|
|
41
|
-
onlyFailures: true
|
|
42
|
-
});
|
|
43
|
-
return failures.map(f => ({
|
|
44
|
-
critique: f.critique || 'No critique available',
|
|
45
|
-
whatWentWrong: [f.task || 'Unknown'],
|
|
46
|
-
howToFix: ['Review similar successful patterns'],
|
|
47
|
-
similarFailures: failures.length
|
|
48
|
-
}));
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* What-if causal analysis
|
|
52
|
-
*/
|
|
53
|
-
async whatIfAnalysis(action) {
|
|
54
|
-
return this.reasoning.whatIfAnalysis(action);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Compose multiple skills for a complex task
|
|
58
|
-
*/
|
|
59
|
-
async composeSkills(task, k = 5) {
|
|
60
|
-
const skills = await this.reasoning.searchSkills(task, k);
|
|
61
|
-
return {
|
|
62
|
-
availableSkills: skills,
|
|
63
|
-
compositionPlan: skills.map(s => s.name).join(' → '),
|
|
64
|
-
expectedSuccessRate: skills.length > 0 ? skills[0].successRate || 0 : 0
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hybrid ReasoningBank Backend (Simplified for v1.7.0)
|
|
3
|
-
*
|
|
4
|
-
* NOTE: This is a simplified version that compiles with agentdb v1.3.9.
|
|
5
|
-
* Full implementation with WASM acceleration and causal reasoning requires
|
|
6
|
-
* additional API alignment work.
|
|
7
|
-
*
|
|
8
|
-
* TODO v1.7.1: Implement full hybrid backend with:
|
|
9
|
-
* - WASM-accelerated similarity computation
|
|
10
|
-
* - CausalRecall integration
|
|
11
|
-
* - Skill consolidation
|
|
12
|
-
* - What-if analysis
|
|
13
|
-
*/
|
|
14
|
-
import { SharedMemoryPool } from '../memory/SharedMemoryPool.js';
|
|
15
|
-
import { ReflexionMemory } from 'agentdb/controllers/ReflexionMemory';
|
|
16
|
-
import { SkillLibrary } from 'agentdb/controllers/SkillLibrary';
|
|
17
|
-
export class HybridReasoningBank {
|
|
18
|
-
memory;
|
|
19
|
-
reflexion;
|
|
20
|
-
skills;
|
|
21
|
-
constructor(options = {}) {
|
|
22
|
-
this.memory = SharedMemoryPool.getInstance();
|
|
23
|
-
const db = this.memory.getDatabase();
|
|
24
|
-
const embedder = this.memory.getEmbedder();
|
|
25
|
-
this.reflexion = new ReflexionMemory(db, embedder);
|
|
26
|
-
this.skills = new SkillLibrary(db, embedder);
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Store a reasoning pattern
|
|
30
|
-
*/
|
|
31
|
-
async storePattern(pattern) {
|
|
32
|
-
return this.reflexion.storeEpisode(pattern);
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Retrieve similar patterns
|
|
36
|
-
*/
|
|
37
|
-
async retrievePatterns(query, options = {}) {
|
|
38
|
-
return this.reflexion.retrieveRelevant({
|
|
39
|
-
task: query,
|
|
40
|
-
k: options.k || 5,
|
|
41
|
-
onlySuccesses: options.onlySuccesses,
|
|
42
|
-
onlyFailures: options.onlyFailures
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Learn optimal strategy (simplified version)
|
|
47
|
-
*/
|
|
48
|
-
async learnStrategy(task) {
|
|
49
|
-
const patterns = await this.retrievePatterns(task, { k: 10, onlySuccesses: true });
|
|
50
|
-
return {
|
|
51
|
-
patterns,
|
|
52
|
-
causality: {
|
|
53
|
-
action: task,
|
|
54
|
-
avgReward: patterns.length > 0 ? patterns[0].reward || 0 : 0,
|
|
55
|
-
avgUplift: 0,
|
|
56
|
-
confidence: patterns.length > 0 ? 0.8 : 0.3,
|
|
57
|
-
evidenceCount: patterns.length,
|
|
58
|
-
recommendation: patterns.length > 0 ? 'DO_IT' : 'NEUTRAL'
|
|
59
|
-
},
|
|
60
|
-
confidence: patterns.length > 0 ? 0.8 : 0.3,
|
|
61
|
-
recommendation: patterns.length > 0 ? `Found ${patterns.length} similar patterns` : 'No patterns found'
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Auto-consolidate patterns into skills (stub)
|
|
66
|
-
*/
|
|
67
|
-
async autoConsolidate(options = {}) {
|
|
68
|
-
// TODO: Implement using NightlyLearner.run()
|
|
69
|
-
return { skillsCreated: 0 };
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* What-if causal analysis (stub)
|
|
73
|
-
*/
|
|
74
|
-
async whatIfAnalysis(action) {
|
|
75
|
-
// TODO: Implement using CausalRecall
|
|
76
|
-
return {
|
|
77
|
-
action,
|
|
78
|
-
avgReward: 0,
|
|
79
|
-
avgUplift: 0,
|
|
80
|
-
confidence: 0,
|
|
81
|
-
evidenceCount: 0,
|
|
82
|
-
recommendation: 'NEUTRAL'
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Search for relevant skills
|
|
87
|
-
*/
|
|
88
|
-
async searchSkills(taskType, k = 5) {
|
|
89
|
-
return this.skills.searchSkills({ task: taskType, k });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ReasoningBank - Closed-loop memory system for AI agents
|
|
3
|
-
* Based on arXiv:2509.25140 (Google DeepMind)
|
|
4
|
-
*
|
|
5
|
-
* @since v1.7.0 - Integrated AgentDB for optimal performance
|
|
6
|
-
*/
|
|
7
|
-
// New hybrid backend (recommended for new code)
|
|
8
|
-
export { HybridReasoningBank } from './HybridBackend.js';
|
|
9
|
-
export { AdvancedMemorySystem } from './AdvancedMemory.js';
|
|
10
|
-
// Re-export AgentDB controllers for advanced usage
|
|
11
|
-
export { ReflexionMemory } from 'agentdb/controllers/ReflexionMemory';
|
|
12
|
-
export { SkillLibrary } from 'agentdb/controllers/SkillLibrary';
|
|
13
|
-
export { CausalMemoryGraph } from 'agentdb/controllers/CausalMemoryGraph';
|
|
14
|
-
export { CausalRecall } from 'agentdb/controllers/CausalRecall';
|
|
15
|
-
export { NightlyLearner } from 'agentdb/controllers/NightlyLearner';
|
|
16
|
-
export { EmbeddingService } from 'agentdb/controllers/EmbeddingService';
|
|
17
|
-
// Original ReasoningBank implementations (backwards compatibility)
|
|
18
|
-
export { retrieveMemories, formatMemoriesForPrompt } from './core/retrieve.js';
|
|
19
|
-
export { judgeTrajectory } from './core/judge.js';
|
|
20
|
-
export { distillMemories } from './core/distill.js';
|
|
21
|
-
export { consolidate, shouldConsolidate } from './core/consolidate.js';
|
|
22
|
-
export { mattsParallel, mattsSequential } from './core/matts.js';
|
|
23
|
-
export { computeEmbedding, clearEmbeddingCache } from './utils/embeddings.js';
|
|
24
|
-
export { mmrSelection, cosineSimilarity } from './utils/mmr.js';
|
|
25
|
-
export { scrubPII, containsPII, scrubMemory } from './utils/pii-scrubber.js';
|
|
26
|
-
export { loadConfig } from './utils/config.js';
|
|
27
|
-
// Re-export database utilities
|
|
28
|
-
import * as db from './db/queries.js';
|
|
29
|
-
export { db };
|
|
30
|
-
// Original functions (backwards compatibility)
|
|
31
|
-
import { loadConfig } from './utils/config.js';
|
|
32
|
-
import { retrieveMemories } from './core/retrieve.js';
|
|
33
|
-
import { judgeTrajectory } from './core/judge.js';
|
|
34
|
-
import { distillMemories } from './core/distill.js';
|
|
35
|
-
import { shouldConsolidate as shouldCons, consolidate as cons } from './core/consolidate.js';
|
|
36
|
-
export async function initialize() {
|
|
37
|
-
const config = loadConfig();
|
|
38
|
-
console.log('[ReasoningBank] Initializing...');
|
|
39
|
-
console.log(`[ReasoningBank] Enabled: ${!!process.env.REASONINGBANK_ENABLED}`);
|
|
40
|
-
console.log(`[ReasoningBank] Database: ${process.env.CLAUDE_FLOW_DB_PATH || '.swarm/memory.db'}`);
|
|
41
|
-
console.log(`[ReasoningBank] Embeddings: ${config.embeddings.provider}`);
|
|
42
|
-
console.log(`[ReasoningBank] Retrieval k: ${config.retrieve.k}`);
|
|
43
|
-
try {
|
|
44
|
-
await db.runMigrations();
|
|
45
|
-
console.log(`[ReasoningBank] Database migrated successfully`);
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
console.error('[ReasoningBank] Migration error:', error);
|
|
49
|
-
throw new Error('ReasoningBank initialization failed: could not run migrations');
|
|
50
|
-
}
|
|
51
|
-
try {
|
|
52
|
-
const dbConn = db.getDb();
|
|
53
|
-
const tables = dbConn.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'pattern%'").all();
|
|
54
|
-
console.log(`[ReasoningBank] Database OK: ${tables.length} tables found`);
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
console.error('[ReasoningBank] Database error:', error);
|
|
58
|
-
throw new Error('ReasoningBank initialization failed: database not accessible');
|
|
59
|
-
}
|
|
60
|
-
console.log('[ReasoningBank] Initialization complete');
|
|
61
|
-
}
|
|
62
|
-
export async function runTask(options) {
|
|
63
|
-
console.log(`[ReasoningBank] Running task: ${options.taskId}`);
|
|
64
|
-
const memories = await retrieveMemories(options.query, {
|
|
65
|
-
domain: options.domain,
|
|
66
|
-
agent: options.agentId
|
|
67
|
-
});
|
|
68
|
-
console.log(`[ReasoningBank] Retrieved ${memories.length} memories`);
|
|
69
|
-
const trajectory = await options.executeFn(memories);
|
|
70
|
-
const verdict = await judgeTrajectory(trajectory, options.query);
|
|
71
|
-
console.log(`[ReasoningBank] Verdict: ${verdict.label} (${verdict.confidence})`);
|
|
72
|
-
const newMemories = await distillMemories(trajectory, verdict, options.query, {
|
|
73
|
-
taskId: options.taskId,
|
|
74
|
-
agentId: options.agentId,
|
|
75
|
-
domain: options.domain
|
|
76
|
-
});
|
|
77
|
-
console.log(`[ReasoningBank] Distilled ${newMemories.length} new memories`);
|
|
78
|
-
let consolidated = false;
|
|
79
|
-
if (shouldCons()) {
|
|
80
|
-
console.log('[ReasoningBank] Running consolidation...');
|
|
81
|
-
await cons();
|
|
82
|
-
consolidated = true;
|
|
83
|
-
}
|
|
84
|
-
return { verdict, usedMemories: memories, newMemories, consolidated };
|
|
85
|
-
}
|
|
86
|
-
export const VERSION = '1.7.0';
|
|
87
|
-
export const PAPER_URL = 'https://arxiv.org/html/2509.25140v1';
|