@sparkleideas/neural 3.0.0-alpha.10 → 3.0.0-alpha.20
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/package.json +1 -1
- package/src/reasoning-bank.d.ts +1 -1
- package/src/reasoning-bank.js +18 -18
- package/src/reasoning-bank.ts +18 -18
- package/src/reasoningbank-adapter.ts +3 -3
package/package.json
CHANGED
package/src/reasoning-bank.d.ts
CHANGED
package/src/reasoning-bank.js
CHANGED
|
@@ -23,7 +23,7 @@ async function ensureAgentDBImport() {
|
|
|
23
23
|
if (!agentdbImportPromise) {
|
|
24
24
|
agentdbImportPromise = (async () => {
|
|
25
25
|
try {
|
|
26
|
-
const agentdbModule = await import('
|
|
26
|
+
const agentdbModule = await import('agentdb');
|
|
27
27
|
AgentDB = agentdbModule.AgentDB || agentdbModule.default;
|
|
28
28
|
}
|
|
29
29
|
catch {
|
|
@@ -69,7 +69,7 @@ export class ReasoningBank {
|
|
|
69
69
|
patterns = new Map();
|
|
70
70
|
eventListeners = new Set();
|
|
71
71
|
// AgentDB instance for vector storage
|
|
72
|
-
|
|
72
|
+
agentdb = null;
|
|
73
73
|
agentdbAvailable = false;
|
|
74
74
|
initialized = false;
|
|
75
75
|
// Performance tracking
|
|
@@ -98,13 +98,13 @@ export class ReasoningBank {
|
|
|
98
98
|
this.agentdbAvailable = AgentDB !== undefined;
|
|
99
99
|
if (this.agentdbAvailable) {
|
|
100
100
|
try {
|
|
101
|
-
this
|
|
101
|
+
this.agentdb = new AgentDB({
|
|
102
102
|
dbPath: this.config.dbPath || ':memory:',
|
|
103
103
|
namespace: this.config.namespace,
|
|
104
104
|
vectorDimension: this.config.vectorDimension,
|
|
105
105
|
vectorBackend: 'auto',
|
|
106
106
|
});
|
|
107
|
-
await this
|
|
107
|
+
await this.agentdb.initialize();
|
|
108
108
|
this.emitEvent({ type: 'memory_consolidated', memoriesCount: 0 });
|
|
109
109
|
}
|
|
110
110
|
catch (error) {
|
|
@@ -119,8 +119,8 @@ export class ReasoningBank {
|
|
|
119
119
|
* Shutdown and cleanup resources
|
|
120
120
|
*/
|
|
121
121
|
async shutdown() {
|
|
122
|
-
if (this
|
|
123
|
-
await this
|
|
122
|
+
if (this.agentdb) {
|
|
123
|
+
await this.agentdb.close?.();
|
|
124
124
|
}
|
|
125
125
|
this.initialized = false;
|
|
126
126
|
}
|
|
@@ -144,7 +144,7 @@ export class ReasoningBank {
|
|
|
144
144
|
}
|
|
145
145
|
let candidates = [];
|
|
146
146
|
// Try AgentDB HNSW search first
|
|
147
|
-
if (this
|
|
147
|
+
if (this.agentdb && this.agentdbAvailable) {
|
|
148
148
|
try {
|
|
149
149
|
const results = await this.searchWithAgentDB(queryEmbedding, retrieveK * 3);
|
|
150
150
|
candidates = results
|
|
@@ -327,7 +327,7 @@ export class ReasoningBank {
|
|
|
327
327
|
};
|
|
328
328
|
this.memories.set(memory.memoryId, entry);
|
|
329
329
|
// Store in AgentDB for vector search
|
|
330
|
-
if (this
|
|
330
|
+
if (this.agentdb && this.agentdbAvailable) {
|
|
331
331
|
await this.storeInAgentDB(memory);
|
|
332
332
|
}
|
|
333
333
|
// Also store trajectory reference
|
|
@@ -621,11 +621,11 @@ export class ReasoningBank {
|
|
|
621
621
|
* Store memory in AgentDB for vector search
|
|
622
622
|
*/
|
|
623
623
|
async storeInAgentDB(memory) {
|
|
624
|
-
if (!this
|
|
624
|
+
if (!this.agentdb)
|
|
625
625
|
return;
|
|
626
626
|
try {
|
|
627
|
-
if (typeof this
|
|
628
|
-
await this
|
|
627
|
+
if (typeof this.agentdb.store === 'function') {
|
|
628
|
+
await this.agentdb.store(memory.memoryId, {
|
|
629
629
|
content: memory.strategy,
|
|
630
630
|
embedding: memory.embedding,
|
|
631
631
|
metadata: {
|
|
@@ -646,14 +646,14 @@ export class ReasoningBank {
|
|
|
646
646
|
* Search using AgentDB HNSW index
|
|
647
647
|
*/
|
|
648
648
|
async searchWithAgentDB(queryEmbedding, k) {
|
|
649
|
-
if (!this
|
|
649
|
+
if (!this.agentdb)
|
|
650
650
|
return [];
|
|
651
651
|
try {
|
|
652
|
-
if (typeof this
|
|
653
|
-
return await this
|
|
652
|
+
if (typeof this.agentdb.search === 'function') {
|
|
653
|
+
return await this.agentdb.search(queryEmbedding, k);
|
|
654
654
|
}
|
|
655
655
|
// Try HNSW controller if available
|
|
656
|
-
const hnsw = this
|
|
656
|
+
const hnsw = this.agentdb.getController?.('hnsw');
|
|
657
657
|
if (hnsw) {
|
|
658
658
|
const results = await hnsw.search(queryEmbedding, k);
|
|
659
659
|
return results.map((r) => ({
|
|
@@ -671,11 +671,11 @@ export class ReasoningBank {
|
|
|
671
671
|
* Delete from AgentDB
|
|
672
672
|
*/
|
|
673
673
|
async deleteFromAgentDB(memoryId) {
|
|
674
|
-
if (!this
|
|
674
|
+
if (!this.agentdb)
|
|
675
675
|
return;
|
|
676
676
|
try {
|
|
677
|
-
if (typeof this
|
|
678
|
-
await this
|
|
677
|
+
if (typeof this.agentdb.delete === 'function') {
|
|
678
|
+
await this.agentdb.delete(memoryId);
|
|
679
679
|
}
|
|
680
680
|
}
|
|
681
681
|
catch {
|
package/src/reasoning-bank.ts
CHANGED
|
@@ -37,7 +37,7 @@ async function ensureAgentDBImport(): Promise<void> {
|
|
|
37
37
|
if (!agentdbImportPromise) {
|
|
38
38
|
agentdbImportPromise = (async () => {
|
|
39
39
|
try {
|
|
40
|
-
const agentdbModule = await import('
|
|
40
|
+
const agentdbModule = await import('agentdb');
|
|
41
41
|
AgentDB = agentdbModule.AgentDB || agentdbModule.default;
|
|
42
42
|
} catch {
|
|
43
43
|
// AgentDB not available - will use fallback
|
|
@@ -172,7 +172,7 @@ export class ReasoningBank {
|
|
|
172
172
|
private eventListeners: Set<NeuralEventListener> = new Set();
|
|
173
173
|
|
|
174
174
|
// AgentDB instance for vector storage
|
|
175
|
-
private
|
|
175
|
+
private agentdb: any = null;
|
|
176
176
|
private agentdbAvailable: boolean = false;
|
|
177
177
|
private initialized: boolean = false;
|
|
178
178
|
|
|
@@ -206,14 +206,14 @@ export class ReasoningBank {
|
|
|
206
206
|
|
|
207
207
|
if (this.agentdbAvailable) {
|
|
208
208
|
try {
|
|
209
|
-
this
|
|
209
|
+
this.agentdb = new AgentDB({
|
|
210
210
|
dbPath: this.config.dbPath || ':memory:',
|
|
211
211
|
namespace: this.config.namespace,
|
|
212
212
|
vectorDimension: this.config.vectorDimension,
|
|
213
213
|
vectorBackend: 'auto',
|
|
214
214
|
});
|
|
215
215
|
|
|
216
|
-
await this
|
|
216
|
+
await this.agentdb.initialize();
|
|
217
217
|
this.emitEvent({ type: 'memory_consolidated', memoriesCount: 0 });
|
|
218
218
|
} catch (error) {
|
|
219
219
|
console.warn('AgentDB initialization failed, using fallback:', error);
|
|
@@ -229,8 +229,8 @@ export class ReasoningBank {
|
|
|
229
229
|
* Shutdown and cleanup resources
|
|
230
230
|
*/
|
|
231
231
|
async shutdown(): Promise<void> {
|
|
232
|
-
if (this
|
|
233
|
-
await this
|
|
232
|
+
if (this.agentdb) {
|
|
233
|
+
await this.agentdb.close?.();
|
|
234
234
|
}
|
|
235
235
|
this.initialized = false;
|
|
236
236
|
}
|
|
@@ -259,7 +259,7 @@ export class ReasoningBank {
|
|
|
259
259
|
let candidates: Array<{ entry: MemoryEntry; relevance: number }> = [];
|
|
260
260
|
|
|
261
261
|
// Try AgentDB HNSW search first
|
|
262
|
-
if (this
|
|
262
|
+
if (this.agentdb && this.agentdbAvailable) {
|
|
263
263
|
try {
|
|
264
264
|
const results = await this.searchWithAgentDB(queryEmbedding, retrieveK * 3);
|
|
265
265
|
candidates = results
|
|
@@ -484,7 +484,7 @@ export class ReasoningBank {
|
|
|
484
484
|
this.memories.set(memory.memoryId, entry);
|
|
485
485
|
|
|
486
486
|
// Store in AgentDB for vector search
|
|
487
|
-
if (this
|
|
487
|
+
if (this.agentdb && this.agentdbAvailable) {
|
|
488
488
|
await this.storeInAgentDB(memory);
|
|
489
489
|
}
|
|
490
490
|
|
|
@@ -830,11 +830,11 @@ export class ReasoningBank {
|
|
|
830
830
|
* Store memory in AgentDB for vector search
|
|
831
831
|
*/
|
|
832
832
|
private async storeInAgentDB(memory: DistilledMemory): Promise<void> {
|
|
833
|
-
if (!this
|
|
833
|
+
if (!this.agentdb) return;
|
|
834
834
|
|
|
835
835
|
try {
|
|
836
|
-
if (typeof this
|
|
837
|
-
await this
|
|
836
|
+
if (typeof this.agentdb.store === 'function') {
|
|
837
|
+
await this.agentdb.store(memory.memoryId, {
|
|
838
838
|
content: memory.strategy,
|
|
839
839
|
embedding: memory.embedding,
|
|
840
840
|
metadata: {
|
|
@@ -858,15 +858,15 @@ export class ReasoningBank {
|
|
|
858
858
|
queryEmbedding: Float32Array,
|
|
859
859
|
k: number
|
|
860
860
|
): Promise<Array<{ id: string; similarity: number }>> {
|
|
861
|
-
if (!this
|
|
861
|
+
if (!this.agentdb) return [];
|
|
862
862
|
|
|
863
863
|
try {
|
|
864
|
-
if (typeof this
|
|
865
|
-
return await this
|
|
864
|
+
if (typeof this.agentdb.search === 'function') {
|
|
865
|
+
return await this.agentdb.search(queryEmbedding, k);
|
|
866
866
|
}
|
|
867
867
|
|
|
868
868
|
// Try HNSW controller if available
|
|
869
|
-
const hnsw = this
|
|
869
|
+
const hnsw = this.agentdb.getController?.('hnsw');
|
|
870
870
|
if (hnsw) {
|
|
871
871
|
const results = await hnsw.search(queryEmbedding, k);
|
|
872
872
|
return results.map((r: any) => ({
|
|
@@ -885,11 +885,11 @@ export class ReasoningBank {
|
|
|
885
885
|
* Delete from AgentDB
|
|
886
886
|
*/
|
|
887
887
|
private async deleteFromAgentDB(memoryId: string): Promise<void> {
|
|
888
|
-
if (!this
|
|
888
|
+
if (!this.agentdb) return;
|
|
889
889
|
|
|
890
890
|
try {
|
|
891
|
-
if (typeof this
|
|
892
|
-
await this
|
|
891
|
+
if (typeof this.agentdb.delete === 'function') {
|
|
892
|
+
await this.agentdb.delete(memoryId);
|
|
893
893
|
}
|
|
894
894
|
} catch {
|
|
895
895
|
// Ignore deletion errors
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* V3 ReasoningBank Adapter
|
|
3
3
|
*
|
|
4
|
-
* Provides
|
|
4
|
+
* Provides agentic-flow@alpha compatible ReasoningBank interface:
|
|
5
5
|
* - 4-step pipeline: RETRIEVE, JUDGE, DISTILL, CONSOLIDATE
|
|
6
6
|
* - Trajectory tracking and verdict judgment
|
|
7
7
|
* - Memory distillation from successful trajectories
|
|
@@ -27,7 +27,7 @@ import { createSONAManager, SONAManager } from './sona-manager.js';
|
|
|
27
27
|
import { createPatternLearner, PatternLearner } from './pattern-learner.js';
|
|
28
28
|
|
|
29
29
|
// ============================================================================
|
|
30
|
-
// ReasoningBank Types (
|
|
30
|
+
// ReasoningBank Types (agentic-flow compatible)
|
|
31
31
|
// ============================================================================
|
|
32
32
|
|
|
33
33
|
/**
|
|
@@ -139,7 +139,7 @@ export class ReasoningBankAdapter {
|
|
|
139
139
|
|
|
140
140
|
constructor(config?: ReasoningBankConfig) {
|
|
141
141
|
this.config = {
|
|
142
|
-
dbPath: config?.dbPath || '
|
|
142
|
+
dbPath: config?.dbPath || '.agentdb/reasoningbank.db',
|
|
143
143
|
enableLearning: config?.enableLearning ?? true,
|
|
144
144
|
enableReasoning: config?.enableReasoning ?? true,
|
|
145
145
|
sonaMode: config?.sonaMode || 'balanced',
|