agentic-flow 1.7.3 → 1.7.5
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 +0 -5
- package/.claude/answer.md +1 -0
- package/.claude/settings.json +19 -20
- package/CHANGELOG.md +0 -117
- package/README.md +17 -81
- package/dist/agentdb/benchmarks/comprehensive-benchmark.js +664 -0
- package/dist/agentdb/benchmarks/frontier-benchmark.js +419 -0
- package/dist/agentdb/benchmarks/reflexion-benchmark.js +370 -0
- package/dist/agentdb/cli/agentdb-cli.js +717 -0
- package/dist/agentdb/controllers/CausalMemoryGraph.js +322 -0
- package/dist/agentdb/controllers/CausalRecall.js +281 -0
- package/dist/agentdb/controllers/EmbeddingService.js +118 -0
- package/dist/agentdb/controllers/ExplainableRecall.js +387 -0
- package/dist/agentdb/controllers/NightlyLearner.js +382 -0
- package/dist/agentdb/controllers/ReflexionMemory.js +239 -0
- package/dist/agentdb/controllers/SkillLibrary.js +276 -0
- package/dist/agentdb/controllers/frontier-index.js +9 -0
- package/dist/agentdb/controllers/index.js +8 -0
- package/dist/agentdb/index.js +32 -0
- package/dist/agentdb/optimizations/BatchOperations.js +198 -0
- package/dist/agentdb/optimizations/QueryOptimizer.js +225 -0
- package/dist/agentdb/optimizations/index.js +7 -0
- package/dist/agentdb/tests/frontier-features.test.js +665 -0
- package/dist/cli-proxy.js +2 -33
- package/dist/index.js +2 -0
- package/dist/mcp/standalone-stdio.js +200 -4
- package/dist/memory/SharedMemoryPool.js +211 -0
- package/dist/memory/index.js +6 -0
- package/dist/reasoningbank/AdvancedMemory.js +239 -0
- package/dist/reasoningbank/HybridBackend.js +305 -0
- package/dist/reasoningbank/index-new.js +87 -0
- package/dist/reasoningbank/index.js +25 -44
- package/dist/utils/agentdb-runtime-patch.js +170 -0
- package/dist/utils/cli.js +0 -22
- package/docs/AGENTDB_TESTING.md +411 -0
- package/docs/v1.7.1-QUICK-START.md +399 -0
- package/package.json +4 -4
- package/scripts/run-validation.sh +165 -0
- package/scripts/test-agentdb.sh +153 -0
- package/.claude/skills/agentdb-memory-patterns/SKILL.md +0 -166
- package/.claude/skills/agentdb-vector-search/SKILL.md +0 -126
- package/.claude/skills/agentic-flow/agentdb-memory-patterns/SKILL.md +0 -166
- package/.claude/skills/agentic-flow/agentdb-vector-search/SKILL.md +0 -126
- package/.claude/skills/agentic-flow/reasoningbank-intelligence/SKILL.md +0 -201
- package/.claude/skills/agentic-flow/swarm-orchestration/SKILL.md +0 -179
- package/.claude/skills/reasoningbank-intelligence/SKILL.md +0 -201
- package/.claude/skills/skill-builder/README.md +0 -308
- package/.claude/skills/skill-builder/SKILL.md +0 -910
- package/.claude/skills/skill-builder/docs/SPECIFICATION.md +0 -358
- package/.claude/skills/skill-builder/resources/schemas/skill-frontmatter.schema.json +0 -41
- package/.claude/skills/skill-builder/resources/templates/full-skill.template +0 -118
- package/.claude/skills/skill-builder/resources/templates/minimal-skill.template +0 -38
- package/.claude/skills/skill-builder/scripts/generate-skill.sh +0 -334
- package/.claude/skills/skill-builder/scripts/validate-skill.sh +0 -198
- package/.claude/skills/swarm-orchestration/SKILL.md +0 -179
- package/docs/AGENTDB_INTEGRATION.md +0 -379
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* ReasoningBank
|
|
2
|
+
* ReasoningBank - Closed-loop memory system for AI agents
|
|
3
|
+
* Based on arXiv:2509.25140 (Google DeepMind)
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Paper: https://arxiv.org/html/2509.25140v1
|
|
7
|
-
*
|
|
8
|
-
* This is the Node.js backend using SQLite for persistent storage.
|
|
9
|
-
* For browser environments, use './wasm-adapter.js' instead.
|
|
10
|
-
* For automatic backend selection, use './backend-selector.js'.
|
|
5
|
+
* @since v1.7.0 - Integrated AgentDB for optimal performance
|
|
11
6
|
*/
|
|
12
|
-
//
|
|
7
|
+
// Apply AgentDB runtime patch before any AgentDB imports
|
|
8
|
+
import '../utils/agentdb-runtime-patch.js';
|
|
9
|
+
// New hybrid backend (recommended for new code)
|
|
10
|
+
export { HybridReasoningBank } from './HybridBackend.js';
|
|
11
|
+
export { AdvancedMemorySystem } from './AdvancedMemory.js';
|
|
12
|
+
// Re-export AgentDB controllers for advanced usage
|
|
13
|
+
export { ReflexionMemory } from 'agentdb/controllers/ReflexionMemory';
|
|
14
|
+
export { SkillLibrary } from 'agentdb/controllers/SkillLibrary';
|
|
15
|
+
export { CausalMemoryGraph } from 'agentdb/controllers/CausalMemoryGraph';
|
|
16
|
+
export { CausalRecall } from 'agentdb/controllers/CausalRecall';
|
|
17
|
+
export { NightlyLearner } from 'agentdb/controllers/NightlyLearner';
|
|
18
|
+
export { EmbeddingService } from 'agentdb/controllers/EmbeddingService';
|
|
19
|
+
// Original ReasoningBank implementations (backwards compatibility)
|
|
13
20
|
export { retrieveMemories, formatMemoriesForPrompt } from './core/retrieve.js';
|
|
14
21
|
export { judgeTrajectory } from './core/judge.js';
|
|
15
22
|
export { distillMemories } from './core/distill.js';
|
|
16
23
|
export { consolidate, shouldConsolidate } from './core/consolidate.js';
|
|
17
24
|
export { mattsParallel, mattsSequential } from './core/matts.js';
|
|
18
|
-
// Utilities
|
|
19
25
|
export { computeEmbedding, clearEmbeddingCache } from './utils/embeddings.js';
|
|
20
26
|
export { mmrSelection, cosineSimilarity } from './utils/mmr.js';
|
|
21
27
|
export { scrubPII, containsPII, scrubMemory } from './utils/pii-scrubber.js';
|
|
22
28
|
export { loadConfig } from './utils/config.js';
|
|
23
|
-
//
|
|
24
|
-
import { loadConfig } from './utils/config.js';
|
|
29
|
+
// Re-export database utilities
|
|
25
30
|
import * as db from './db/queries.js';
|
|
31
|
+
export { db };
|
|
32
|
+
// Original functions (backwards compatibility)
|
|
33
|
+
import { loadConfig } from './utils/config.js';
|
|
26
34
|
import { retrieveMemories } from './core/retrieve.js';
|
|
27
35
|
import { judgeTrajectory } from './core/judge.js';
|
|
28
36
|
import { distillMemories } from './core/distill.js';
|
|
29
|
-
import { shouldConsolidate, consolidate } from './core/consolidate.js';
|
|
30
|
-
// Database
|
|
31
|
-
export { db };
|
|
32
|
-
/**
|
|
33
|
-
* Initialize ReasoningBank
|
|
34
|
-
* Run migrations and check configuration
|
|
35
|
-
*/
|
|
37
|
+
import { shouldConsolidate as shouldCons, consolidate as cons } from './core/consolidate.js';
|
|
36
38
|
export async function initialize() {
|
|
37
39
|
const config = loadConfig();
|
|
38
40
|
console.log('[ReasoningBank] Initializing...');
|
|
@@ -40,7 +42,6 @@ export async function initialize() {
|
|
|
40
42
|
console.log(`[ReasoningBank] Database: ${process.env.CLAUDE_FLOW_DB_PATH || '.swarm/memory.db'}`);
|
|
41
43
|
console.log(`[ReasoningBank] Embeddings: ${config.embeddings.provider}`);
|
|
42
44
|
console.log(`[ReasoningBank] Retrieval k: ${config.retrieve.k}`);
|
|
43
|
-
// Run migrations to create database and tables
|
|
44
45
|
try {
|
|
45
46
|
await db.runMigrations();
|
|
46
47
|
console.log(`[ReasoningBank] Database migrated successfully`);
|
|
@@ -49,7 +50,6 @@ export async function initialize() {
|
|
|
49
50
|
console.error('[ReasoningBank] Migration error:', error);
|
|
50
51
|
throw new Error('ReasoningBank initialization failed: could not run migrations');
|
|
51
52
|
}
|
|
52
|
-
// Check database connection
|
|
53
53
|
try {
|
|
54
54
|
const dbConn = db.getDb();
|
|
55
55
|
const tables = dbConn.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'pattern%'").all();
|
|
@@ -61,48 +61,29 @@ export async function initialize() {
|
|
|
61
61
|
}
|
|
62
62
|
console.log('[ReasoningBank] Initialization complete');
|
|
63
63
|
}
|
|
64
|
-
/**
|
|
65
|
-
* Full task execution with ReasoningBank
|
|
66
|
-
* Combines retrieve → execute → judge → distill → consolidate
|
|
67
|
-
*/
|
|
68
64
|
export async function runTask(options) {
|
|
69
65
|
console.log(`[ReasoningBank] Running task: ${options.taskId}`);
|
|
70
|
-
// 1. Retrieve memories
|
|
71
66
|
const memories = await retrieveMemories(options.query, {
|
|
72
67
|
domain: options.domain,
|
|
73
68
|
agent: options.agentId
|
|
74
69
|
});
|
|
75
70
|
console.log(`[ReasoningBank] Retrieved ${memories.length} memories`);
|
|
76
|
-
// 2. Execute task with memories
|
|
77
71
|
const trajectory = await options.executeFn(memories);
|
|
78
|
-
// 3. Judge trajectory
|
|
79
72
|
const verdict = await judgeTrajectory(trajectory, options.query);
|
|
80
73
|
console.log(`[ReasoningBank] Verdict: ${verdict.label} (${verdict.confidence})`);
|
|
81
|
-
// 4. Distill new memories
|
|
82
74
|
const newMemories = await distillMemories(trajectory, verdict, options.query, {
|
|
83
75
|
taskId: options.taskId,
|
|
84
76
|
agentId: options.agentId,
|
|
85
77
|
domain: options.domain
|
|
86
78
|
});
|
|
87
79
|
console.log(`[ReasoningBank] Distilled ${newMemories.length} new memories`);
|
|
88
|
-
// 5. Consolidate if needed
|
|
89
80
|
let consolidated = false;
|
|
90
|
-
if (
|
|
81
|
+
if (shouldCons()) {
|
|
91
82
|
console.log('[ReasoningBank] Running consolidation...');
|
|
92
|
-
await
|
|
83
|
+
await cons();
|
|
93
84
|
consolidated = true;
|
|
94
85
|
}
|
|
95
|
-
return {
|
|
96
|
-
verdict,
|
|
97
|
-
usedMemories: memories,
|
|
98
|
-
newMemories,
|
|
99
|
-
consolidated
|
|
100
|
-
};
|
|
86
|
+
return { verdict, usedMemories: memories, newMemories, consolidated };
|
|
101
87
|
}
|
|
102
|
-
|
|
103
|
-
// Ultra-fast vector database drop-in replacement
|
|
104
|
-
// 150x-12,500x faster than legacy implementation
|
|
105
|
-
export { createAgentDBAdapter, createDefaultAgentDBAdapter, migrateToAgentDB, validateMigration } from './agentdb-adapter.js';
|
|
106
|
-
// Version info
|
|
107
|
-
export const VERSION = '1.0.0';
|
|
88
|
+
export const VERSION = '1.7.1';
|
|
108
89
|
export const PAPER_URL = 'https://arxiv.org/html/2509.25140v1';
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentDB Runtime Patch
|
|
3
|
+
*
|
|
4
|
+
* Automatically fixes AgentDB v1.3.9 import resolution issues at runtime.
|
|
5
|
+
* This patch works in all contexts: npm install, npm install -g, and npx.
|
|
6
|
+
*
|
|
7
|
+
* Issue: agentdb v1.3.9 missing .js extensions in ESM exports
|
|
8
|
+
* Solution: Patch the controller index.js file at runtime before first import
|
|
9
|
+
*/
|
|
10
|
+
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
|
11
|
+
import { join, dirname } from 'path';
|
|
12
|
+
import { fileURLToPath } from 'url';
|
|
13
|
+
let patched = false;
|
|
14
|
+
let patchAttempted = false;
|
|
15
|
+
/**
|
|
16
|
+
* Apply AgentDB import fix at runtime
|
|
17
|
+
* Safe to call multiple times - only patches once
|
|
18
|
+
*/
|
|
19
|
+
export function applyAgentDBPatch() {
|
|
20
|
+
// Only attempt once per process
|
|
21
|
+
if (patchAttempted) {
|
|
22
|
+
return patched;
|
|
23
|
+
}
|
|
24
|
+
patchAttempted = true;
|
|
25
|
+
try {
|
|
26
|
+
// Find agentdb installation
|
|
27
|
+
const agentdbPath = findAgentDBPath();
|
|
28
|
+
if (!agentdbPath) {
|
|
29
|
+
console.warn('[AgentDB Patch] Could not locate agentdb installation');
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const controllerIndexPath = join(agentdbPath, 'dist', 'controllers', 'index.js');
|
|
33
|
+
if (!existsSync(controllerIndexPath)) {
|
|
34
|
+
console.warn(`[AgentDB Patch] Controller index not found: ${controllerIndexPath}`);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
// Read current content
|
|
38
|
+
let content = readFileSync(controllerIndexPath, 'utf8');
|
|
39
|
+
// Check if already patched
|
|
40
|
+
if (content.includes("from './ReflexionMemory.js'")) {
|
|
41
|
+
patched = true;
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
// Apply patches
|
|
45
|
+
const patches = [
|
|
46
|
+
{ from: "from './ReflexionMemory'", to: "from './ReflexionMemory.js'" },
|
|
47
|
+
{ from: "from './SkillLibrary'", to: "from './SkillLibrary.js'" },
|
|
48
|
+
{ from: "from './EmbeddingService'", to: "from './EmbeddingService.js'" },
|
|
49
|
+
{ from: "from './CausalMemoryGraph'", to: "from './CausalMemoryGraph.js'" },
|
|
50
|
+
{ from: "from './CausalRecall'", to: "from './CausalRecall.js'" },
|
|
51
|
+
{ from: "from './NightlyLearner'", to: "from './NightlyLearner.js'" }
|
|
52
|
+
];
|
|
53
|
+
let modified = false;
|
|
54
|
+
for (const patch of patches) {
|
|
55
|
+
if (content.includes(patch.from) && !content.includes(patch.to)) {
|
|
56
|
+
content = content.replace(new RegExp(patch.from, 'g'), patch.to);
|
|
57
|
+
modified = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (modified) {
|
|
61
|
+
try {
|
|
62
|
+
writeFileSync(controllerIndexPath, content, 'utf8');
|
|
63
|
+
patched = true;
|
|
64
|
+
console.log('[AgentDB Patch] ✅ Successfully patched AgentDB imports');
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
catch (writeError) {
|
|
68
|
+
// If we can't write (npx temp dir permissions), that's OK - imports will fail gracefully
|
|
69
|
+
console.warn('[AgentDB Patch] ⚠️ Could not write patch (read-only):', writeError.message);
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.warn('[AgentDB Patch] Error applying patch:', error.message);
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Find AgentDB installation directory
|
|
82
|
+
* Checks multiple possible locations
|
|
83
|
+
*/
|
|
84
|
+
function findAgentDBPath() {
|
|
85
|
+
const possiblePaths = [
|
|
86
|
+
// Local node_modules (most common)
|
|
87
|
+
join(process.cwd(), 'node_modules', 'agentdb'),
|
|
88
|
+
// Parent directory node_modules (monorepo)
|
|
89
|
+
join(process.cwd(), '..', 'node_modules', 'agentdb'),
|
|
90
|
+
// Global npm installation
|
|
91
|
+
join(process.execPath, '..', '..', 'lib', 'node_modules', 'agentdb'),
|
|
92
|
+
// Relative to this file (for bundled installations)
|
|
93
|
+
...(typeof __dirname !== 'undefined'
|
|
94
|
+
? [
|
|
95
|
+
join(__dirname, '..', '..', 'node_modules', 'agentdb'),
|
|
96
|
+
join(__dirname, '..', '..', '..', 'agentdb')
|
|
97
|
+
]
|
|
98
|
+
: []),
|
|
99
|
+
// Using import.meta.url (ESM)
|
|
100
|
+
...(typeof import.meta !== 'undefined' && import.meta.url
|
|
101
|
+
? (() => {
|
|
102
|
+
try {
|
|
103
|
+
const currentDir = dirname(fileURLToPath(import.meta.url));
|
|
104
|
+
return [
|
|
105
|
+
join(currentDir, '..', '..', 'node_modules', 'agentdb'),
|
|
106
|
+
join(currentDir, '..', '..', '..', 'agentdb')
|
|
107
|
+
];
|
|
108
|
+
}
|
|
109
|
+
catch {
|
|
110
|
+
return [];
|
|
111
|
+
}
|
|
112
|
+
})()
|
|
113
|
+
: [])
|
|
114
|
+
];
|
|
115
|
+
// Try each path
|
|
116
|
+
for (const path of possiblePaths) {
|
|
117
|
+
if (existsSync(join(path, 'package.json'))) {
|
|
118
|
+
try {
|
|
119
|
+
const pkg = JSON.parse(readFileSync(join(path, 'package.json'), 'utf8'));
|
|
120
|
+
if (pkg.name === 'agentdb') {
|
|
121
|
+
return path;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// Try require.resolve as fallback
|
|
130
|
+
try {
|
|
131
|
+
const resolved = require.resolve('agentdb/package.json');
|
|
132
|
+
return dirname(resolved);
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
// Not found via require.resolve
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Check if AgentDB patch is needed
|
|
141
|
+
*/
|
|
142
|
+
export function isAgentDBPatchNeeded() {
|
|
143
|
+
const agentdbPath = findAgentDBPath();
|
|
144
|
+
if (!agentdbPath)
|
|
145
|
+
return false;
|
|
146
|
+
const controllerIndexPath = join(agentdbPath, 'dist', 'controllers', 'index.js');
|
|
147
|
+
if (!existsSync(controllerIndexPath))
|
|
148
|
+
return false;
|
|
149
|
+
const content = readFileSync(controllerIndexPath, 'utf8');
|
|
150
|
+
return !content.includes("from './ReflexionMemory.js'");
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Get patch status information
|
|
154
|
+
*/
|
|
155
|
+
export function getAgentDBPatchStatus() {
|
|
156
|
+
return {
|
|
157
|
+
needed: isAgentDBPatchNeeded(),
|
|
158
|
+
applied: patched,
|
|
159
|
+
attempted: patchAttempted,
|
|
160
|
+
location: findAgentDBPath()
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
// Auto-apply patch on module load (non-blocking)
|
|
164
|
+
// This ensures the patch is applied before any imports
|
|
165
|
+
if (typeof process !== 'undefined' && !process.env.SKIP_AGENTDB_PATCH) {
|
|
166
|
+
// Run asynchronously to not block module loading
|
|
167
|
+
setImmediate(() => {
|
|
168
|
+
applyAgentDBPatch();
|
|
169
|
+
});
|
|
170
|
+
}
|
package/dist/utils/cli.js
CHANGED
|
@@ -49,16 +49,6 @@ export function parseArgs() {
|
|
|
49
49
|
options.mode = 'reasoningbank';
|
|
50
50
|
return options;
|
|
51
51
|
}
|
|
52
|
-
// Check for agentdb command
|
|
53
|
-
if (args[0] === 'agentdb') {
|
|
54
|
-
options.mode = 'agentdb';
|
|
55
|
-
return options;
|
|
56
|
-
}
|
|
57
|
-
// Check for skills command
|
|
58
|
-
if (args[0] === 'skills') {
|
|
59
|
-
options.mode = 'skills';
|
|
60
|
-
return options;
|
|
61
|
-
}
|
|
62
52
|
for (let i = 0; i < args.length; i++) {
|
|
63
53
|
const arg = args[i];
|
|
64
54
|
switch (arg) {
|
|
@@ -165,7 +155,6 @@ USAGE:
|
|
|
165
155
|
npx agentic-flow [COMMAND] [OPTIONS]
|
|
166
156
|
|
|
167
157
|
COMMANDS:
|
|
168
|
-
skills <command> Claude Code Skills management (init, create, list)
|
|
169
158
|
reasoningbank <cmd> Memory system that learns from experience (demo, test, init)
|
|
170
159
|
claude-code [options] Spawn Claude Code with proxy + Agent Booster (57x faster edits)
|
|
171
160
|
mcp <command> [server] Manage MCP servers (start, stop, status, list)
|
|
@@ -182,12 +171,6 @@ REASONINGBANK COMMANDS:
|
|
|
182
171
|
npx agentic-flow reasoningbank benchmark Run performance benchmarks
|
|
183
172
|
npx agentic-flow reasoningbank status Show memory statistics
|
|
184
173
|
|
|
185
|
-
SKILLS COMMANDS:
|
|
186
|
-
npx agentic-flow skills init [location] Initialize skills directories (personal/project/both)
|
|
187
|
-
npx agentic-flow skills create Create example agentic-flow skills
|
|
188
|
-
npx agentic-flow skills list List all installed skills
|
|
189
|
-
npx agentic-flow skills help Show skills help
|
|
190
|
-
|
|
191
174
|
MCP COMMANDS:
|
|
192
175
|
npx agentic-flow mcp start [server] Start MCP server(s)
|
|
193
176
|
npx agentic-flow mcp stop [server] Stop MCP server(s)
|
|
@@ -233,11 +216,6 @@ OPTIONS:
|
|
|
233
216
|
--help, -h Show this help message
|
|
234
217
|
|
|
235
218
|
EXAMPLES:
|
|
236
|
-
# Skills (Claude Code integration!)
|
|
237
|
-
npx agentic-flow skills init # Initialize skills directories
|
|
238
|
-
npx agentic-flow skills create # Create agentdb-quickstart skill
|
|
239
|
-
npx agentic-flow skills list # List all installed skills
|
|
240
|
-
|
|
241
219
|
# ReasoningBank (Learn from agent experience!)
|
|
242
220
|
npx agentic-flow reasoningbank demo # See 0% → 100% success transformation
|
|
243
221
|
npx agentic-flow reasoningbank test # Run 27 validation tests
|