agentic-flow 1.6.5 → 1.7.0
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/skills/.claude-flow/metrics/agent-metrics.json +1 -0
- package/.claude/skills/.claude-flow/metrics/performance.json +87 -0
- package/.claude/skills/.claude-flow/metrics/task-metrics.json +10 -0
- package/.claude/skills/skill-builder/.claude-flow/metrics/agent-metrics.json +1 -0
- package/.claude/skills/skill-builder/.claude-flow/metrics/performance.json +87 -0
- package/.claude/skills/skill-builder/.claude-flow/metrics/task-metrics.json +10 -0
- package/CHANGELOG.md +0 -20
- package/README.md +16 -2
- 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/skills-manager.js +1297 -0
- package/dist/cli/update-message.js +175 -0
- package/dist/cli-proxy.js +2 -26
- 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 +67 -0
- package/dist/reasoningbank/HybridBackend.js +91 -0
- package/dist/reasoningbank/index-new.js +87 -0
- package/dist/reasoningbank/index.js +0 -4
- package/dist/utils/cli.js +0 -5
- package/docs/AGENTDB_TESTING.md +411 -0
- package/package.json +4 -4
- package/scripts/run-validation.sh +165 -0
- package/scripts/test-agentdb.sh +153 -0
- package/wasm/reasoningbank/reasoningbank_wasm_bg.js +2 -2
- package/wasm/reasoningbank/reasoningbank_wasm_bg.wasm +0 -0
- package/docs/AGENTDB_INTEGRATION.md +0 -379
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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';
|
|
@@ -99,10 +99,6 @@ export async function runTask(options) {
|
|
|
99
99
|
consolidated
|
|
100
100
|
};
|
|
101
101
|
}
|
|
102
|
-
// AgentDB Integration
|
|
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
102
|
// Version info
|
|
107
103
|
export const VERSION = '1.0.0';
|
|
108
104
|
export const PAPER_URL = 'https://arxiv.org/html/2509.25140v1';
|
package/dist/utils/cli.js
CHANGED
|
@@ -49,11 +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
52
|
for (let i = 0; i < args.length; i++) {
|
|
58
53
|
const arg = args[i];
|
|
59
54
|
switch (arg) {
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
# AgentDB CLI - Local Testing Guide
|
|
2
|
+
|
|
3
|
+
## Quick Start
|
|
4
|
+
|
|
5
|
+
### Option 1: Run the Full Test Suite (Recommended)
|
|
6
|
+
```bash
|
|
7
|
+
# From the project root: /workspaces/agentic-flow/agentic-flow
|
|
8
|
+
./scripts/test-agentdb.sh
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This will run 13 comprehensive tests covering all CLI features!
|
|
12
|
+
|
|
13
|
+
### Option 2: Manual Testing
|
|
14
|
+
|
|
15
|
+
#### 1. Ensure you're in the correct directory
|
|
16
|
+
```bash
|
|
17
|
+
cd /workspaces/agentic-flow/agentic-flow
|
|
18
|
+
pwd # Should show: /workspaces/agentic-flow/agentic-flow
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
#### 2. Build the Project (if not already built)
|
|
22
|
+
```bash
|
|
23
|
+
npm run build
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
#### 3. Test the CLI Directly
|
|
27
|
+
```bash
|
|
28
|
+
# Show help (all 17 commands)
|
|
29
|
+
node dist/agentdb/cli/agentdb-cli.js --help
|
|
30
|
+
|
|
31
|
+
# Or use npx (if globally installed)
|
|
32
|
+
npx agentdb --help
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 3. Create a Test Database
|
|
36
|
+
```bash
|
|
37
|
+
# Set database path
|
|
38
|
+
export AGENTDB_PATH=./test-agentdb.db
|
|
39
|
+
|
|
40
|
+
# Or specify inline for each command
|
|
41
|
+
AGENTDB_PATH=./test-agentdb.db node dist/agentdb/cli/agentdb-cli.js db stats
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Test Each Command Category
|
|
45
|
+
|
|
46
|
+
### 🧠 Reflexion Memory (Episodic Replay)
|
|
47
|
+
```bash
|
|
48
|
+
# Store an episode with self-critique
|
|
49
|
+
node dist/agentdb/cli/agentdb-cli.js reflexion store \
|
|
50
|
+
"session-1" \
|
|
51
|
+
"implement_authentication" \
|
|
52
|
+
0.95 \
|
|
53
|
+
true \
|
|
54
|
+
"Successfully used OAuth2 with JWT tokens" \
|
|
55
|
+
"User login requirement" \
|
|
56
|
+
"Working auth system" \
|
|
57
|
+
1200 \
|
|
58
|
+
5000
|
|
59
|
+
|
|
60
|
+
# Store a failed episode
|
|
61
|
+
node dist/agentdb/cli/agentdb-cli.js reflexion store \
|
|
62
|
+
"session-1" \
|
|
63
|
+
"implement_authentication" \
|
|
64
|
+
0.3 \
|
|
65
|
+
false \
|
|
66
|
+
"Forgot to validate tokens properly" \
|
|
67
|
+
"User login requirement" \
|
|
68
|
+
"Insecure auth" \
|
|
69
|
+
800 \
|
|
70
|
+
3000
|
|
71
|
+
|
|
72
|
+
# Retrieve relevant episodes
|
|
73
|
+
node dist/agentdb/cli/agentdb-cli.js reflexion retrieve \
|
|
74
|
+
"authentication" \
|
|
75
|
+
5 \
|
|
76
|
+
0.5
|
|
77
|
+
|
|
78
|
+
# Get critique summary from failures
|
|
79
|
+
node dist/agentdb/cli/agentdb-cli.js reflexion critique-summary \
|
|
80
|
+
"authentication" \
|
|
81
|
+
true
|
|
82
|
+
|
|
83
|
+
# Prune old episodes
|
|
84
|
+
node dist/agentdb/cli/agentdb-cli.js reflexion prune 30 0.2
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 🛠️ Skill Library (Lifelong Learning)
|
|
88
|
+
```bash
|
|
89
|
+
# Create a skill manually
|
|
90
|
+
node dist/agentdb/cli/agentdb-cli.js skill create \
|
|
91
|
+
"jwt_authentication" \
|
|
92
|
+
"Generate and validate JWT tokens for user authentication" \
|
|
93
|
+
"function generateJWT(payload) { return jwt.sign(payload, secret); }"
|
|
94
|
+
|
|
95
|
+
# Search for skills
|
|
96
|
+
node dist/agentdb/cli/agentdb-cli.js skill search \
|
|
97
|
+
"authentication tokens" \
|
|
98
|
+
5
|
|
99
|
+
|
|
100
|
+
# Auto-consolidate episodes into skills
|
|
101
|
+
node dist/agentdb/cli/agentdb-cli.js skill consolidate \
|
|
102
|
+
3 \
|
|
103
|
+
0.7 \
|
|
104
|
+
7
|
|
105
|
+
|
|
106
|
+
# Prune underperforming skills
|
|
107
|
+
node dist/agentdb/cli/agentdb-cli.js skill prune \
|
|
108
|
+
3 \
|
|
109
|
+
0.4 \
|
|
110
|
+
60
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### 🔗 Causal Memory Graph (Intervention-Based)
|
|
114
|
+
```bash
|
|
115
|
+
# Add a causal edge manually
|
|
116
|
+
node dist/agentdb/cli/agentdb-cli.js causal add-edge \
|
|
117
|
+
"add_unit_tests" \
|
|
118
|
+
"code_quality_score" \
|
|
119
|
+
0.25 \
|
|
120
|
+
0.95 \
|
|
121
|
+
100
|
|
122
|
+
|
|
123
|
+
# Create an A/B experiment
|
|
124
|
+
node dist/agentdb/cli/agentdb-cli.js causal experiment create \
|
|
125
|
+
"test-coverage-vs-bugs" \
|
|
126
|
+
"test_coverage" \
|
|
127
|
+
"bug_rate"
|
|
128
|
+
|
|
129
|
+
# Add observations (treatment group)
|
|
130
|
+
node dist/agentdb/cli/agentdb-cli.js causal experiment add-observation \
|
|
131
|
+
1 \
|
|
132
|
+
true \
|
|
133
|
+
0.15 \
|
|
134
|
+
'{"coverage": 0.85}'
|
|
135
|
+
|
|
136
|
+
# Add observations (control group)
|
|
137
|
+
node dist/agentdb/cli/agentdb-cli.js causal experiment add-observation \
|
|
138
|
+
1 \
|
|
139
|
+
false \
|
|
140
|
+
0.35 \
|
|
141
|
+
'{"coverage": 0.45}'
|
|
142
|
+
|
|
143
|
+
# Calculate uplift
|
|
144
|
+
node dist/agentdb/cli/agentdb-cli.js causal experiment calculate 1
|
|
145
|
+
|
|
146
|
+
# Query causal edges
|
|
147
|
+
node dist/agentdb/cli/agentdb-cli.js causal query \
|
|
148
|
+
"test" \
|
|
149
|
+
"quality" \
|
|
150
|
+
0.6 \
|
|
151
|
+
0.1 \
|
|
152
|
+
10
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 🔍 Causal Recall (Utility-Based Reranking)
|
|
156
|
+
```bash
|
|
157
|
+
# Retrieve with causal utility and provenance certificate
|
|
158
|
+
node dist/agentdb/cli/agentdb-cli.js recall with-certificate \
|
|
159
|
+
"implement secure authentication" \
|
|
160
|
+
10 \
|
|
161
|
+
0.7 \
|
|
162
|
+
0.2 \
|
|
163
|
+
0.1
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### 🌙 Nightly Learner (Automated Discovery)
|
|
167
|
+
```bash
|
|
168
|
+
# Discover causal edges from patterns (dry run)
|
|
169
|
+
node dist/agentdb/cli/agentdb-cli.js learner run \
|
|
170
|
+
3 \
|
|
171
|
+
0.6 \
|
|
172
|
+
0.7 \
|
|
173
|
+
true
|
|
174
|
+
|
|
175
|
+
# Discover and save edges
|
|
176
|
+
node dist/agentdb/cli/agentdb-cli.js learner run \
|
|
177
|
+
3 \
|
|
178
|
+
0.6 \
|
|
179
|
+
0.7 \
|
|
180
|
+
false
|
|
181
|
+
|
|
182
|
+
# Prune low-quality edges
|
|
183
|
+
node dist/agentdb/cli/agentdb-cli.js learner prune \
|
|
184
|
+
0.5 \
|
|
185
|
+
0.05 \
|
|
186
|
+
90
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 📊 Database Stats
|
|
190
|
+
```bash
|
|
191
|
+
# Get comprehensive database statistics
|
|
192
|
+
node dist/agentdb/cli/agentdb-cli.js db stats
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Full Workflow Example
|
|
196
|
+
|
|
197
|
+
### Scenario: Learning from Authentication Implementation
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
#!/bin/bash
|
|
201
|
+
|
|
202
|
+
# Set up test database
|
|
203
|
+
export AGENTDB_PATH=./auth-learning.db
|
|
204
|
+
|
|
205
|
+
# 1. Store successful attempts
|
|
206
|
+
node dist/agentdb/cli/agentdb-cli.js reflexion store \
|
|
207
|
+
"session-auth-1" "oauth2_implementation" 0.95 true \
|
|
208
|
+
"Used industry-standard OAuth2 flow" \
|
|
209
|
+
"Implement secure login" "Working OAuth2 system" 1500 6000
|
|
210
|
+
|
|
211
|
+
node dist/agentdb/cli/agentdb-cli.js reflexion store \
|
|
212
|
+
"session-auth-2" "jwt_tokens" 0.90 true \
|
|
213
|
+
"JWT with proper expiration and refresh tokens" \
|
|
214
|
+
"Token management" "Secure JWT system" 1200 5500
|
|
215
|
+
|
|
216
|
+
# 2. Store failed attempts
|
|
217
|
+
node dist/agentdb/cli/agentdb-cli.js reflexion store \
|
|
218
|
+
"session-auth-3" "session_storage" 0.35 false \
|
|
219
|
+
"Insecure session storage in localStorage" \
|
|
220
|
+
"Session management" "Security vulnerability" 800 3000
|
|
221
|
+
|
|
222
|
+
# 3. Create a skill from successful pattern
|
|
223
|
+
node dist/agentdb/cli/agentdb-cli.js skill create \
|
|
224
|
+
"secure_oauth2_jwt" \
|
|
225
|
+
"OAuth2 flow with JWT token management" \
|
|
226
|
+
"const auth = { oauth2: true, jwt: true, refresh: true }"
|
|
227
|
+
|
|
228
|
+
# 4. Add causal edge
|
|
229
|
+
node dist/agentdb/cli/agentdb-cli.js causal add-edge \
|
|
230
|
+
"add_token_refresh" "session_security" 0.40 0.92 50
|
|
231
|
+
|
|
232
|
+
# 5. Query for authentication guidance
|
|
233
|
+
node dist/agentdb/cli/agentdb-cli.js reflexion retrieve \
|
|
234
|
+
"secure authentication" 5 0.8
|
|
235
|
+
|
|
236
|
+
# 6. Get critique summary of what NOT to do
|
|
237
|
+
node dist/agentdb/cli/agentdb-cli.js reflexion critique-summary \
|
|
238
|
+
"authentication" true
|
|
239
|
+
|
|
240
|
+
# 7. Search for applicable skills
|
|
241
|
+
node dist/agentdb/cli/agentdb-cli.js skill search \
|
|
242
|
+
"oauth jwt tokens" 3
|
|
243
|
+
|
|
244
|
+
# 8. Check database stats
|
|
245
|
+
node dist/agentdb/cli/agentdb-cli.js db stats
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
## Verify Installation
|
|
249
|
+
|
|
250
|
+
### Check Binary Links
|
|
251
|
+
```bash
|
|
252
|
+
# Should show the CLI binary path
|
|
253
|
+
which agentdb
|
|
254
|
+
|
|
255
|
+
# Or check npm bin
|
|
256
|
+
npm bin agentdb
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Run from Package
|
|
260
|
+
```bash
|
|
261
|
+
# If you've run npm install -g or npm link
|
|
262
|
+
agentdb --help
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
## Environment Variables
|
|
266
|
+
|
|
267
|
+
```bash
|
|
268
|
+
# Database path (default: ./agentdb.db)
|
|
269
|
+
export AGENTDB_PATH=/path/to/your/database.db
|
|
270
|
+
|
|
271
|
+
# Example with custom path
|
|
272
|
+
AGENTDB_PATH=~/my-agent-memory.db node dist/agentdb/cli/agentdb-cli.js db stats
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## Expected Output Examples
|
|
276
|
+
|
|
277
|
+
### Successful Episode Storage
|
|
278
|
+
```
|
|
279
|
+
✓ Stored episode #1 (session: session-1, task: implement_authentication)
|
|
280
|
+
Reward: 0.95 | Success: true | Latency: 1200ms | Tokens: 5000
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Skill Search Results
|
|
284
|
+
```
|
|
285
|
+
🔍 Found 3 skills for "authentication"
|
|
286
|
+
|
|
287
|
+
#1: jwt_authentication (success rate: 0.90, uses: 5)
|
|
288
|
+
Generate and validate JWT tokens for user authentication
|
|
289
|
+
|
|
290
|
+
#2: oauth2_flow (success rate: 0.85, uses: 3)
|
|
291
|
+
Complete OAuth2 authorization code flow
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### Database Stats
|
|
295
|
+
```
|
|
296
|
+
AgentDB Statistics
|
|
297
|
+
|
|
298
|
+
Episodes: 15
|
|
299
|
+
Skills: 8
|
|
300
|
+
Causal Edges: 12
|
|
301
|
+
Experiments: 3
|
|
302
|
+
Certificates: 5
|
|
303
|
+
|
|
304
|
+
Total Size: 2.4 MB
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
## Troubleshooting
|
|
308
|
+
|
|
309
|
+
### Issue: "Cannot find module"
|
|
310
|
+
```bash
|
|
311
|
+
# Rebuild the project
|
|
312
|
+
npm run build
|
|
313
|
+
|
|
314
|
+
# Check dist folder exists
|
|
315
|
+
ls dist/agentdb/cli/agentdb-cli.js
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
### Issue: "Database is locked"
|
|
319
|
+
```bash
|
|
320
|
+
# Close any open database connections
|
|
321
|
+
# Or use a different database path
|
|
322
|
+
export AGENTDB_PATH=./test2-agentdb.db
|
|
323
|
+
```
|
|
324
|
+
|
|
325
|
+
### Issue: "Permission denied"
|
|
326
|
+
```bash
|
|
327
|
+
# Make CLI executable
|
|
328
|
+
chmod +x dist/agentdb/cli/agentdb-cli.js
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## Advanced Testing
|
|
332
|
+
|
|
333
|
+
### Test with Programmatic API
|
|
334
|
+
```typescript
|
|
335
|
+
import { AgentDBCLI } from './dist/agentdb/cli/agentdb-cli.js';
|
|
336
|
+
|
|
337
|
+
const cli = new AgentDBCLI('./test.db');
|
|
338
|
+
|
|
339
|
+
// Store episode
|
|
340
|
+
await cli.reflexionStore({
|
|
341
|
+
sessionId: 'test-1',
|
|
342
|
+
task: 'example',
|
|
343
|
+
reward: 0.9,
|
|
344
|
+
success: true,
|
|
345
|
+
critique: 'Good approach'
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// Retrieve episodes
|
|
349
|
+
await cli.reflexionRetrieve({
|
|
350
|
+
task: 'example',
|
|
351
|
+
k: 5
|
|
352
|
+
});
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### Integration with Your Project
|
|
356
|
+
```typescript
|
|
357
|
+
// In your agent code
|
|
358
|
+
import { AgentDBCLI } from 'agentic-flow/agentdb';
|
|
359
|
+
|
|
360
|
+
const memory = new AgentDBCLI();
|
|
361
|
+
|
|
362
|
+
// Learn from task outcomes
|
|
363
|
+
async function learnFromTask(task, outcome) {
|
|
364
|
+
await memory.reflexionStore({
|
|
365
|
+
sessionId: getCurrentSession(),
|
|
366
|
+
task: task.name,
|
|
367
|
+
reward: outcome.score,
|
|
368
|
+
success: outcome.passed,
|
|
369
|
+
critique: outcome.feedback,
|
|
370
|
+
input: task.input,
|
|
371
|
+
output: outcome.result,
|
|
372
|
+
latencyMs: outcome.duration,
|
|
373
|
+
tokensUsed: outcome.tokens
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// Retrieve similar past experiences
|
|
378
|
+
async function recallSimilar(task) {
|
|
379
|
+
return await memory.reflexionRetrieve({
|
|
380
|
+
task: task.name,
|
|
381
|
+
k: 5,
|
|
382
|
+
minReward: 0.7
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
## Performance Benchmarks
|
|
388
|
+
|
|
389
|
+
```bash
|
|
390
|
+
# Time a full workflow
|
|
391
|
+
time bash full-workflow-example.sh
|
|
392
|
+
|
|
393
|
+
# Check database performance
|
|
394
|
+
node dist/agentdb/cli/agentdb-cli.js db stats
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
## Next Steps
|
|
398
|
+
|
|
399
|
+
1. ✅ Test basic commands (reflexion, skill)
|
|
400
|
+
2. ✅ Test causal features (edges, experiments)
|
|
401
|
+
3. ✅ Run nightly learner for discovery
|
|
402
|
+
4. ✅ Verify causal recall with certificates
|
|
403
|
+
5. ✅ Check database stats
|
|
404
|
+
6. 🚀 Integrate into your agent workflows
|
|
405
|
+
|
|
406
|
+
## Resources
|
|
407
|
+
|
|
408
|
+
- **AgentDB Controllers**: `/src/agentdb/controllers/`
|
|
409
|
+
- **CLI Source**: `/src/agentdb/cli/agentdb-cli.ts`
|
|
410
|
+
- **Tests**: `/src/agentdb/tests/frontier-features.test.ts`
|
|
411
|
+
- **Binary**: `/dist/agentdb/cli/agentdb-cli.js`
|