agentic-flow 1.5.11 → 1.5.13
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/README.md +2 -1
- package/dist/reasoningbank/backend-selector.js +145 -0
- package/dist/reasoningbank/index.js +4 -0
- package/dist/reasoningbank/wasm-adapter.js +1 -1
- package/docs/DOCKER_VALIDATION_RESULTS.md +391 -0
- package/docs/IMPLEMENTATION_SUMMARY.md +369 -0
- package/docs/NO_REGRESSIONS_CONFIRMED.md +384 -0
- package/docs/PUBLICATION_REPORT_v1.5.11.md +421 -0
- package/docs/REASONINGBANK_BACKENDS.md +375 -0
- package/docs/REASONINGBANK_FIXES.md +455 -0
- package/docs/REASONINGBANK_INVESTIGATION.md +380 -0
- package/docs/WASM_ESM_FIX.md +180 -0
- package/package.json +14 -2
- package/validation/docker/Dockerfile.reasoningbank-local +24 -0
- package/validation/docker/Dockerfile.reasoningbank-test +21 -0
- package/validation/docker/README.md +234 -0
- package/validation/docker/docker-compose.yml +29 -0
- package/validation/docker/test-reasoningbank-npx.mjs +442 -0
- package/validation/test-regression.mjs +246 -0
- package/wasm/reasoningbank/package.json +6 -0
- package/wasm/reasoningbank/reasoningbank_wasm.js +4 -553
- package/wasm/reasoningbank/reasoningbank_wasm_bg.js +555 -0
- package/wasm/reasoningbank/reasoningbank_wasm_bg.wasm +0 -0
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
# ReasoningBank Storage Backends
|
|
2
|
+
|
|
3
|
+
ReasoningBank provides **two storage implementations** optimized for different environments:
|
|
4
|
+
|
|
5
|
+
## 📊 Backend Comparison
|
|
6
|
+
|
|
7
|
+
| Backend | Environment | Storage | Persistence | Performance | Use Case |
|
|
8
|
+
|---------|-------------|---------|-------------|-------------|----------|
|
|
9
|
+
| **Node.js** | CLI, servers | SQLite | ✅ Yes | 2-5ms/op | Production, long-term memory |
|
|
10
|
+
| **WASM** | Browser | IndexedDB | ✅ Yes | 1-3ms/op | Web apps, client-side |
|
|
11
|
+
| **WASM** | Node.js | RAM | ❌ No | 0.04ms/op | Temporary data, fast access |
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 🔧 Usage
|
|
16
|
+
|
|
17
|
+
### Node.js Backend (Recommended for CLIs)
|
|
18
|
+
|
|
19
|
+
**Use when:** Building CLIs, servers, or any application needing persistent storage.
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import { ReasoningBank } from 'agentic-flow/dist/reasoningbank/index.js';
|
|
23
|
+
|
|
24
|
+
// Initialize with SQLite database
|
|
25
|
+
const rb = new ReasoningBank({
|
|
26
|
+
dbPath: '.swarm/memory.db'
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Store pattern (persists to disk)
|
|
30
|
+
await rb.storePattern({
|
|
31
|
+
task_description: 'Implement authentication',
|
|
32
|
+
task_category: 'auth',
|
|
33
|
+
strategy: 'jwt-tokens',
|
|
34
|
+
success_score: 0.9
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Search patterns (queries SQLite database)
|
|
38
|
+
const patterns = await rb.searchByCategory('auth', 10);
|
|
39
|
+
// Returns: All patterns from database ✅
|
|
40
|
+
|
|
41
|
+
// Semantic search
|
|
42
|
+
const similar = await rb.findSimilar('user login', 'auth', 5);
|
|
43
|
+
// Returns: Similar patterns with scores (e.g., 0.54-0.62)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**Features:**
|
|
47
|
+
- ✅ Persistent SQLite storage
|
|
48
|
+
- ✅ Automatic embedding generation
|
|
49
|
+
- ✅ Fast semantic search (2-5ms)
|
|
50
|
+
- ✅ Production-ready
|
|
51
|
+
- ✅ Cross-session memory
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
### WASM Backend (For Browsers)
|
|
56
|
+
|
|
57
|
+
**Use when:** Building web applications that need client-side storage.
|
|
58
|
+
|
|
59
|
+
```javascript
|
|
60
|
+
import { createReasoningBank } from 'agentic-flow/dist/reasoningbank/wasm-adapter.js';
|
|
61
|
+
|
|
62
|
+
// Initialize WASM instance (uses IndexedDB in browser)
|
|
63
|
+
const rb = await createReasoningBank('my-app-db');
|
|
64
|
+
|
|
65
|
+
// Store pattern (persists to IndexedDB)
|
|
66
|
+
await rb.storePattern({
|
|
67
|
+
task_description: 'Handle form validation',
|
|
68
|
+
task_category: 'ui',
|
|
69
|
+
strategy: 'real-time-validation',
|
|
70
|
+
success_score: 0.95
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// Semantic search
|
|
74
|
+
const similar = await rb.findSimilar('user input validation', 'ui', 5);
|
|
75
|
+
// Returns: Similar patterns with scores
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Features:**
|
|
79
|
+
- ✅ Persistent IndexedDB storage (browser)
|
|
80
|
+
- ✅ Native performance via WASM
|
|
81
|
+
- ✅ Ultra-fast operations (0.04ms in-memory)
|
|
82
|
+
- ✅ Browser-optimized
|
|
83
|
+
- ⚠️ In-memory only in Node.js (ephemeral)
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## 🎯 Backend Selection Guide
|
|
88
|
+
|
|
89
|
+
### Automatic Selection (Recommended)
|
|
90
|
+
|
|
91
|
+
```javascript
|
|
92
|
+
// Environment-aware import
|
|
93
|
+
const ReasoningBankImpl = typeof window !== 'undefined'
|
|
94
|
+
? await import('agentic-flow/dist/reasoningbank/wasm-adapter.js')
|
|
95
|
+
: await import('agentic-flow/dist/reasoningbank/index.js');
|
|
96
|
+
|
|
97
|
+
const rb = typeof window !== 'undefined'
|
|
98
|
+
? await ReasoningBankImpl.createReasoningBank('app-memory')
|
|
99
|
+
: new ReasoningBankImpl.ReasoningBank({ dbPath: '.swarm/memory.db' });
|
|
100
|
+
|
|
101
|
+
// Now use rb normally - it will work optimally in both environments
|
|
102
|
+
const patterns = await rb.searchByCategory('category', 10);
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Manual Selection
|
|
106
|
+
|
|
107
|
+
**Choose Node.js backend when:**
|
|
108
|
+
- Building CLI tools
|
|
109
|
+
- Need persistent storage
|
|
110
|
+
- Running on servers
|
|
111
|
+
- Require SQLite features
|
|
112
|
+
|
|
113
|
+
**Choose WASM backend when:**
|
|
114
|
+
- Building web apps
|
|
115
|
+
- Need client-side storage
|
|
116
|
+
- Want maximum browser performance
|
|
117
|
+
- Require offline capabilities
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
## 🔍 Key Differences
|
|
122
|
+
|
|
123
|
+
### Storage Location
|
|
124
|
+
|
|
125
|
+
**Node.js:**
|
|
126
|
+
```
|
|
127
|
+
.swarm/memory.db (SQLite database on disk)
|
|
128
|
+
├── patterns table
|
|
129
|
+
├── pattern_embeddings table
|
|
130
|
+
└── Full SQL query support
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
**WASM (Browser):**
|
|
134
|
+
```
|
|
135
|
+
IndexedDB: my-app-db (browser storage)
|
|
136
|
+
├── patterns store
|
|
137
|
+
├── embeddings store
|
|
138
|
+
└── Fast key-value lookups
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
**WASM (Node.js):**
|
|
142
|
+
```
|
|
143
|
+
RAM only (ephemeral, lost on process exit)
|
|
144
|
+
├── In-memory HashMap
|
|
145
|
+
└── Fastest access, no persistence
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Embedding Generation
|
|
149
|
+
|
|
150
|
+
Both backends **automatically generate embeddings** when you store patterns:
|
|
151
|
+
|
|
152
|
+
```rust
|
|
153
|
+
// Internal: reasoningbank-core/src/engine.rs
|
|
154
|
+
pub fn prepare_pattern(&self, mut pattern: Pattern) -> Result<Pattern> {
|
|
155
|
+
// Auto-generate embedding if not present
|
|
156
|
+
if pattern.embedding.is_none() {
|
|
157
|
+
let embedding = VectorEmbedding::from_text(&pattern.task_description);
|
|
158
|
+
pattern.embedding = Some(embedding.values);
|
|
159
|
+
}
|
|
160
|
+
Ok(pattern)
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
**You don't need to manually generate embeddings!** They are created automatically from your task description.
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## 📦 Package.json Integration
|
|
169
|
+
|
|
170
|
+
For projects supporting both Node.js and browsers, use conditional exports:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"name": "my-app",
|
|
175
|
+
"exports": {
|
|
176
|
+
"./memory": {
|
|
177
|
+
"node": "./dist/memory-node.js",
|
|
178
|
+
"browser": "./dist/memory-browser.js"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
**memory-node.js:**
|
|
185
|
+
```javascript
|
|
186
|
+
export { ReasoningBank } from 'agentic-flow/dist/reasoningbank/index.js';
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
**memory-browser.js:**
|
|
190
|
+
```javascript
|
|
191
|
+
export { createReasoningBank as ReasoningBank } from 'agentic-flow/dist/reasoningbank/wasm-adapter.js';
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
## 🧪 Validation
|
|
197
|
+
|
|
198
|
+
### Test Node.js Backend
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
node <<EOF
|
|
202
|
+
import { ReasoningBank } from 'agentic-flow/dist/reasoningbank/index.js';
|
|
203
|
+
|
|
204
|
+
const rb = new ReasoningBank({ dbPath: '.swarm/memory.db' });
|
|
205
|
+
|
|
206
|
+
// Store
|
|
207
|
+
const id = await rb.storePattern({
|
|
208
|
+
task_description: 'Test pattern',
|
|
209
|
+
task_category: 'test',
|
|
210
|
+
strategy: 'validation',
|
|
211
|
+
success_score: 0.95
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// Search
|
|
215
|
+
const patterns = await rb.searchByCategory('test', 10);
|
|
216
|
+
console.log(\`Found \${patterns.length} patterns\`);
|
|
217
|
+
// Expected: 1 pattern
|
|
218
|
+
|
|
219
|
+
// Get stats
|
|
220
|
+
const stats = await rb.getStats();
|
|
221
|
+
console.log(stats);
|
|
222
|
+
// Expected: { total_patterns: 1, total_categories: 1 }
|
|
223
|
+
EOF
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Test WASM Backend (Browser)
|
|
227
|
+
|
|
228
|
+
```javascript
|
|
229
|
+
// In browser console or webpack bundle
|
|
230
|
+
import { createReasoningBank } from 'agentic-flow/dist/reasoningbank/wasm-adapter.js';
|
|
231
|
+
|
|
232
|
+
const rb = await createReasoningBank('test-db');
|
|
233
|
+
|
|
234
|
+
// Store
|
|
235
|
+
await rb.storePattern({
|
|
236
|
+
task_description: 'Browser test',
|
|
237
|
+
task_category: 'test',
|
|
238
|
+
strategy: 'client-side',
|
|
239
|
+
success_score: 0.9
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
// Search
|
|
243
|
+
const patterns = await rb.searchByCategory('test', 10);
|
|
244
|
+
console.log(`Found ${patterns.length} patterns`);
|
|
245
|
+
// Expected: 1 pattern
|
|
246
|
+
|
|
247
|
+
// Semantic search
|
|
248
|
+
const similar = await rb.findSimilar('test validation', 'test', 5);
|
|
249
|
+
console.log(`Similarity: ${similar[0]?.similarity_score}`);
|
|
250
|
+
// Expected: score > 0.5
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Test WASM Backend (Node.js - In-Memory)
|
|
254
|
+
|
|
255
|
+
```bash
|
|
256
|
+
node --experimental-wasm-modules <<EOF
|
|
257
|
+
import { createReasoningBank } from 'agentic-flow/dist/reasoningbank/wasm-adapter.js';
|
|
258
|
+
|
|
259
|
+
const rb = await createReasoningBank('test');
|
|
260
|
+
|
|
261
|
+
// Store
|
|
262
|
+
await rb.storePattern({
|
|
263
|
+
task_description: 'Node WASM test',
|
|
264
|
+
task_category: 'test',
|
|
265
|
+
strategy: 'in-memory',
|
|
266
|
+
success_score: 0.92
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
// Search (same session)
|
|
270
|
+
const patterns = await rb.searchByCategory('test', 10);
|
|
271
|
+
console.log(\`Found \${patterns.length} patterns\`);
|
|
272
|
+
// Expected: 1 pattern (only in current session)
|
|
273
|
+
|
|
274
|
+
// Stats
|
|
275
|
+
const stats = await rb.getStats();
|
|
276
|
+
console.log(\`Backend: \${stats.storage_backend}\`);
|
|
277
|
+
// Expected: "wasm-memory"
|
|
278
|
+
EOF
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
---
|
|
282
|
+
|
|
283
|
+
## ⚠️ Important Notes
|
|
284
|
+
|
|
285
|
+
### WASM in Node.js
|
|
286
|
+
|
|
287
|
+
When using WASM in Node.js:
|
|
288
|
+
- Storage is **in-memory only** (not persistent)
|
|
289
|
+
- Data is **lost** when process exits
|
|
290
|
+
- Useful for temporary/ephemeral data
|
|
291
|
+
- **Use Node.js backend instead** for persistent storage
|
|
292
|
+
|
|
293
|
+
### Node.js Flag Requirement
|
|
294
|
+
|
|
295
|
+
When importing WASM in Node.js, you need the experimental flag:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
node --experimental-wasm-modules your-script.mjs
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
This is **not required** for:
|
|
302
|
+
- Node.js backend (SQLite)
|
|
303
|
+
- WASM in browsers
|
|
304
|
+
- Production builds with bundlers (webpack, vite, rollup)
|
|
305
|
+
|
|
306
|
+
---
|
|
307
|
+
|
|
308
|
+
## 🚀 Recommendations
|
|
309
|
+
|
|
310
|
+
### For agentic-flow Package
|
|
311
|
+
|
|
312
|
+
1. **Default to environment-appropriate backend**:
|
|
313
|
+
- Node.js → SQLite backend
|
|
314
|
+
- Browser → WASM backend
|
|
315
|
+
|
|
316
|
+
2. **Document WASM limitations** in Node.js:
|
|
317
|
+
- In-memory only
|
|
318
|
+
- No cross-session persistence
|
|
319
|
+
- Use Node.js backend for CLIs
|
|
320
|
+
|
|
321
|
+
3. **Provide helper function**:
|
|
322
|
+
```typescript
|
|
323
|
+
export function getRecommendedBackend(): 'nodejs' | 'wasm' {
|
|
324
|
+
return typeof window === 'undefined' ? 'nodejs' : 'wasm';
|
|
325
|
+
}
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### For Integration Projects
|
|
329
|
+
|
|
330
|
+
1. **Use Node.js backend** for:
|
|
331
|
+
- CLI tools (like claude-flow)
|
|
332
|
+
- Server applications
|
|
333
|
+
- Long-running processes
|
|
334
|
+
- Persistent memory requirements
|
|
335
|
+
|
|
336
|
+
2. **Use WASM backend** for:
|
|
337
|
+
- Browser applications
|
|
338
|
+
- Client-side AI features
|
|
339
|
+
- Offline-first apps
|
|
340
|
+
- WebAssembly-optimized environments
|
|
341
|
+
|
|
342
|
+
---
|
|
343
|
+
|
|
344
|
+
## 📊 Performance Metrics
|
|
345
|
+
|
|
346
|
+
### Storage Operations
|
|
347
|
+
|
|
348
|
+
| Operation | Node.js | WASM (Browser) | WASM (Node.js) |
|
|
349
|
+
|-----------|---------|----------------|----------------|
|
|
350
|
+
| **Store Pattern** | 2-5ms | 1-3ms | 0.04ms |
|
|
351
|
+
| **Category Search** | 2-3ms | 1-2ms | 0.02ms |
|
|
352
|
+
| **Semantic Search** | 3-5ms | 2-4ms | 0.06ms |
|
|
353
|
+
| **Get Stats** | 1ms | 0.5ms | 0.01ms |
|
|
354
|
+
|
|
355
|
+
### Embedding Generation
|
|
356
|
+
|
|
357
|
+
Both backends generate embeddings at the same speed:
|
|
358
|
+
- **1024-dimensional vectors**
|
|
359
|
+
- **Generated from text** via `VectorEmbedding::from_text()`
|
|
360
|
+
- **Automatically created** on `storePattern()`
|
|
361
|
+
|
|
362
|
+
---
|
|
363
|
+
|
|
364
|
+
## 🔗 Related Documentation
|
|
365
|
+
|
|
366
|
+
- [ReasoningBank Core](https://github.com/ruvnet/agentic-flow/tree/main/agentic-flow/src/reasoningbank)
|
|
367
|
+
- [WASM ESM Fix](./WASM_ESM_FIX.md)
|
|
368
|
+
- [ReasoningBank Investigation](./REASONINGBANK_INVESTIGATION.md)
|
|
369
|
+
- [ReasoningBank Fixes](./REASONINGBANK_FIXES.md)
|
|
370
|
+
|
|
371
|
+
---
|
|
372
|
+
|
|
373
|
+
**Status**: Production Ready ✅
|
|
374
|
+
**Maintained by**: [@ruvnet](https://github.com/ruvnet)
|
|
375
|
+
**Version**: 1.5.12+
|