summaryrefslogtreecommitdiff
path: root/docs/research/claude-flow-research.md
blob: 479691a58b89e3ed573d49b328974900fea2e480 (plain) (blame)
1
2
3
4
5
6
7
8
9
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Claude-Flow (Ruflo v3) Research Summary

> Research conducted 2026-02-24 for makima improvement evaluation

## Overview

claude-flow (marketed as Ruflo v3) is an enterprise AI orchestration system built around Claude Code. It provides 175+ MCP tools, manages 60+ specialized agents, and has accumulated 5,923+ commits. Key performance claims: 84.8% SWE-Bench solve rate, 2.8-4.4x faster task completion vs baseline Claude Code.

**Repository**: https://github.com/ruvnet/claude-flow

## Architecture

### Layered Design
```
User Layer:       CLI + Claude Code interfaces
Entry Layer:      MCP Server with AIDefence security validation
Routing Layer:    Q-Learning router + MoE (8 experts) + 42 skills + 17 hooks
Swarm Layer:      Topologies (mesh/hierarchical/ring/star) + consensus
Agent Layer:      60+ specialized agents
Resources:        Memory systems, LLM providers, 12 background workers
Intelligence:     RuVector with 10+ optimization components
```

### MCP Integration
- Runs as stdio process providing 175+ tools
- MCP 2025-11-25 full specification compliance
- Supports tools, resources, prompts, and tasks
- Multiple transports: stdio, HTTP, WebSocket, in-process

## Multi-Agent Coordination (Hive Mind)

### Queen Types (Coordinators)
| Type | Role |
|------|------|
| Strategic | Planning and goal decomposition |
| Tactical | Execution coordination |
| Adaptive | Optimization and learning |

### Worker Types (8 Specialized Roles)
1. **Researcher** - Information gathering and analysis
2. **Coder** - Implementation
3. **Analyst** - Data analysis and insights
4. **Tester** - Quality assurance
5. **Architect** - System design
6. **Reviewer** - Code review and quality gates
7. **Optimizer** - Performance tuning
8. **Documenter** - Documentation generation

### Consensus Algorithms
- **Byzantine** (f < n/3): 2/3 majority for decisions
- **Weighted Voting**: Queen has 3x authority
- **Majority Voting**: Simple democratic decisions

## Task Routing & Scheduling

### Q-Learning Router
- Combined with MoE (8 experts)
- 89% routing accuracy
- 34,798 routes/s throughput
- Learns which agents perform best per task type through execution trajectories

### Three-Tier Routing Strategy
| Tier | Handler | Latency | Cost |
|------|---------|---------|------|
| Simple | Agent Booster WASM | <1ms | $0 |
| Medium | Haiku/Sonnet | ~500ms | Low |
| Complex | Opus + multi-agent swarms | 2-5s | Standard |

### Task Templates (Agent Combinations)
| Task Type | Recommended Agents |
|-----------|--------------------|
| Bug Fix | Coordinator, Researcher, Coder, Tester |
| Feature | Coordinator, Architect, Coder, Tester, Reviewer |
| Refactor | Coordinator, Architect, Coder, Reviewer |
| Performance | Coordinator, Perf-Engineer, Coder |
| Security | Coordinator, Security-Architect, Auditor |

## Self-Learning Mechanisms

### SONA (Self-Optimizing Neural Architecture)
- <0.05ms adaptation time
- Rapid behavior adjustment at runtime
- Two-tier LoRA + EWC++ + ReasoningBank integration

### EWC++ (Elastic Weight Consolidation)
- Preserves 95%+ knowledge across tasks
- Prevents catastrophic forgetting

### ReasoningBank
- Pattern caching with RETRIEVE → JUDGE → DISTILL → CONSOLIDATE → ROUTE cycle
- 32% token savings through pattern retrieval instead of full context
- Stores successful execution trajectories for reuse

### MicroLoRA
- 128x compressed fine-tuning
- No full retraining required
- Lightweight runtime adaptation

## Memory & Context Sharing

### 3-Scope Architecture
| Scope | Purpose |
|-------|---------|
| Project | Task-specific context |
| Local | Machine/user patterns |
| User | Cross-project learnings |

### Storage Stack
- **HNSW Vector Search**: 150x-12,500x faster retrieval, 16,400 QPS
- **AgentDB**: SQLite with WAL for persistence
- **LRU Cache**: Sub-millisecond access for hot data
- **Knowledge Graph**: PageRank + community detection for insight ranking

### 8 Memory Types
Attention, episodic, procedural, semantic, + 4 additional types for comprehensive knowledge representation.

## Drift Control

Critical for multi-agent alignment:
1. **Hierarchical Coordinator** validates all outputs against goals
2. **Small Teams** (6-8 agents) reduce coordination overhead
3. **Frequent Checkpoints** via post-task hooks verify compliance
4. **Raft Consensus** maintains authoritative state
5. **Specialized Roles** enforce clear task boundaries

## Cost Optimization

### Multi-Layer Strategy
| Layer | Mechanism | Savings |
|-------|-----------|---------|
| 1 | Agent Booster WASM | Eliminates tokens entirely |
| 2 | Haiku/Sonnet routing | 75% lower than Opus |
| 3 | ReasoningBank | -32% token savings |
| 4 | Token compression | 30-50% reduction |
| 5 | Caching | 95% hit rate |
| **Combined** | **All layers** | **Extends Claude Max 250%** |

## Hook System

33+ hooks across 7 categories:
- **Session**: start, end
- **Agent**: pre-spawn, post-spawn, pre-terminate
- **Task**: pre-execute, post-complete, error
- **Tool**: pre-call, post-call
- **Memory**: store/retrieve operations
- **Swarm**: coordination events
- **File**: read/write operations

Self-Learning Hooks feed execution insights back into the Q-Learning router.

## Claims System (Human-Agent Coordination)
- **Claim**: Agent requests task ownership
- **Release**: Agent returns uncompleted work
- **Handoff**: Human reassigns to different agent
- Prevents duplicate effort and maintains clear responsibility

## Fault Tolerance
- Byzantine fault-tolerant (f < n/3, 2/3 majority)
- 6 LLM provider failover (Claude, GPT, Gemini, etc.)
- Checkpoint system prevents cascading failures
- Persist/Restore/Export session management

## Swarm Topologies
| Topology | Structure | Best For |
|----------|-----------|----------|
| Hierarchical | Coordinator + workers | Structured coding tasks (0.20s, 256MB/agent) |
| Mesh | Peer-to-peer | Collaborative, high redundancy |
| Ring | Sequential chain | Pipeline processing |
| Star | Hub-and-spoke | Centralized control |