v3/implementation/architecture/AGENTIC-FLOW-INTEGRATION-ANALYSIS.md
Current State: Claude-Flow v2.7.47 uses agentic-flow@^1.9.4
Latest Alpha: [email protected] (published yesterday)
Upgrade Impact: Major performance and capability improvements
| Aspect | v1.9.4 (Current) | v2.0.1-alpha.50 | Improvement |
|---|---|---|---|
| Attention Mechanisms | Basic | 5 types (Flash, MoE, etc.) | Full suite |
| AgentDB Integration | Partial | EnhancedAgentDBWrapper | 50-200x faster |
| GNN Query Refinement | None | Full support | +12.4% recall |
| Hook Tools | 10 | 19 (+ intelligence tools) | +90% coverage |
| Learning System | ReasoningBank | + SONA + Trajectory | Complete loop |
| Runtime Detection | Manual | Auto (NAPI→WASM→JS) | Zero-config |
// Main exports
export * as reasoningbank from "./reasoningbank/index.js";
// Parallel agent execution
import { webResearchAgent, codeReviewAgent, dataAgent, claudeAgent } from "./agents/*";
// Agent loading
import { getAgent, listAgents } from "./utils/agentLoader.js";
// MCP commands
import { handleMCPCommand } from "./utils/mcpCommands.js";
import { handleReasoningBankCommand } from "./utils/reasoningbankCommands.js";
Production-Ready Wrappers (replacing broken @ruvector/* alpha APIs):
// GNN wrapper exports (11-22x speedup)
export { differentiableSearch, hierarchicalForward, RuvectorLayer, TensorCompress };
// AgentDB Fast API (50-200x faster than CLI)
export { AgentDBFast, createFastAgentDB };
// Native Attention (Rust with TypedArray support)
export {
NativeMultiHeadAttention, NativeFlashAttention,
NativeLinearAttention, NativeHyperbolicAttention, NativeMoEAttention
};
// Fallback Attention (JavaScript implementations)
export {
FallbackMultiHeadAttention, FallbackFlashAttention,
FallbackLinearAttention, FallbackHyperbolicAttention, FallbackMoEAttention
};
// Embedding service (3 providers)
export {
EmbeddingService, OpenAIEmbeddingService,
TransformersEmbeddingService, MockEmbeddingService
};
export { AttentionCoordinator, createAttentionCoordinator };
AttentionCoordinator Capabilities:
coordinateAgents(outputs, mechanism) - Attention-based consensusrouteToExperts(task, agents, topK) - MoE expert selectiontopologyAwareCoordination(outputs, topology, graph) - GraphRoPE coordination// Hybrid backend (recommended)
export { HybridReasoningBank } from './HybridBackend.js';
export { AdvancedMemorySystem } from './AdvancedMemory.js';
// AgentDB controllers
export { ReflexionMemory, SkillLibrary, CausalMemoryGraph,
CausalRecall, NightlyLearner, EmbeddingService };
// Original functions (backward compatible)
export { retrieveMemories, formatMemoriesForPrompt };
export { judgeTrajectory };
export { distillMemories };
export { consolidate, shouldConsolidate };
export { mattsParallel, mattsSequential };
export { computeEmbedding, clearEmbeddingCache };
export { mmrSelection, cosineSimilarity };
export { scrubPII, containsPII, scrubMemory };
Original Hooks (10):
export { hookPreEditTool, hookPostEditTool };
export { hookPreCommandTool, hookPostCommandTool };
export { hookRouteTool, hookExplainTool };
export { hookPretrainTool, hookBuildAgentsTool };
export { hookMetricsTool, hookTransferTool };
NEW Intelligence Bridge (9):
export {
getIntelligence, routeTaskIntelligent,
beginTaskTrajectory, recordTrajectoryStep, endTaskTrajectory,
storePattern, findSimilarPatterns,
getIntelligenceStats, forceLearningCycle,
computeAttentionSimilarity
};
NEW Intelligence MCP Tools (9):
export {
intelligenceRouteTool,
intelligenceTrajectoryStartTool, intelligenceTrajectoryStepTool, intelligenceTrajectoryEndTool,
intelligencePatternStoreTool, intelligencePatternSearchTool,
intelligenceStatsTool, intelligenceLearnTool, intelligenceAttentionTool
};
| File | Integration Type | Status |
|---|---|---|
src/services/agentic-flow-hooks/ | Hook system | Full pipeline |
src/reasoningbank/reasoningbank-adapter.js | Memory backend | ReasoningBank v1 |
src/neural/ | Neural integration | Partial |
src/hooks/ | Hook matchers | Basic |
src/cli/simple-commands/ | CLI commands | Basic |
Current Implementation (src/services/agentic-flow-hooks/):
hook-manager.ts - Central manager with pipelinesllm-hooks.ts - Pre/post LLM call hooksmemory-hooks.ts - Memory operation hooksneural-hooks.ts - Neural training hooksperformance-hooks.ts - Metrics collectionworkflow-hooks.ts - Workflow execution hooksPipelines Defined:
llm-call-pipeline - Pre-call → Execution → Post-callmemory-operation-pipeline - Validation → Storage → Syncworkflow-execution-pipeline - Init → Execution → CompletionCurrent (src/reasoningbank/reasoningbank-adapter.js):
import * as ReasoningBank from 'agentic-flow/reasoningbank';
// Uses v1 API
await ReasoningBank.initialize();
Missing v2 Features:
HybridReasoningBank - Best of SQLite + WASMAdvancedMemorySystem - Full learning loopCurrent dependency:
"agentic-flow": "^1.9.4"
Upgrade to:
"agentic-flow": "^2.0.1-alpha.0"
Benefits:
Current: Using basic AgentDB wrapper Upgrade to: EnhancedAgentDBWrapper
// src/v3/core/enhanced-agentdb.ts
import { EnhancedAgentDBWrapper } from 'agentic-flow/core';
export const createEnhancedDB = () => new EnhancedAgentDBWrapper({
dimension: 384,
enableAttention: true,
attentionConfig: {
type: 'flash', // 4x faster, 75% memory reduction
numHeads: 8,
headDim: 64
},
enableGNN: true,
gnnConfig: {
numLayers: 3, // +12.4% recall
hiddenDim: 256,
aggregation: 'attention'
},
runtimePreference: 'napi' // Auto-fallback: NAPI → WASM → JS
});
Current: Basic swarm coordination Upgrade to: Attention-based consensus
// src/v3/coordination/attention-swarm.ts
import { AttentionCoordinator, createAttentionCoordinator } from 'agentic-flow/coordination';
export class AttentionSwarmCoordinator {
private coordinator: AttentionCoordinator;
async coordinateAgents(agentOutputs: AgentOutput[]) {
// Attention-based consensus (better than voting)
return this.coordinator.coordinateAgents(agentOutputs, 'flash');
}
async routeToExperts(task: Task, agents: Agent[], topK = 3) {
// MoE-based expert selection
return this.coordinator.routeToExperts(task, agents, topK);
}
async topologyAwareCoordination(outputs: AgentOutput[], topology: string) {
// GraphRoPE for mesh/hierarchical coordination
return this.coordinator.topologyAwareCoordination(outputs, topology);
}
}
New capabilities from v2:
import {
getIntelligence,
routeTaskIntelligent,
beginTaskTrajectory,
recordTrajectoryStep,
endTaskTrajectory,
storePattern,
findSimilarPatterns,
forceLearningCycle
} from 'agentic-flow/mcp/fastmcp/tools/hooks';
// Pre-task: Query learned patterns
async function preTaskHook(task: Task) {
const patterns = await findSimilarPatterns(task.description, { k: 5 });
return { suggestions: patterns };
}
// During task: Record trajectory
async function duringTaskHook(step: TaskStep) {
await recordTrajectoryStep({
stepId: step.id,
action: step.action,
result: step.result,
embedding: await computeEmbedding(step.description)
});
}
// Post-task: Store learning
async function postTaskHook(task: Task, result: TaskResult) {
await endTaskTrajectory({
taskId: task.id,
success: result.success,
reward: calculateReward(result)
});
if (result.success && result.quality > 0.8) {
await storePattern({
pattern: task.description,
solution: result.output,
confidence: result.quality
});
}
}
Current: SQLite-only ReasoningBank Upgrade to: Hybrid backend (best of both)
import { HybridReasoningBank } from 'agentic-flow/reasoningbank';
const reasoningBank = new HybridReasoningBank({
sqlitePath: '.swarm/memory.db',
wasmFallback: true, // For Windows/browser
cacheSize: 1000,
consolidationInterval: 3600000 // 1 hour
});
await reasoningBank.initialize();
// Store with automatic embedding
await reasoningBank.store({
key: 'pattern:auth',
value: authImplementation,
metadata: { domain: 'security', confidence: 0.95 }
});
// Semantic search
const similar = await reasoningBank.searchSemantic('authentication patterns', {
k: 5,
threshold: 0.7
});
New controllers available:
import {
ReflexionMemory, // Self-improvement through feedback
SkillLibrary, // Store successful patterns
CausalMemoryGraph, // Causal relationships
CausalRecall, // Cause-effect retrieval
NightlyLearner // Background learning
} from 'agentic-flow/reasoningbank';
// Reflexion: Learn from mistakes
const reflexion = new ReflexionMemory(agentDB);
await reflexion.recordAttempt(task, result, feedback);
const improvements = await reflexion.suggestImprovements(task);
// Skill Library: Store successful patterns
const skills = new SkillLibrary(agentDB);
await skills.addSkill({
name: 'api-authentication',
pattern: authCode,
context: { framework: 'express', method: 'jwt' }
});
const relevantSkills = await skills.findRelevantSkills('implement login');
// Causal Memory: Track cause-effect
const causal = new CausalMemoryGraph(agentDB);
await causal.recordCause(action, effect, confidence);
const effects = await causal.predictEffects(proposedAction);
// Nightly Learner: Background optimization
const learner = new NightlyLearner(agentDB);
await learner.scheduleLearning({ interval: '0 2 * * *' }); // 2 AM daily
v2 provides auto-detection:
import { shouldUseNativePackage, getWrapperPerformance } from 'agentic-flow/core';
// Check if native package should be used
const useNative = shouldUseNativePackage('@ruvector/gnn');
// Returns false for alpha packages (use wrappers instead)
// Get performance info
const gnnPerf = getWrapperPerformance('gnn');
// { speedup: '11-22x', latency: '1-5ms', status: 'verified' }
const agentdbPerf = getWrapperPerformance('agentdb-fast');
// { speedup: '50-200x', latency: '10-50ms', status: 'verified' }
┌─────────────────────────────────────────────────────────────┐
│ Claude-Flow v3 │
├─────────────────────────────────────────────────────────────┤
│ ┌─────────────────────────────────────────────────────┐ │
│ │ v2 Compatibility Layer │ │
│ │ - SwarmCoordinator adapter │ │
│ │ - AgentManager adapter │ │
│ │ - MemoryManager bridge │ │
│ └─────────────────────────────────────────────────────┘ │
│ │ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ [email protected] Core │ │
│ │ ┌───────────────┐ ┌───────────────┐ │ │
│ │ │ Enhanced │ │ Attention │ │ │
│ │ │ AgentDB │ │ Coordinator │ │ │
│ │ │ Wrapper │ │ (Flash/MoE) │ │ │
│ │ └───────────────┘ └───────────────┘ │ │
│ │ ┌───────────────┐ ┌───────────────┐ │ │
│ │ │ Hybrid │ │ Intelligence │ │ │
│ │ │ ReasoningBank │ │ Bridge │ │ │
│ │ └───────────────┘ └───────────────┘ │ │
│ │ ┌───────────────┐ ┌───────────────┐ │ │
│ │ │ AgentDB │ │ Hook Tools │ │ │
│ │ │ Controllers │ │ (19 tools) │ │ │
│ │ └───────────────┘ └───────────────┘ │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
| Claude-Flow Component | agentic-flow v2 Integration | Priority |
|---|---|---|
SwarmCoordinator | AttentionCoordinator | HIGH |
AgentManager | EnhancedAgentDBWrapper | HIGH |
MemoryManager | HybridReasoningBank | HIGH |
HookManager | Intelligence Bridge | MEDIUM |
NeuralManager | NightlyLearner | MEDIUM |
ReasoningBankAdapter | AgentDB Controllers | MEDIUM |
InitController | Auto runtime detection | LOW |
New Files:
src/v3/
├── core/
│ └── enhanced-agentdb.ts # EnhancedAgentDBWrapper integration
├── coordination/
│ └── attention-coordinator.ts # AttentionCoordinator wrapper
├── memory/
│ └── hybrid-reasoningbank.ts # HybridReasoningBank integration
├── learning/
│ ├── intelligence-bridge.ts # Intelligence tools integration
│ └── controllers.ts # AgentDB controllers
└── hooks/
└── v2-hooks.ts # New hook tools integration
Modified Files:
package.json # Upgrade agentic-flow version
src/services/agentic-flow-hooks/ # Add intelligence bridge
src/reasoningbank/reasoningbank-adapter.js # Use HybridReasoningBank
| Operation | v1 (CLI) | v2 (Fast API) | Improvement |
|---|---|---|---|
| Initialize | 2,350ms | 10-50ms | 50-200x |
| Store vector | 150ms | 1-5ms | 30-150x |
| Search k=10 | 500ms | 5-20ms | 25-100x |
| Batch store | 5,000ms | 50-100ms | 50-100x |
| Mechanism | Latency | Memory | Use Case |
|---|---|---|---|
| Flash | 0.7-1.5ms | 25% of base | Default (fastest) |
| Multi-Head | 2-5ms | 100% | Complex reasoning |
| Linear | 1-3ms | 50% | Long sequences |
| Hyperbolic | 3-8ms | 100% | Hierarchical data |
| MoE | 1-4ms | Variable | Expert routing |
| Metric | Without GNN | With GNN | Improvement |
|---|---|---|---|
| Recall@5 | 72.3% | 81.3% | +12.4% |
| Recall@10 | 78.1% | 87.8% | +12.4% |
| Latency | 5ms | 8ms | +60% (acceptable) |
"agentic-flow": "^2.0.1-alpha.0"src/v3/core/enhanced-agentdb.tssrc/v3/coordination/attention-coordinator.tssrc/v3/memory/hybrid-reasoningbank.tssrc/v3/learning/intelligence-bridge.tsRisk: v2.0.1-alpha.50 may have breaking changes Mitigation:
Risk: NAPI modules may fail on some systems Mitigation:
Risk: New features may impact startup time Mitigation:
agentic-flow@^2.0.1-alpha.0| Metric | Before | After | Improvement |
|---|---|---|---|
| AgentDB ops | 150ms | 5ms | 30x faster |
| Consensus quality | Basic voting | Attention-based | +55% accuracy |
| Memory search | 500ms | 20ms | 25x faster |
| Learning loop | Manual | Automatic | Continuous |
| Recall accuracy | 72% | 84% | +12.4% |
agentic-flow v2 includes a production-ready QUIC transport layer:
// dist/transport/quic.js
export { QuicClient, QuicServer, QuicConnectionPool, QuicTransport };
// Key capabilities:
class QuicClient {
// Connection pooling with 4x memory efficiency
maxConnections: 100;
maxConcurrentStreams: 100;
// HTTP/3 over QUIC
async sendRequest(connectionId, method, path, headers, body);
// TLS 1.3 integration
certPath, keyPath, verifyPeer;
// Performance features
enableEarlyData: true; // 0-RTT when available
initialCongestionWindow: 10;
}
| Metric | TCP/HTTP/2 | QUIC (Projected) | Improvement |
|---|---|---|---|
| Connection Setup | 100-150ms | 10-20ms | 5-15x faster |
| Agent Spawn (10) | 3,700ms | 220ms | 16.8x faster |
| Throughput | 3.4K msg/s | 8.9K msg/s | 2.6x higher |
| Memory (2K agents) | 3.2MB | 1.6MB | 50% reduction |
wasm/
├── quic/
│ ├── agentic_flow_quic_bg.wasm # QUIC client/server
│ └── agentic_flow_quic.d.ts # TypeScript bindings
├── reasoningbank/
│ ├── reasoningbank_wasm_bg.wasm # ReasoningBank engine
│ └── reasoningbank_wasm.d.ts # Pattern storage, search
dist/wasm/
├── ruvector-edge.js # Edge GNN inference
├── edge-full.js # Full edge runtime
└── onnx-embeddings-wasm.js # ONNX embedding inference
WASM Capabilities:
// wasm/quic/agentic_flow_quic.d.ts
export class WasmQuicClient {
constructor(config: any);
sendMessage(addr: string, message: any): Promise<void>;
recvMessage(addr: string): Promise<any>;
poolStats(): Promise<any>;
close(): Promise<void>;
}
// wasm/reasoningbank/reasoningbank_wasm.d.ts
export class ReasoningBankWasm {
constructor(db_name?: string | null);
storePattern(pattern_json: string): Promise<string>;
getPattern(id: string): Promise<string>;
searchByCategory(category: string, limit: number): Promise<string>;
findSimilar(task: string, category: string, top_k: number): Promise<string>;
getStats(): Promise<string>;
}
// src/v3/transport/quic-integration.ts
import { QuicTransport, QuicConnectionPool } from 'agentic-flow/transport';
export class ClaudeFlowQuicTransport {
private pool: QuicConnectionPool;
async initialize() {
const client = new QuicClient({
serverHost: 'localhost',
serverPort: 4433,
maxConcurrentStreams: 100,
enableEarlyData: true // 0-RTT
});
await client.initialize();
this.pool = new QuicConnectionPool(client, 10);
}
// Agent-to-agent communication
async sendToAgent(agentId: string, message: Message): Promise<Response> {
const conn = await this.pool.getConnection(agentId);
return this.client.sendRequest(
conn.id,
'POST',
'/agent/message',
{ 'Content-Type': 'application/json' },
JSON.stringify(message)
);
}
}
Current Implementation (src/reasoningbank/reasoningbank-adapter.js):
// v1 API usage (current)
import * as ReasoningBank from 'agentic-flow/reasoningbank';
await ReasoningBank.initialize();
ReasoningBank.db.upsertMemory(memory);
ReasoningBank.computeEmbedding(value);
ReasoningBank.retrieveMemories(query, options);
ReasoningBank.db.fetchMemoryCandidates(options);
ReasoningBank.db.getAllActiveMemories();
Migration Path to v2:
// v2 API (recommended)
import { HybridReasoningBank, computeEmbedding } from 'agentic-flow/reasoningbank';
import { EnhancedAgentDBWrapper } from 'agentic-flow/core';
const bank = new HybridReasoningBank({
sqlitePath: '.swarm/memory.db',
wasmFallback: true, // Windows/browser support
embeddingDimension: 384
});
await bank.initialize();
// 50-200x faster operations
await bank.store({ key, value, metadata });
const results = await bank.searchSemantic(query, { k: 10 });
Current Implementation (src/neural/integration.ts):
agenticHookManager for hook registrationNeuralDomainMapperIntegration classneural-pattern-detected, post-neural-trainEnhancement with v2:
import {
beginTaskTrajectory,
recordTrajectoryStep,
endTaskTrajectory,
forceLearningCycle
} from 'agentic-flow/mcp/fastmcp/tools/hooks';
// Add trajectory tracking to existing neural integration
class EnhancedNeuralIntegration extends NeuralDomainMapperIntegration {
async trackLearning(task: Task) {
await beginTaskTrajectory({ taskId: task.id });
// During execution
await recordTrajectoryStep({
stepId: step.id,
action: step.action,
result: step.result
});
// After completion
await endTaskTrajectory({
taskId: task.id,
success: task.success,
reward: task.quality
});
// Trigger nightly learning if high quality
if (task.quality > 0.9) {
await forceLearningCycle();
}
}
}
Current Implementation (src/services/agentic-flow-hooks/):
| File | Current Hooks | v2 Enhancement |
|---|---|---|
llm-hooks.ts | pre-llm-call, post-llm-call | + routeTaskIntelligent |
memory-hooks.ts | pre-memory-store, post-memory-store | + storePattern, findSimilarPatterns |
neural-hooks.ts | pre-neural-train, post-neural-train | + trajectory tracking |
performance-hooks.ts | performance-metric | + computeAttentionSimilarity |
workflow-hooks.ts | workflow-start/step/complete | + intelligenceRouteTool |
Current Skills Using agentic-flow:
| Skill | Import | v2 Migration |
|---|---|---|
reasoningbank-intelligence | ReasoningBank | HybridReasoningBank |
reasoningbank-agentdb | createAgentDBAdapter, computeEmbedding | EnhancedAgentDBWrapper |
agentdb-optimization | createAgentDBAdapter | AgentDBFast |
agentdb-vector-search | createAgentDBAdapter, computeEmbedding | GNN-enhanced search |
agentdb-memory-patterns | createAgentDBAdapter, migrateToAgentDB | ReflexionMemory, SkillLibrary |
agentdb-learning | createAgentDBAdapter | NightlyLearner |
agentdb-advanced | createAgentDBAdapter | CausalMemoryGraph |
// dist/mcp/fastmcp/tools/sona-tools.js
export const sonaTools = [
'sona_trajectory_begin', // Start trajectory recording
'sona_trajectory_step', // Record step in trajectory
'sona_trajectory_end', // Complete trajectory with verdict
'sona_pattern_find', // Find similar patterns
'sona_pattern_store', // Store successful pattern
'sona_micro_lora_train', // Train micro LoRA adapter
'sona_apply_micro_lora', // Apply trained adapter
'sona_learning_status', // Get learning statistics
'sona_force_consolidation' // Force memory consolidation
];
// src/v3/learning/sona-integration.ts
import {
sona_trajectory_begin,
sona_trajectory_step,
sona_trajectory_end,
sona_pattern_find,
sona_pattern_store
} from 'agentic-flow/mcp/fastmcp/tools/sona-tools';
export class SOANLearningSystem {
private activeTrajectories = new Map<string, string>();
async startTask(task: Task): Promise<void> {
const trajectoryId = await sona_trajectory_begin({
taskId: task.id,
description: task.description,
category: task.category
});
this.activeTrajectories.set(task.id, trajectoryId);
}
async recordStep(taskId: string, step: TaskStep): Promise<void> {
const trajectoryId = this.activeTrajectories.get(taskId);
await sona_trajectory_step({
trajectoryId,
action: step.action,
observation: step.observation,
reward: step.reward,
timestamp: Date.now()
});
}
async completeTask(taskId: string, result: TaskResult): Promise<void> {
const trajectoryId = this.activeTrajectories.get(taskId);
// End trajectory with verdict
await sona_trajectory_end({
trajectoryId,
success: result.success,
verdict: result.success ? 'positive' : 'negative',
reward: result.quality
});
// Store successful patterns
if (result.success && result.quality > 0.8) {
await sona_pattern_store({
pattern: result.solution,
category: result.category,
confidence: result.quality,
metadata: { taskId, trajectoryId }
});
}
this.activeTrajectories.delete(taskId);
}
async findSimilarPatterns(query: string, k = 5): Promise<Pattern[]> {
return sona_pattern_find({
query,
topK: k,
threshold: 0.7
});
}
}
package.json change:
{
"dependencies": {
"agentic-flow": "^2.0.1-alpha.0"
}
}
Expected impact:
Replace src/reasoningbank/reasoningbank-adapter.js:
// src/v3/memory/hybrid-adapter.ts
import { HybridReasoningBank } from 'agentic-flow/reasoningbank';
import { EnhancedAgentDBWrapper } from 'agentic-flow/core';
export class HybridMemoryAdapter {
private bank: HybridReasoningBank;
private db: EnhancedAgentDBWrapper;
async initialize() {
this.bank = new HybridReasoningBank({
sqlitePath: '.swarm/memory.db',
wasmFallback: true,
cacheSize: 1000
});
this.db = new EnhancedAgentDBWrapper({
dimension: 384,
enableAttention: true,
attentionConfig: { type: 'flash' },
enableGNN: true,
gnnConfig: { numLayers: 3 }
});
await Promise.all([
this.bank.initialize(),
this.db.initialize()
]);
}
// Backward compatible API
async storeMemory(key: string, value: string, options = {}) {
return this.bank.store({ key, value, metadata: options });
}
async queryMemories(query: string, options = {}) {
// Use GNN-enhanced search (+12.4% recall)
return this.bank.searchSemantic(query, {
k: options.limit || 10,
useGNN: true,
threshold: options.minConfidence || 0.3
});
}
}
Enhance swarm coordinator with attention mechanisms:
// src/v3/swarm/attention-swarm.ts
import { AttentionCoordinator } from 'agentic-flow/coordination';
export class AttentionSwarmCoordinator {
private coordinator: AttentionCoordinator;
constructor() {
this.coordinator = new AttentionCoordinator({
mechanisms: ['flash', 'moe'],
defaultMechanism: 'flash'
});
}
async coordinateAgentOutputs(outputs: AgentOutput[]): Promise<ConsenusResult> {
// Attention-based consensus (better than voting)
return this.coordinator.coordinateAgents(outputs, 'flash');
}
async routeToExperts(task: Task, agents: Agent[]): Promise<Agent[]> {
// MoE expert selection
return this.coordinator.routeToExperts(task, agents, 3);
}
async meshCoordination(outputs: AgentOutput[]): Promise<MeshResult> {
// GraphRoPE for mesh topology
return this.coordinator.topologyAwareCoordination(outputs, 'mesh');
}
}
Add to hook system:
// src/v3/hooks/intelligence-hooks.ts
import {
getIntelligence,
routeTaskIntelligent,
storePattern,
findSimilarPatterns,
getIntelligenceStats
} from 'agentic-flow/mcp/fastmcp/tools/hooks';
export function registerIntelligenceHooks(hookManager: AgenticHookManager) {
// Pre-task: Query learned patterns
hookManager.register({
id: 'intelligence-pre-task',
type: 'pre-llm-call',
priority: 90,
handler: async (payload, context) => {
const patterns = await findSimilarPatterns(payload.prompt, { k: 5 });
if (patterns.length > 0) {
// Inject learned patterns into context
return {
continue: true,
modifiedPayload: {
...payload,
systemContext: payload.systemContext + formatPatterns(patterns)
}
};
}
return { continue: true };
}
});
// Post-task: Store successful patterns
hookManager.register({
id: 'intelligence-post-task',
type: 'post-llm-call',
priority: 80,
handler: async (payload, context) => {
if (payload.success && payload.quality > 0.8) {
await storePattern({
pattern: payload.task,
solution: payload.response,
confidence: payload.quality
});
}
return { continue: true };
}
});
}
New file: src/v3/learning/sona-system.ts
(See Section 11.2 for full implementation)
package.json to agentic-flow@^2.0.1-alpha.0HybridMemoryAdapterreasoningbank-adapter.jsAttentionSwarmCoordinator| Priority | Integration | Current | v2 Feature | Impact |
|---|---|---|---|---|
| 1 | Dependency | ^1.9.4 | ^2.0.1-alpha.0 | Foundation |
| 2 | AgentDB | Basic | EnhancedAgentDBWrapper | 50-200x faster |
| 3 | Memory | SQLite | HybridReasoningBank | WASM fallback |
| 4 | Search | Basic | GNN-enhanced | +12.4% recall |
| 5 | Coordination | Voting | AttentionCoordinator | Better consensus |
| 6 | Expert routing | None | MoE routing | Smart selection |
| 7 | Learning | Manual | Intelligence bridge | Automatic |
| 8 | Trajectory | None | SONA tracking | Experience replay |
| 9 | Transport | HTTP | QUIC | 5-15x faster |
| 10 | Runtime | Manual | Auto-detection | Zero-config |
See companion document: LEARNING-OPTIMIZED-PLAN.md
| Controller | Purpose | Integration Priority |
|---|---|---|
LearningSystem | 9 RL algorithms | HIGH |
ReflexionMemory | Self-improvement loops | HIGH |
SkillLibrary | Pattern storage | HIGH |
CausalMemoryGraph | Cause-effect reasoning | MEDIUM |
NightlyLearner | Automated discovery | MEDIUM |
AttentionService | FlashAttention | HIGH |
HNSWIndex | 150x faster search | HIGH |
agentic-flow (19 hooks): Intelligence bridge, SONA trajectory, pattern storage agentdb (9 learning): RL sessions, reflexion, skills, causal discovery
Pre-Task → Pattern Retrieval + Skill Lookup + Causal Query
During → SONA Trajectory + Experience Recording
Post-Task → Pattern Storage + Skill Evolution + Causal Discovery
Nightly → FlashAttention Consolidation + A/B Experiments + Transfer Learning
# Minimal install - works on all platforms
npm install claude-flow@3 --save
# ~2MB, no native dependencies, pure JavaScript
Core includes:
# Install components as needed
npx claude-flow install <component>
# Available components:
npx claude-flow install learning # RL + trajectory tracking
npx claude-flow install memory # Persistent memory (SQLite/WASM)
npx claude-flow install attention # Flash/MoE attention mechanisms
npx claude-flow install transport # QUIC transport layer
npx claude-flow install neural # Neural pattern training
npx claude-flow install gnn # GNN query enhancement
npm install claude-flow@3
npx claude-flow install native # NAPI bindings (50-200x faster)
# Total: ~15MB with native bindings
npm install claude-flow@3
npx claude-flow install native # Universal binary
# Fallback: WASM if Rosetta issues
npm install claude-flow@3
npx claude-flow install wasm # WASM backend (recommended)
# Note: NAPI optional but requires build tools
┌─────────────────────────────────────────────────────────────┐
│ CORE (Required) │
│ CLI, Swarm Basics, In-Memory, JS Runtime (~2MB) │
└─────────────────────────────────────────────────────────────┘
│
┌─────────────────────┼─────────────────────┐
│ │ │
▼ ▼ ▼
┌───────────────┐ ┌───────────────┐ ┌───────────────┐
│ memory │ │ learning │ │ attention │
│ SQLite/WASM │ │ RL + SONA │ │ Flash/MoE │
│ (~3MB) │ │ (~2MB) │ │ (~1MB) │
└───────────────┘ └───────────────┘ └───────────────┘
│ │ │
│ ▼ │
│ ┌───────────────┐ │
└───────────▶│ neural │◀─────────────┘
│ Pattern Train │
│ (~2MB) │
└───────────────┘
│
▼
┌───────────────┐
│ gnn │
│ Query Refine │
│ (~4MB) │
└───────────────┘
// Automatic runtime selection (zero config)
const runtimeChain = [
'napi', // Native bindings (fastest)
'wasm', // WebAssembly (portable)
'js' // Pure JavaScript (universal)
];
// Platform detection
const platform = {
linux: { preferred: 'napi', fallback: 'wasm' },
darwin: { preferred: 'napi', fallback: 'wasm' },
win32: { preferred: 'wasm', fallback: 'js' } // WASM default on Windows
};
// .claude-flow/config.json
{
"core": {
"runtime": "auto", // auto | napi | wasm | js
"lazyLoad": true, // Load components on first use
"maxMemoryMB": 512 // Memory limit for caching
},
"components": {
"memory": "enabled", // enabled | disabled | lazy
"learning": "lazy", // Loads when first RL session starts
"attention": "lazy",
"transport": "disabled", // Explicitly disabled
"neural": "lazy",
"gnn": "disabled"
}
}
| Configuration | Size | Platforms | Performance |
|---|---|---|---|
| Core Only | ~2MB | All | Baseline |
| + Memory | ~5MB | All | Persistent storage |
| + Learning | ~7MB | All | RL capabilities |
| + Attention | ~8MB | All | Better consensus |
| Full (JS) | ~15MB | All | Complete features |
| Full (NAPI) | ~25MB | Linux/Mac | Maximum speed |
# Minimal CLI usage
npm install -g claude-flow@3
# Basic swarm coordination
npm install claude-flow@3
# With persistent memory
npm install claude-flow@3 && npx claude-flow install memory
# Full learning system
npm install claude-flow@3 && npx claude-flow install learning memory
# Maximum performance (Linux/Mac)
npm install claude-flow@3 && npx claude-flow install --all --native
┌─────────────┐
│ E2E (5%) │ Cross-platform smoke tests
├─────────────┤
│Integration │ Component interactions
│ (15%) │
├─────────────┤
│ Unit │ Individual functions
│ (80%) │
└─────────────┘
| Test Suite | Linux | macOS Intel | macOS ARM | Windows |
|---|---|---|---|---|
| Core | ✓ | ✓ | ✓ | ✓ |
| NAPI bindings | ✓ | ✓ | ✓ | Optional |
| WASM fallback | ✓ | ✓ | ✓ | ✓ |
| Memory (SQLite) | ✓ | ✓ | ✓ | ✓ |
| Learning (RL) | ✓ | ✓ | ✓ | ✓ |
# Run performance benchmarks
npx claude-flow benchmark
# Specific component benchmarks
npx claude-flow benchmark memory --iterations 1000
npx claude-flow benchmark learning --episodes 100
npx claude-flow benchmark attention --batch-size 32
# Compare runtimes
npx claude-flow benchmark --runtime napi
npx claude-flow benchmark --runtime wasm
npx claude-flow benchmark --runtime js
// Performance thresholds (fail if exceeded)
const thresholds = {
'memory.store': { p95: 10, unit: 'ms' },
'memory.search': { p95: 50, unit: 'ms' },
'learning.predict': { p95: 5, unit: 'ms' },
'attention.forward': { p95: 2, unit: 'ms' },
'startup.cold': { max: 500, unit: 'ms' },
'startup.warm': { max: 100, unit: 'ms' }
};
NAPI fails → WASM fallback → JS fallback → Error with guidance
│ │ │
▼ ▼ ▼
Log warning Log warning Log error
Continue Continue Suggest fix
// Each component fails independently
class ComponentManager {
async loadComponent(name: string): Promise<Component> {
try {
return await this.loadNative(name);
} catch (e) {
console.warn(`Native ${name} unavailable, using WASM`);
try {
return await this.loadWasm(name);
} catch (e) {
console.warn(`WASM ${name} unavailable, using JS`);
return await this.loadJs(name);
}
}
}
}
// Automatic checkpoint and recovery
const learningConfig = {
checkpointInterval: 100, // Save every 100 episodes
maxRetries: 3, // Retry failed operations
rollbackOnCorruption: true, // Auto-rollback if DB corrupted
isolateFailures: true // One session failure doesn't affect others
};
# View real-time metrics
npx claude-flow metrics
# Export metrics for external systems
npx claude-flow metrics --format prometheus
npx claude-flow metrics --format json > metrics.json
| Metric | Description | Alert Threshold |
|---|---|---|
cf_startup_ms | Cold start time | > 1000ms |
cf_memory_mb | Memory usage | > 80% of limit |
cf_component_load_ms | Component load time | > 500ms |
cf_learning_episodes | Total episodes | - |
cf_learning_success_rate | Success percentage | < 50% |
cf_storage_bytes | Disk usage | > 1GB |
// .claude-flow/config.json
{
"logging": {
"level": "info", // error | warn | info | debug | trace
"file": ".claude-flow/logs/claude-flow.log",
"maxSize": "10MB",
"maxFiles": 5,
"components": {
"memory": "warn", // Per-component overrides
"learning": "debug"
}
}
}
# Audit before install
npm audit claude-flow@3
# Verify checksums
npx claude-flow verify --checksums
| Data Type | Storage | Encryption | Retention |
|---|---|---|---|
| Patterns | Local SQLite | Optional | Configurable |
| Trajectories | Local SQLite | Optional | 90 days default |
| Episodes | Local SQLite | Optional | 90 days default |
| Metrics | Local JSON | No | 30 days default |
// .claude-flow/config.json
{
"security": {
"mcpToolAllowlist": [
"swarm_*",
"memory_*",
"learning_*"
],
"mcpToolDenylist": [
"admin_*"
],
"requireConfirmation": [
"learning_transfer",
"memory_delete"
]
}
}
Deep review completed: 2026-01-03 agentic-flow version analyzed: 2.0.1-alpha.50 agentdb version analyzed: 2.0.0-alpha.3.1 Claude-Flow version: 2.7.47