agentic-flow 1.4.8 → 1.4.10
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.
|
@@ -3,14 +3,112 @@
|
|
|
3
3
|
* Operates on Claude Flow's memory.db at .swarm/memory.db
|
|
4
4
|
*/
|
|
5
5
|
import BetterSqlite3 from 'better-sqlite3';
|
|
6
|
-
import { existsSync } from 'fs';
|
|
7
|
-
import { join } from 'path';
|
|
6
|
+
import { existsSync, mkdirSync } from 'fs';
|
|
7
|
+
import { join, dirname } from 'path';
|
|
8
8
|
// Simple logger for database operations
|
|
9
9
|
const logger = {
|
|
10
10
|
info: (msg, data) => console.log(`[INFO] ${msg}`, data || ''),
|
|
11
11
|
error: (msg, data) => console.error(`[ERROR] ${msg}`, data || '')
|
|
12
12
|
};
|
|
13
13
|
let dbInstance = null;
|
|
14
|
+
/**
|
|
15
|
+
* Run database migrations (create tables)
|
|
16
|
+
*/
|
|
17
|
+
export async function runMigrations() {
|
|
18
|
+
const dbPath = process.env.CLAUDE_FLOW_DB_PATH || join(process.cwd(), '.swarm', 'memory.db');
|
|
19
|
+
// Create directory if it doesn't exist
|
|
20
|
+
const dbDir = dirname(dbPath);
|
|
21
|
+
if (!existsSync(dbDir)) {
|
|
22
|
+
mkdirSync(dbDir, { recursive: true });
|
|
23
|
+
logger.info('Created database directory', { path: dbDir });
|
|
24
|
+
}
|
|
25
|
+
// Create database file
|
|
26
|
+
const db = new BetterSqlite3(dbPath);
|
|
27
|
+
db.pragma('journal_mode = WAL');
|
|
28
|
+
db.pragma('foreign_keys = ON');
|
|
29
|
+
// Create tables
|
|
30
|
+
db.exec(`
|
|
31
|
+
CREATE TABLE IF NOT EXISTS patterns (
|
|
32
|
+
id TEXT PRIMARY KEY,
|
|
33
|
+
type TEXT NOT NULL,
|
|
34
|
+
pattern_data TEXT NOT NULL,
|
|
35
|
+
confidence REAL NOT NULL DEFAULT 0.5,
|
|
36
|
+
usage_count INTEGER NOT NULL DEFAULT 0,
|
|
37
|
+
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
38
|
+
last_used TEXT
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
CREATE TABLE IF NOT EXISTS pattern_embeddings (
|
|
42
|
+
id TEXT PRIMARY KEY,
|
|
43
|
+
model TEXT NOT NULL,
|
|
44
|
+
dims INTEGER NOT NULL,
|
|
45
|
+
vector BLOB NOT NULL,
|
|
46
|
+
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
47
|
+
FOREIGN KEY (id) REFERENCES patterns(id) ON DELETE CASCADE
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
CREATE TABLE IF NOT EXISTS pattern_links (
|
|
51
|
+
src_id TEXT NOT NULL,
|
|
52
|
+
dst_id TEXT NOT NULL,
|
|
53
|
+
relation TEXT NOT NULL,
|
|
54
|
+
weight REAL NOT NULL DEFAULT 1.0,
|
|
55
|
+
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
56
|
+
PRIMARY KEY (src_id, dst_id, relation),
|
|
57
|
+
FOREIGN KEY (src_id) REFERENCES patterns(id) ON DELETE CASCADE,
|
|
58
|
+
FOREIGN KEY (dst_id) REFERENCES patterns(id) ON DELETE CASCADE
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
CREATE TABLE IF NOT EXISTS task_trajectories (
|
|
62
|
+
task_id TEXT PRIMARY KEY,
|
|
63
|
+
agent_id TEXT NOT NULL,
|
|
64
|
+
query TEXT NOT NULL,
|
|
65
|
+
trajectory_json TEXT NOT NULL,
|
|
66
|
+
started_at TEXT,
|
|
67
|
+
ended_at TEXT,
|
|
68
|
+
judge_label TEXT,
|
|
69
|
+
judge_conf REAL,
|
|
70
|
+
judge_reasons TEXT,
|
|
71
|
+
matts_run_id TEXT,
|
|
72
|
+
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
CREATE TABLE IF NOT EXISTS matts_runs (
|
|
76
|
+
run_id TEXT PRIMARY KEY,
|
|
77
|
+
task_id TEXT NOT NULL,
|
|
78
|
+
mode TEXT NOT NULL,
|
|
79
|
+
k INTEGER NOT NULL,
|
|
80
|
+
status TEXT NOT NULL,
|
|
81
|
+
summary TEXT,
|
|
82
|
+
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
CREATE TABLE IF NOT EXISTS consolidation_runs (
|
|
86
|
+
run_id TEXT PRIMARY KEY,
|
|
87
|
+
items_processed INTEGER NOT NULL,
|
|
88
|
+
duplicates_found INTEGER NOT NULL,
|
|
89
|
+
contradictions_found INTEGER NOT NULL,
|
|
90
|
+
items_pruned INTEGER NOT NULL,
|
|
91
|
+
duration_ms INTEGER NOT NULL,
|
|
92
|
+
created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
CREATE TABLE IF NOT EXISTS metrics_log (
|
|
96
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
97
|
+
metric_name TEXT NOT NULL,
|
|
98
|
+
value REAL NOT NULL,
|
|
99
|
+
timestamp TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
CREATE INDEX IF NOT EXISTS idx_patterns_type ON patterns(type);
|
|
103
|
+
CREATE INDEX IF NOT EXISTS idx_patterns_confidence ON patterns(confidence DESC);
|
|
104
|
+
CREATE INDEX IF NOT EXISTS idx_patterns_created_at ON patterns(created_at DESC);
|
|
105
|
+
CREATE INDEX IF NOT EXISTS idx_pattern_links_relation ON pattern_links(relation);
|
|
106
|
+
CREATE INDEX IF NOT EXISTS idx_trajectories_agent ON task_trajectories(agent_id);
|
|
107
|
+
`);
|
|
108
|
+
db.close();
|
|
109
|
+
dbInstance = null; // Reset instance to force reconnection
|
|
110
|
+
logger.info('Database migrations completed', { path: dbPath });
|
|
111
|
+
}
|
|
14
112
|
/**
|
|
15
113
|
* Get database connection (singleton)
|
|
16
114
|
*/
|
|
@@ -36,6 +36,15 @@ export async function initialize() {
|
|
|
36
36
|
console.log(`[ReasoningBank] Database: ${process.env.CLAUDE_FLOW_DB_PATH || '.swarm/memory.db'}`);
|
|
37
37
|
console.log(`[ReasoningBank] Embeddings: ${config.embeddings.provider}`);
|
|
38
38
|
console.log(`[ReasoningBank] Retrieval k: ${config.retrieve.k}`);
|
|
39
|
+
// Run migrations to create database and tables
|
|
40
|
+
try {
|
|
41
|
+
await db.runMigrations();
|
|
42
|
+
console.log(`[ReasoningBank] Database migrated successfully`);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error('[ReasoningBank] Migration error:', error);
|
|
46
|
+
throw new Error('ReasoningBank initialization failed: could not run migrations');
|
|
47
|
+
}
|
|
39
48
|
// Check database connection
|
|
40
49
|
try {
|
|
41
50
|
const dbConn = db.getDb();
|
|
@@ -1,75 +1,168 @@
|
|
|
1
1
|
import { parse } from 'yaml';
|
|
2
|
-
import { readFileSync } from 'fs';
|
|
3
|
-
import { join } from 'path';
|
|
2
|
+
import { readFileSync, existsSync } from 'fs';
|
|
3
|
+
import { join, dirname } from 'path';
|
|
4
|
+
import { fileURLToPath } from 'url';
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
4
7
|
let configCache = null;
|
|
5
|
-
|
|
8
|
+
// Default configuration
|
|
9
|
+
const DEFAULT_CONFIG = {
|
|
10
|
+
retrieve: {
|
|
11
|
+
k: 3,
|
|
12
|
+
alpha: 0.65,
|
|
13
|
+
beta: 0.15,
|
|
14
|
+
gamma: 0.20,
|
|
15
|
+
delta: 0.10,
|
|
16
|
+
recency_half_life_days: 45,
|
|
17
|
+
min_score: 0.3
|
|
18
|
+
},
|
|
19
|
+
judge: {
|
|
20
|
+
model: 'claude-sonnet-4-5-20250929',
|
|
21
|
+
max_tokens: 512,
|
|
22
|
+
temperature: 0,
|
|
23
|
+
confidence_threshold: 0.5
|
|
24
|
+
},
|
|
25
|
+
distill: {
|
|
26
|
+
model: undefined,
|
|
27
|
+
max_tokens: undefined,
|
|
28
|
+
temperature: undefined,
|
|
29
|
+
max_items_success: 3,
|
|
30
|
+
max_items_failure: 2,
|
|
31
|
+
confidence_prior_success: 0.75,
|
|
32
|
+
confidence_prior_failure: 0.60
|
|
33
|
+
},
|
|
34
|
+
consolidate: {
|
|
35
|
+
duplicate_threshold: 0.95,
|
|
36
|
+
contradiction_threshold: 0.85,
|
|
37
|
+
trigger_threshold: 20,
|
|
38
|
+
prune_age_days: 180,
|
|
39
|
+
prune_min_confidence: 0.3,
|
|
40
|
+
min_confidence_keep: 0.5
|
|
41
|
+
},
|
|
42
|
+
matts: {
|
|
43
|
+
parallel_k: 3,
|
|
44
|
+
sequential_k: 5,
|
|
45
|
+
sequential_r: 5,
|
|
46
|
+
sequential_stop_on_success: true,
|
|
47
|
+
confidence_boost: 0.05
|
|
48
|
+
},
|
|
49
|
+
embeddings: {
|
|
50
|
+
provider: 'claude',
|
|
51
|
+
model: 'claude-3-5-sonnet-20241022',
|
|
52
|
+
dims: 1024,
|
|
53
|
+
dimensions: 1024,
|
|
54
|
+
cache_ttl_seconds: 3600
|
|
55
|
+
},
|
|
56
|
+
governance: {
|
|
57
|
+
scrub_pii: true,
|
|
58
|
+
pii_scrubber: true,
|
|
59
|
+
tenant_scoped: false
|
|
60
|
+
},
|
|
61
|
+
features: {
|
|
62
|
+
enable_pre_task_hook: true,
|
|
63
|
+
enable_post_task_hook: true,
|
|
64
|
+
enable_matts_parallel: true
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
// Try multiple paths to find config file
|
|
68
|
+
function findConfigPath() {
|
|
69
|
+
const paths = [
|
|
70
|
+
// Development: relative to source file
|
|
71
|
+
join(__dirname, '../config/reasoningbank.yaml'),
|
|
72
|
+
// npm package: relative to dist file
|
|
73
|
+
join(__dirname, '../../config/reasoningbank.yaml'),
|
|
74
|
+
// User override: current working directory
|
|
75
|
+
join(process.cwd(), '.swarm/reasoningbank.yaml'),
|
|
76
|
+
join(process.cwd(), 'reasoningbank.yaml')
|
|
77
|
+
];
|
|
78
|
+
for (const path of paths) {
|
|
79
|
+
if (existsSync(path)) {
|
|
80
|
+
return path;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
6
85
|
export function loadConfig() {
|
|
7
86
|
if (configCache)
|
|
8
87
|
return configCache;
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
88
|
+
const configPath = findConfigPath();
|
|
89
|
+
// If no config file found, use defaults
|
|
90
|
+
if (!configPath) {
|
|
91
|
+
configCache = DEFAULT_CONFIG;
|
|
92
|
+
return configCache;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const yamlContent = readFileSync(configPath, 'utf-8');
|
|
96
|
+
const parsed = parse(yamlContent);
|
|
97
|
+
// Handle nested reasoningbank: key
|
|
98
|
+
const raw = parsed.reasoningbank || parsed;
|
|
99
|
+
// Map the full config to our simplified interface
|
|
100
|
+
configCache = {
|
|
101
|
+
retrieve: {
|
|
102
|
+
k: raw.retrieve?.k ?? 3,
|
|
103
|
+
alpha: raw.retrieve?.alpha ?? 0.65,
|
|
104
|
+
beta: raw.retrieve?.beta ?? 0.15,
|
|
105
|
+
gamma: raw.retrieve?.gamma ?? 0.20,
|
|
106
|
+
delta: raw.retrieve?.delta ?? 0.10,
|
|
107
|
+
recency_half_life_days: raw.retrieve?.recency_half_life_days ?? 45,
|
|
108
|
+
min_score: raw.retrieve?.min_score ?? 0.3
|
|
109
|
+
},
|
|
110
|
+
judge: {
|
|
111
|
+
model: raw.judge?.model ?? 'claude-sonnet-4-5-20250929',
|
|
112
|
+
max_tokens: raw.judge?.max_tokens ?? 512,
|
|
113
|
+
temperature: raw.judge?.temperature ?? 0,
|
|
114
|
+
confidence_threshold: raw.judge?.fallback_confidence ?? 0.5
|
|
115
|
+
},
|
|
116
|
+
distill: {
|
|
117
|
+
model: raw.distill?.model,
|
|
118
|
+
max_tokens: raw.distill?.max_tokens,
|
|
119
|
+
temperature: raw.distill?.temperature,
|
|
120
|
+
max_items_success: raw.distill?.max_items_per_trajectory ?? 3,
|
|
121
|
+
max_items_failure: 2,
|
|
122
|
+
confidence_prior_success: raw.distill?.success_confidence_prior ?? 0.75,
|
|
123
|
+
confidence_prior_failure: raw.distill?.failure_confidence_prior ?? 0.60
|
|
124
|
+
},
|
|
125
|
+
consolidate: {
|
|
126
|
+
duplicate_threshold: raw.consolidate?.dedup_similarity_threshold ?? 0.95,
|
|
127
|
+
contradiction_threshold: raw.consolidate?.contradiction_threshold ?? 0.85,
|
|
128
|
+
trigger_threshold: raw.consolidate?.run_every_new_items ?? 20,
|
|
129
|
+
prune_age_days: raw.consolidate?.prune_age_days ?? 180,
|
|
130
|
+
prune_min_confidence: raw.consolidate?.min_confidence_keep ?? 0.3,
|
|
131
|
+
min_confidence_keep: raw.consolidate?.min_confidence_keep ?? 0.5
|
|
132
|
+
},
|
|
133
|
+
matts: {
|
|
134
|
+
parallel_k: raw.matts?.parallel?.k ?? 3,
|
|
135
|
+
sequential_k: raw.matts?.sequential?.r ?? 5,
|
|
136
|
+
sequential_r: raw.matts?.sequential?.r ?? 5,
|
|
137
|
+
sequential_stop_on_success: raw.matts?.sequential?.stop_on_success ?? true,
|
|
138
|
+
confidence_boost: 0.05
|
|
139
|
+
},
|
|
140
|
+
embeddings: {
|
|
141
|
+
provider: raw.embeddings?.provider ?? 'claude',
|
|
142
|
+
model: raw.embeddings?.model ?? 'claude-3-5-sonnet-20241022',
|
|
143
|
+
dims: raw.embeddings?.dimensions ?? 1024,
|
|
144
|
+
dimensions: raw.embeddings?.dimensions ?? 1024,
|
|
145
|
+
cache_ttl_seconds: raw.embeddings?.cache_ttl_seconds ?? 3600
|
|
146
|
+
},
|
|
147
|
+
governance: {
|
|
148
|
+
scrub_pii: raw.governance?.pii_scrubber ?? true,
|
|
149
|
+
pii_scrubber: raw.governance?.pii_scrubber ?? true,
|
|
150
|
+
tenant_scoped: raw.governance?.tenant_scoped ?? false
|
|
151
|
+
},
|
|
152
|
+
features: {
|
|
153
|
+
enable_pre_task_hook: raw.features?.enable_pre_task_hook ?? true,
|
|
154
|
+
enable_post_task_hook: raw.features?.enable_post_task_hook ?? true,
|
|
155
|
+
enable_matts_parallel: raw.features?.enable_matts_parallel ?? true
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
return configCache;
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
// If config file exists but can't be read, use defaults
|
|
162
|
+
console.warn(`[ReasoningBank] Could not load config from ${configPath}, using defaults:`, error instanceof Error ? error.message : String(error));
|
|
163
|
+
configCache = DEFAULT_CONFIG;
|
|
164
|
+
return configCache;
|
|
165
|
+
}
|
|
73
166
|
}
|
|
74
167
|
export function clearConfigCache() {
|
|
75
168
|
configCache = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentic-flow",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.10",
|
|
4
4
|
"description": "Production-ready AI agent orchestration platform with 66 specialized agents, 213 MCP tools, ReasoningBank learning memory, and autonomous multi-agent swarms. Built by @ruvnet with Claude Agent SDK, neural networks, memory persistence, GitHub integration, and distributed consensus protocols.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|