Files
proffesor-for-testing__agen…/docs/architecture/agent-learning-system.html
Profa a25a1c2679 feat(agents): migrate CoverageAnalyzerAgent and QualityGateAgent to BaseAgent for RuVector integration
Phase 0.5: Universal RuVector Integration (v2.5.9)

## Agent Architecture Migration

- **CoverageAnalyzerAgent**: Migrated from EventEmitter to extend BaseAgent
  - Full RuVector integration with HybridRouter support
  - Implements abstract methods: initializeComponents(), performTask(), loadKnowledge(), cleanup()
  - New getCoverageStatus() method for agent-specific status
  - Configuration via CoverageAnalyzerConfig extending BaseAgentConfig

- **QualityGateAgent**: Migrated from EventEmitter to extend BaseAgent
  - Full RuVector integration with HybridRouter support
  - Implements abstract methods: initializeComponents(), performTask(), loadKnowledge(), cleanup()
  - New getQualityGateStatus() method for agent-specific status
  - Configuration via QualityGateConfig extending BaseAgentConfig

## RuVector Methods Now Available on All Agents

All QE agents now inherit these methods from BaseAgent:
- hasRuVectorCache() - Check if RuVector GNN cache is enabled
- getRuVectorMetrics() - Get GNN/LoRA/cache performance metrics
- getCacheHitRate() - Get cache hit rate (0-1)
- getRoutingStats() - Get routing decisions and latency statistics
- forceRuVectorLearn() - Trigger LoRA learning consolidation
- getCostSavingsReport() - Get cost savings from caching
- getLLMStats() - Get LLM provider status including RuVector

## Other Changes

- Updated QEAgentFactory to use new single-config constructor pattern
- Added 6 RuVector MCP tools for external integration
- Updated verification script - All 6 tests pass
- Added BaseAgent.RuVector.test.ts unit tests
- Added ruvector-agent-usage.ts example

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-18 14:58:07 +00:00

1095 lines
71 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Agent Learning System Architecture | Agentic QE</title>
<style>
:root {
--bg-primary: #0d1117;
--bg-secondary: #161b22;
--bg-tertiary: #21262d;
--border-color: #30363d;
--text-primary: #e6edf3;
--text-secondary: #8b949e;
--accent-blue: #58a6ff;
--accent-green: #3fb950;
--accent-purple: #a371f7;
--accent-orange: #d29922;
--accent-red: #f85149;
--accent-cyan: #39c5cf;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
background: var(--bg-primary);
color: var(--text-primary);
line-height: 1.6;
min-height: 100vh;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 2rem;
}
header {
background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
border-bottom: 1px solid var(--border-color);
padding: 3rem 2rem;
text-align: center;
position: relative;
overflow: hidden;
}
header::before {
content: '';
position: absolute;
top: 0;
left: 0;
right: 0;
height: 3px;
background: linear-gradient(90deg, var(--accent-blue), var(--accent-purple), var(--accent-cyan));
}
header h1 {
font-size: 2.5rem;
font-weight: 600;
margin-bottom: 0.5rem;
background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
}
header p {
color: var(--text-secondary);
font-size: 1.1rem;
}
nav {
background: var(--bg-secondary);
border-bottom: 1px solid var(--border-color);
padding: 1rem 2rem;
position: sticky;
top: 0;
z-index: 100;
}
nav ul {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
list-style: none;
justify-content: center;
}
nav a {
color: var(--text-secondary);
text-decoration: none;
padding: 0.5rem 1rem;
border-radius: 6px;
font-size: 0.875rem;
transition: all 0.2s;
}
nav a:hover {
color: var(--text-primary);
background: var(--bg-tertiary);
}
section {
margin: 3rem 0;
padding: 2rem;
background: var(--bg-secondary);
border: 1px solid var(--border-color);
border-radius: 12px;
}
h2 {
font-size: 1.75rem;
font-weight: 600;
margin-bottom: 1.5rem;
padding-bottom: 0.75rem;
border-bottom: 2px solid var(--border-color);
display: flex;
align-items: center;
gap: 0.75rem;
}
h2 .section-number {
display: inline-flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
background: var(--accent-blue);
color: var(--bg-primary);
border-radius: 50%;
font-size: 0.875rem;
font-weight: 700;
}
h3 {
font-size: 1.25rem;
font-weight: 600;
margin: 1.5rem 0 1rem;
color: var(--accent-cyan);
}
h4 {
font-size: 1rem;
font-weight: 600;
margin: 1rem 0 0.5rem;
color: var(--accent-purple);
}
p {
margin-bottom: 1rem;
color: var(--text-secondary);
}
.diagram-container {
background: var(--bg-primary);
border: 1px solid var(--border-color);
border-radius: 8px;
padding: 1.5rem;
margin: 1.5rem 0;
overflow-x: auto;
}
.diagram {
font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
font-size: 0.8rem;
line-height: 1.4;
white-space: pre;
color: var(--text-primary);
}
.diagram .highlight-blue { color: var(--accent-blue); }
.diagram .highlight-green { color: var(--accent-green); }
.diagram .highlight-purple { color: var(--accent-purple); }
.diagram .highlight-orange { color: var(--accent-orange); }
.diagram .highlight-cyan { color: var(--accent-cyan); }
.code-block {
background: var(--bg-primary);
border: 1px solid var(--border-color);
border-radius: 8px;
padding: 1rem 1.5rem;
margin: 1rem 0;
overflow-x: auto;
}
.code-block code {
font-family: 'Fira Code', 'Monaco', 'Consolas', monospace;
font-size: 0.875rem;
color: var(--accent-green);
}
.file-reference {
display: inline-block;
background: var(--bg-tertiary);
padding: 0.25rem 0.75rem;
border-radius: 4px;
font-family: monospace;
font-size: 0.8rem;
color: var(--accent-orange);
margin: 0.25rem 0;
}
table {
width: 100%;
border-collapse: collapse;
margin: 1.5rem 0;
font-size: 0.9rem;
}
th, td {
padding: 0.75rem 1rem;
text-align: left;
border: 1px solid var(--border-color);
}
th {
background: var(--bg-tertiary);
font-weight: 600;
color: var(--text-primary);
}
td {
background: var(--bg-primary);
color: var(--text-secondary);
}
td code {
background: var(--bg-tertiary);
padding: 0.15rem 0.4rem;
border-radius: 3px;
font-size: 0.8rem;
color: var(--accent-cyan);
}
.info-box {
background: linear-gradient(135deg, rgba(88, 166, 255, 0.1), rgba(163, 113, 247, 0.1));
border: 1px solid var(--accent-blue);
border-radius: 8px;
padding: 1rem 1.5rem;
margin: 1rem 0;
}
.info-box.success {
background: linear-gradient(135deg, rgba(63, 185, 80, 0.1), rgba(57, 197, 207, 0.1));
border-color: var(--accent-green);
}
.benefit-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 1.5rem;
margin: 1.5rem 0;
}
.benefit-card {
background: var(--bg-primary);
border: 1px solid var(--border-color);
border-radius: 8px;
padding: 1.5rem;
transition: transform 0.2s, border-color 0.2s;
}
.benefit-card:hover {
transform: translateY(-2px);
border-color: var(--accent-blue);
}
.benefit-card h4 {
margin-top: 0;
display: flex;
align-items: center;
gap: 0.5rem;
}
.benefit-card ul {
margin: 0.5rem 0 0 1.5rem;
color: var(--text-secondary);
}
.benefit-card li {
margin: 0.25rem 0;
}
.flow-step {
display: flex;
align-items: flex-start;
gap: 1rem;
margin: 1rem 0;
padding: 1rem;
background: var(--bg-primary);
border-radius: 8px;
border-left: 3px solid var(--accent-blue);
}
.flow-step .step-number {
flex-shrink: 0;
width: 2rem;
height: 2rem;
display: flex;
align-items: center;
justify-content: center;
background: var(--accent-blue);
color: var(--bg-primary);
border-radius: 50%;
font-weight: 700;
font-size: 0.875rem;
}
.flow-step .step-content h4 {
margin: 0 0 0.5rem 0;
color: var(--text-primary);
}
.flow-step .step-content p {
margin: 0;
font-size: 0.9rem;
}
.tag {
display: inline-block;
padding: 0.2rem 0.5rem;
border-radius: 4px;
font-size: 0.75rem;
font-weight: 600;
margin-right: 0.25rem;
}
.tag.new { background: var(--accent-green); color: var(--bg-primary); }
.tag.key { background: var(--accent-orange); color: var(--bg-primary); }
.tag.phase { background: var(--accent-purple); color: var(--bg-primary); }
footer {
text-align: center;
padding: 2rem;
color: var(--text-secondary);
border-top: 1px solid var(--border-color);
margin-top: 3rem;
}
footer a {
color: var(--accent-blue);
text-decoration: none;
}
@media (max-width: 768px) {
.container { padding: 1rem; }
header { padding: 2rem 1rem; }
header h1 { font-size: 1.75rem; }
section { padding: 1.5rem; }
nav ul { justify-content: flex-start; }
.diagram { font-size: 0.65rem; }
}
</style>
</head>
<body>
<header>
<h1>Agent Learning System Architecture</h1>
<p>Complete Agent Lifecycle with RuvLLM, RuVector, and ReasoningBank Integration</p>
</header>
<nav>
<ul>
<li><a href="#spawning">Agent Spawning</a></li>
<li><a href="#initialization">Initialization</a></li>
<li><a href="#llm-selection">LLM Selection</a></li>
<li><a href="#learning">Learning</a></li>
<li><a href="#pattern-retrieval">Pattern Retrieval</a></li>
<li><a href="#architecture">Architecture</a></li>
<li><a href="#integration">Integration</a></li>
<li><a href="#benefits">Benefits</a></li>
</ul>
</nav>
<div class="container">
<!-- Section 1: Agent Spawning -->
<section id="spawning">
<h2><span class="section-number">1</span> Agent Spawning - Two Entry Points</h2>
<h3>A. Via Claude Code Task Tool</h3>
<div class="diagram-container">
<div class="diagram">User &rarr; Claude Code &rarr; Task Tool &rarr; External Agent Process
&boxur;&boxh;&boxh; Direct CLI execution</div>
</div>
<p>When you use Claude Code's Task tool:</p>
<ul style="margin-left: 1.5rem; color: var(--text-secondary);">
<li>Spawns an external process</li>
<li>Agent runs independently</li>
<li>Hooks notify visualization dashboard</li>
</ul>
<h3>B. Via AQE MCP Tools</h3>
<div class="diagram-container">
<div class="diagram">User &rarr; Claude Code &rarr; MCP Tool &rarr; AgentSpawnHandler &rarr; AgentRegistry &rarr; QEAgentFactory
&boxv; &boxv;
&boxv; &boxur;&boxh; Creates BaseAgentConfig
&boxv; &boxv; &boxur;&boxh; agentType
&boxv; &boxv; &boxur;&boxh; capabilities
&boxv; &boxv; &boxur;&boxh; memoryStore (SHARED) <span class="highlight-orange">&larr; KEY!</span>
&boxv; &boxv; &boxur;&boxh; enableLearning: true
&boxv; &boxv; &boxur;&boxh; learningConfig
&boxv; &boxv;
&boxv; &boxur;&boxh; Creates Agent Instance
&boxv; &boxur;&boxh; TestGeneratorAgent
&boxv; CoverageAnalyzerAgent
&boxv; etc.
&boxv;
&boxur;&boxh; Returns AgentInstance metadata</div>
</div>
<p class="file-reference">Key File: src/mcp/handlers/agent-spawn.ts:56-232</p>
</section>
<!-- Section 2: BaseAgent Initialization -->
<section id="initialization">
<h2><span class="section-number">2</span> BaseAgent Initialization - Multi-Stage Process</h2>
<div class="diagram-container">
<div class="diagram"><span class="highlight-blue">BaseAgent.initialize()</span>
&boxv;
&boxur;&boxh; 1. Load Knowledge (subclass-specific)
&boxv;
&boxur;&boxh; 2. Restore State from Memory
&boxv;
&boxur;&boxh; 3. Create Performance Tracker
&boxv;
&boxur;&boxh; 4. Create LearningEngine &boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; &boxv; &boxv;
&boxv; &boxur;&boxh; Q-Learning Algorithm (default) &boxv;
&boxv; &boxur;&boxh; Q-Table: Map&lt;state, Map&lt;action, reward&gt;&gt; &boxv;
&boxv; &boxur;&boxh; SwarmMemoryManager (SHARED) &boxv;
&boxv; &boxur;&boxh; HNSWPatternAdapter (Phase 0 M0.3) <span class="highlight-cyan">&larr; RuVector!</span> &boxv;
&boxv; &boxv;
&boxur;&boxh; 5. Initialize LLM Provider &boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; &boxv; &boxv;
&boxv; &boxur;&boxh; Selection Priority: &boxv;
&boxv; 1. HybridRouter (if enableHybridRouter: true) <span class="highlight-green">&larr; NEW!</span> &boxv;
&boxv; &boxur;&boxh; Routes: RuVector Cache &rarr; RuvLLM &rarr; Cloud &boxv;
&boxv; 2. RuvLLM (LOCAL - default) <span class="highlight-cyan">&larr; RuvLLM!</span> &boxv;
&boxv; 3. Claude (if ANTHROPIC_API_KEY) &boxv;
&boxv; 4. OpenRouter (if OPENROUTER_API_KEY) &boxv;
&boxv; &boxv;
&boxur;&boxh; 5b. Initialize HybridRouter &boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; &boxv; &boxv;
&boxv; &boxur;&boxh; Create RuVectorClient (GNN cache client) &boxv;
&boxv; &boxur;&boxh; Configure cache threshold (default: 0.85) &boxv;
&boxv; &boxur;&boxh; Enable LoRA learning (rank: 8) &boxv;
&boxv; &boxur;&boxh; Enable EWC++ anti-forgetting &boxv;
&boxv; &boxv;
&boxur;&boxh; 6. Initialize Federated Learning (Phase 0 M0.5) &boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; &boxur;&boxh; Register with FederatedManager &boxv;
&boxv; &boxv;
&boxur;&boxh; 7. Initialize Subclass Components &boxv;
(TestGeneratorAgent &rarr; PatternExtractor, ReasoningBank) &boxv;
&boxv;
&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;
&boxv;
&blacktriangledown;
<span class="highlight-green">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; INITIALIZATION COMPLETE &boxv;
&boxv; &boxv;
&boxv; Agent State: &boxv;
&boxv; &boxur;&boxh; learningEngine: LearningEngine (with Q-table + HNSW) &boxv;
&boxv; &boxur;&boxh; llmProvider: RuvllmProvider (local) OR Claude/OpenRouter &boxv;
&boxv; &boxur;&boxh; hybridRouter: HybridRouter (if enableHybridRouter) &larr; NEW! &boxv;
&boxv; &boxv; &boxur;&boxh; ruvectorClient: RuVectorClient (GNN cache) &boxv;
&boxv; &boxur;&boxh; llmSessionId: "sess-xxx" (for session continuity) &boxv;
&boxv; &boxur;&boxh; federatedManager: FederatedManager (cross-agent learning) &boxv;
&boxv; &boxur;&boxh; memoryStore: SwarmMemoryManager (SQLite .agentic-qe/memory.db) &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span></div>
</div>
<h4>Key Files:</h4>
<p class="file-reference">src/agents/BaseAgent.ts:216-276 (initialize)</p>
<p class="file-reference">src/learning/LearningEngine.ts:107-179 (constructor + init)</p>
<p class="file-reference">src/agents/BaseAgent.ts:668-727 (LLM initialization)</p>
</section>
<!-- Section 3: LLM Provider Selection -->
<section id="llm-selection">
<h2><span class="section-number">3</span> LLM Provider Selection</h2>
<h3>Provider Selection Matrix</h3>
<div class="diagram-container">
<div class="diagram"><span class="highlight-blue">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; LLM PROVIDER SELECTION &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span>
&boxv; &boxv;
&boxv; Environment Check Selected Provider &boxv;
&boxv; &boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh; &boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh; &boxv;
&boxv; &boxv;
&boxv; 1. <span class="highlight-green">enableHybridRouter: true</span> &rArr; <span class="highlight-green">HybridRouter (NEW!)</span> &boxv;
&boxv; (Phase 0.5) &boxur;&boxh; Cache-first routing &boxv;
&boxv; &boxv;
&boxv; 2. LLM_PROVIDER env override &rArr; Use specified provider &boxv;
&boxv; &boxv;
&boxv; 3. Inside Claude Code + &boxv;
&boxv; ANTHROPIC_API_KEY &rArr; <span class="highlight-purple">Claude API</span> &boxv;
&boxv; &boxv;
&boxv; 4. OPENROUTER_API_KEY &rArr; <span class="highlight-orange">OpenRouter (300+ models)</span> &boxv;
&boxv; &boxv;
&boxv; 5. ANTHROPIC_API_KEY &rArr; <span class="highlight-purple">Claude API</span> &boxv;
&boxv; &boxv;
&boxv; 6. RuvLLM available &rArr; <span class="highlight-cyan">RuvLLM (LOCAL, FREE)</span> &boxv;
&boxv; (default for QE agents) &boxv;
&boxv; &boxv;
&boxv; 7. Fallback &rArr; Algorithmic-only mode &boxv;
&boxv; &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</div>
</div>
<h3>HybridRouter with RuVector Cache</h3>
<div class="diagram-container">
<div class="diagram"><span class="highlight-cyan">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; HYBRIDROUTER CACHE-FIRST ROUTING &boxv;
&boxv; (src/providers/HybridRouter.ts) &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span>
&boxv; &boxv;
&boxv; Request Flow: &boxv;
&boxv; &boxv;
&boxv; &boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr; &boxv;
&boxv; &boxv; Agent Request &boxv; prompt + context &boxv;
&boxv; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxv;
&boxv; &boxv; &boxv;
&boxv; &blacktriangledown; &boxv;
&boxv; <span class="highlight-green">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> &boxv;
&boxv; <span class="highlight-green">&boxv; 1. RuVector &boxv;</span> GNN cache lookup &boxv;
&boxv; <span class="highlight-green">&boxv; Cache &boxv;</span> - Sub-ms latency (&lt;1ms) &boxv;
&boxv; <span class="highlight-green">&boxv; (Docker) &boxv;</span> - 0.85 confidence threshold &boxv;
&boxv; <span class="highlight-green">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> - If HIT &rarr; return cached response &boxv;
&boxv; &boxv; <span class="highlight-orange">MISS</span> &boxv;
&boxv; &blacktriangledown; &boxv;
&boxv; <span class="highlight-cyan">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> &boxv;
&boxv; <span class="highlight-cyan">&boxv; 2. RuvLLM &boxv;</span> Local inference &boxv;
&boxv; <span class="highlight-cyan">&boxv; (Local) &boxv;</span> - Zero cost &boxv;
&boxv; <span class="highlight-cyan">&boxv; &boxv;</span> - TRM/SONA enabled &boxv;
&boxv; <span class="highlight-cyan">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> - Cache response for future &boxv;
&boxv; &boxv; <span class="highlight-orange">UNAVAILABLE</span> &boxv;
&boxv; &blacktriangledown; &boxv;
&boxv; <span class="highlight-purple">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> &boxv;
&boxv; <span class="highlight-purple">&boxv; 3. Cloud LLM &boxv;</span> Claude/OpenRouter fallback &boxv;
&boxv; <span class="highlight-purple">&boxv; (Remote) &boxv;</span> - Higher quality &boxv;
&boxv; <span class="highlight-purple">&boxv; &boxv;</span> - Cache response + trigger learning &boxv;
&boxv; <span class="highlight-purple">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> &boxv;
&boxv; &boxv;
&boxv; <span class="highlight-blue">Learning Features:</span> &boxv;
&boxv; &boxur;&boxh; LoRA: Low-rank adaptation (rank: 8, alpha: 16) &boxv;
&boxv; &boxur;&boxh; EWC++: Elastic Weight Consolidation (anti-forgetting) &boxv;
&boxv; &boxur;&boxh; GNN: Graph Neural Network pattern matching &boxv;
&boxv; &boxv;
&boxv; <span class="highlight-green">Cost Savings:</span> &boxv;
&boxv; &boxur;&boxh; Cache hits: ~$0.00 per request &boxv;
&boxv; &boxur;&boxh; Local LLM: ~$0.00 per request &boxv;
&boxv; &boxur;&boxh; Cloud only when necessary &boxv;
&boxv; &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</div>
</div>
<h3>RuvLLM Features</h3>
<div class="diagram-container">
<div class="diagram"><span class="highlight-purple">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; RUVLLM PROVIDER &boxv;
&boxv; (src/providers/RuvllmProvider.ts) &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span>
&boxv; &boxv;
&boxv; <span class="highlight-green">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> &boxv;
&boxv; <span class="highlight-green">&boxv; TRM (Test-time &boxv;</span> Iterative reasoning refinement &boxv;
&boxv; <span class="highlight-green">&boxv; Reasoning & &boxv;</span> - Up to 7 iterations &boxv;
&boxv; <span class="highlight-green">&boxv; Metacognition) &boxv;</span> - Converges at 95% confidence &boxv;
&boxv; <span class="highlight-green">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> - Improves output quality &boxv;
&boxv; &boxv; &boxv;
&boxv; <span class="highlight-cyan">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&blacktriangledown;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> &boxv;
&boxv; <span class="highlight-cyan">&boxv; SONA (Self- &boxv;</span> Continuous model adaptation &boxv;
&boxv; <span class="highlight-cyan">&boxv; Organizing &boxv;</span> - LoRA rank: 8, alpha: 16 &boxv;
&boxv; <span class="highlight-cyan">&boxv; Neural Arch) &boxv;</span> - EWC lambda: 2000 &boxv;
&boxv; <span class="highlight-cyan">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> - Prevents catastrophic forgetting &boxv;
&boxv; &boxv; &boxv;
&boxv; <span class="highlight-orange">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&blacktriangledown;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> &boxv;
&boxv; <span class="highlight-orange">&boxv; Sessions &boxv;</span> Multi-turn context preservation &boxv;
&boxv; <span class="highlight-orange">&boxv; &boxv;</span> - 50% latency reduction &boxv;
&boxv; <span class="highlight-orange">&boxv; &boxv;</span> - Context reuse across calls &boxv;
&boxv; <span class="highlight-orange">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> - Session timeout: 30 min &boxv;
&boxv; &boxv; &boxv;
&boxv; <span class="highlight-blue">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&blacktriangledown;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> &boxv;
&boxv; <span class="highlight-blue">&boxv; Batch API &boxv;</span> Parallel request processing &boxv;
&boxv; <span class="highlight-blue">&boxv; &boxv;</span> - 4x throughput &boxv;
&boxv; <span class="highlight-blue">&boxv; &boxv;</span> - Rate limiting protection &boxv;
&boxv; <span class="highlight-blue">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> &boxv;
&boxv; &boxv;
&boxv; Default Model: llama-3.2-3b-instruct &boxv;
&boxv; Port: 8080 &boxv;
&boxv; Context Size: 4096 &boxv;
&boxv; &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</div>
</div>
<h3>When LLM is Called During Task Execution</h3>
<div class="flow-step">
<span class="step-number">1</span>
<div class="step-content">
<h4>Phase 1: Code Analysis</h4>
<p><code>analyzeCodeWithConsciousness()</code> - May use LLM for analysis</p>
</div>
</div>
<div class="flow-step">
<span class="step-number">2</span>
<div class="step-content">
<h4>Phase 2: Pattern Retrieval <span class="tag">NO LLM</span></h4>
<p><code>findApplicablePatterns()</code> - Uses HNSW vector search O(log n), &lt;1ms p95</p>
</div>
</div>
<div class="flow-step">
<span class="step-number">3</span>
<div class="step-content">
<h4>Phase 3: Pattern Recognition</h4>
<p><code>recognizePatterns()</code> - May use LLM</p>
</div>
</div>
<div class="flow-step">
<span class="step-number">4</span>
<div class="step-content">
<h4>Phase 4: Test Strategy Selection <span class="tag">NO LLM</span></h4>
<p><code>selectTestStrategy()</code> - Algorithmic, no LLM</p>
</div>
</div>
<div class="flow-step">
<span class="step-number">5</span>
<div class="step-content">
<h4>Phase 5: Test Generation <span class="tag key">LLM CALLED</span></h4>
<p><code>generateUnitTests()</code>, <code>generateIntegrationTests()</code>, <code>generateEdgeCaseTests()</code> - LLM called via <code>this.llmChat(prompt)</code></p>
</div>
</div>
<div class="flow-step">
<span class="step-number">6</span>
<div class="step-content">
<h4>Phase 6: Test Optimization <span class="tag">NO LLM</span></h4>
<p><code>optimizeTestSelection()</code> - Algorithmic</p>
</div>
</div>
<div class="flow-step">
<span class="step-number">7</span>
<div class="step-content">
<h4>Phase 7: Pattern Extraction & Storage</h4>
<p>Extracts patterns for future reuse via <code>this.llmEmbed()</code> for embedding generation</p>
</div>
</div>
<p class="file-reference">Key File: src/agents/TestGeneratorAgent.ts:390-666 (generateTestsWithAI)</p>
</section>
<!-- Section 4: Learning from Execution -->
<section id="learning">
<h2><span class="section-number">4</span> Learning from Execution</h2>
<p class="file-reference">src/learning/LearningEngine.ts:227-345</p>
<h3>1. Extract Experience</h3>
<div class="code-block">
<code>TaskExperience {
state: encode(complexity, capabilities, resources)
action: encode(strategy, parallelization, retry)
reward: calculated from results
nextState: updated state
timestamp: when executed
}</code>
</div>
<h4>Reward Calculation</h4>
<table>
<tr><th>Condition</th><th>Reward</th></tr>
<tr><td>Success</td><td><code>+1.0</code></td></tr>
<tr><td>Failure</td><td><code>-1.0</code></td></tr>
<tr><td>Fast execution</td><td><code>+0.2 bonus</code></td></tr>
<tr><td>Errors</td><td><code>-0.3 penalty</code></td></tr>
<tr><td>Coverage (test gen)</td><td><code>+0.5 bonus</code></td></tr>
<tr><td>User feedback</td><td><code>-1 to +1</code></td></tr>
<tr><td colspan="2">Final: clamp to [-2, +2]</td></tr>
</table>
<h3>2. Update Q-Table (Q-Learning Algorithm)</h3>
<div class="info-box">
<p style="font-family: monospace; font-size: 1.1rem; color: var(--text-primary); margin: 0;">
Q(s,a) &larr; Q(s,a) + &alpha;[r + &gamma;&middot;max(Q(s',a')) - Q(s,a)]
</p>
</div>
<table>
<tr><th>Variable</th><th>Meaning</th><th>Value</th></tr>
<tr><td>&alpha;</td><td>Learning rate</td><td><code>0.1</code></td></tr>
<tr><td>&gamma;</td><td>Discount factor</td><td><code>0.95</code></td></tr>
<tr><td>s</td><td>Current state</td><td>-</td></tr>
<tr><td>a</td><td>Action taken</td><td>-</td></tr>
<tr><td>r</td><td>Reward received</td><td>-</td></tr>
<tr><td>s'</td><td>Next state</td><td>-</td></tr>
</table>
<p>Persisted to: SwarmMemoryManager &rarr; q_values table</p>
<h3>3. Update Patterns (Dual Storage)</h3>
<div class="diagram-container">
<div class="diagram">Pattern Update:
&boxur;&boxh; usageCount++
&boxur;&boxh; successRate = (old * count + result) / (count + 1)
&boxur;&boxh; confidence = min(0.95, confidence + 0.01)
<span class="highlight-blue">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; DUAL STORAGE &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span>
&boxv; &boxv;
&boxv; <span class="highlight-orange">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> <span class="highlight-cyan">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> &boxv;
&boxv; <span class="highlight-orange">&boxv; SQLite &boxv;</span> <span class="highlight-cyan">&boxv; HNSW (RuVector) &boxv;</span> &boxv;
&boxv; <span class="highlight-orange">&boxv; (Primary) &boxv;</span> <span class="highlight-cyan">&boxv; (Vector Search) &boxv;</span> &boxv;
&boxv; <span class="highlight-orange">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> <span class="highlight-cyan">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> &boxv;
&boxv; &boxv; &boxv; &boxv; &boxv; &boxv;
&boxv; &boxv; patterns table &boxv; &boxv; O(log n) search &boxv; &boxv;
&boxv; &boxv; q_values table &boxv; &boxv; &lt;1ms p95 latency &boxv; &boxv;
&boxv; &boxv; experiences &boxv; &boxv; 768-dim embeddings &boxv; &boxv;
&boxv; &boxv; &boxv; &boxv; &boxv; &boxv;
&boxv; &boxv; .agentic-qe/ &boxv; &boxv; In-memory index &boxv; &boxv;
&boxv; &boxv; memory.db &boxv; &boxv; &boxv; &boxv;
&boxv; &boxv; &boxv; &boxv; &boxv; &boxv;
&boxv; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxv;
&boxv; &boxv; &boxv; &boxv;
&boxv; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxv;
&boxv; &boxv; &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;
&boxv;
&blacktriangledown;
<span class="highlight-green">SHARED ACROSS ALL AGENTS</span>
(Single source of truth)</div>
</div>
<h3>4. Exploration Decay</h3>
<div class="info-box success">
<p style="font-family: monospace; margin: 0; color: var(--text-primary);">
explorationRate *= 0.995
</p>
<p style="margin: 0.5rem 0 0 0;">
0.30 (start) &rarr; &rarr; &rarr; &rarr; &rarr; &rarr; &rarr; &rarr; 0.01 (min)<br>
Over ~1000 tasks: EXPLORING &rarr; EXPLOITING
</p>
</div>
<h3>5. Federated Sharing (Optional)</h3>
<ul style="margin-left: 1.5rem; color: var(--text-secondary);">
<li>Generate embedding for pattern</li>
<li>Calculate priority from reward</li>
<li>Share with FederatedManager</li>
<li>Other agents can <code>syncWithTeam()</code> to get shared patterns</li>
</ul>
</section>
<!-- Section 5: Pattern Retrieval -->
<section id="pattern-retrieval">
<h2><span class="section-number">5</span> Pattern Retrieval During Future Tasks</h2>
<div class="flow-step">
<span class="step-number">1</span>
<div class="step-content">
<h4>Extract Code Signature</h4>
<div class="code-block">
<code>codeSignature = {
functionName: "createUser"
complexity: "medium"
patterns: ["service", "async", "validation"]
}</code>
</div>
</div>
</div>
<div class="flow-step">
<span class="step-number">2</span>
<div class="step-content">
<h4>Query HNSW (O(log n) Vector Search)</h4>
<div class="code-block">
<code>learningEngine.searchSimilarPatterns("createUser test")
&darr;
hnswAdapter.searchSimilar(query, k=5)
&darr;
1. Generate query embedding (RuvLLM or hash fallback)
2. Search HNSW index (O(log n), &lt;1ms)
3. Return top-k similar patterns
Results:
&boxur;&boxh; Pattern: "service-async-test" (similarity: 0.92)
&boxur;&boxh; Pattern: "validation-test" (similarity: 0.87)
&boxur;&boxh; Pattern: "crud-service-test" (similarity: 0.81)</code>
</div>
</div>
</div>
<div class="flow-step">
<span class="step-number">3</span>
<div class="step-content">
<h4>Apply Patterns (Reduce LLM Calls)</h4>
<p>For each high-confidence pattern (applicability &gt; 0.7):</p>
<ul style="margin-left: 1.5rem; color: var(--text-secondary);">
<li>Use pattern template for test structure</li>
<li>Customize with code-specific details</li>
<li>SKIP LLM call for template portions</li>
</ul>
</div>
</div>
<div class="info-box success">
<h4 style="margin: 0 0 0.5rem 0; color: var(--accent-green);">Performance Comparison</h4>
<table style="margin: 0;">
<tr>
<td><strong>WITHOUT PATTERNS:</strong></td>
<td>10 tests &rarr; 10 LLM calls &rarr; ~5000ms</td>
</tr>
<tr>
<td><strong>WITH PATTERNS:</strong></td>
<td>7 from patterns + 3 LLM calls &rarr; ~2000ms</td>
</tr>
<tr>
<td colspan="2" style="color: var(--accent-green);"><strong>60% faster, 70% cost reduction</strong></td>
</tr>
</table>
</div>
</section>
<!-- Section 6: Complete Data Flow Architecture -->
<section id="architecture">
<h2><span class="section-number">6</span> Complete Data Flow Architecture</h2>
<div class="diagram-container">
<div class="diagram"> <span class="highlight-blue">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span>
<span class="highlight-blue">&boxv; USER REQUEST &boxv;</span>
<span class="highlight-blue">&boxv; "Generate tests for X.ts" &boxv;</span>
<span class="highlight-blue">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span>
&boxv;
&blacktriangledown;
<span class="highlight-purple">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span>
<span class="highlight-purple">&boxv; CLAUDE CODE &boxv;</span>
<span class="highlight-purple">&boxv; (Orchestrator / Interface) &boxv;</span>
<span class="highlight-purple">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span>
&boxv;
&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&btee;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; &boxv;
&blacktriangledown; &blacktriangledown;
<span class="highlight-green">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> <span class="highlight-orange">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span>
<span class="highlight-green">&boxv; MCP Tools &boxv;</span> <span class="highlight-orange">&boxv; Task Tool &boxv;</span>
<span class="highlight-green">&boxv; (aqe-mcp server) &boxv;</span> <span class="highlight-orange">&boxv; (direct spawn) &boxv;</span>
<span class="highlight-green">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> <span class="highlight-orange">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span>
&boxv; &boxv;
&blacktriangledown; &boxv;
<span class="highlight-cyan">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> &boxv;
<span class="highlight-cyan">&boxv; AgentRegistry &boxv;</span> &boxv;
<span class="highlight-cyan">&boxv; &boxur;&boxh; Shared Memory &boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&btee;</span>
<span class="highlight-cyan">&boxv; &boxur;&boxh; Creates Config &boxv;</span> &boxv;
<span class="highlight-cyan">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> &boxv;
&boxv; &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;
&boxv;
&blacktriangledown;
<span class="highlight-blue">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span>
<span class="highlight-blue">&boxv; QE AGENT (BaseAgent) &boxv;</span>
<span class="highlight-blue">&boxv; &boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr; &boxv;</span>
<span class="highlight-blue">&boxv; &boxv; TestGeneratorAgent &boxv; &boxv;</span>
<span class="highlight-blue">&boxv; &boxv; CoverageAnalyzerAgent &boxv; &boxv;</span>
<span class="highlight-blue">&boxv; &boxv; SecurityScannerAgent &boxv; &boxv;</span>
<span class="highlight-blue">&boxv; &boxv; etc. &boxv; &boxv;</span>
<span class="highlight-blue">&boxv; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxv;</span>
<span class="highlight-blue">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&caret;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span>
&boxv;
&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&btee;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;
&boxv; &boxv; &boxv;
&blacktriangledown; &blacktriangledown; &blacktriangledown;
<span class="highlight-purple">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> <span class="highlight-cyan">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span> <span class="highlight-orange">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span>
<span class="highlight-purple">&boxv; LLM Provider &boxv;</span> <span class="highlight-cyan">&boxv; Learning Engine &boxv;</span> <span class="highlight-orange">&boxv; Memory Store &boxv;</span>
<span class="highlight-purple">&boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv;</span> <span class="highlight-orange">&boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr; &boxv;</span> <span class="highlight-cyan">&boxv; &boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr; &boxv;</span> <span class="highlight-orange">&boxv; &boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr; &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; RuvLLM &boxv; &boxv;</span>&larr;&rarr;<span class="highlight-cyan">&boxv;&rArr;&boxv; Q-Table &boxv; &boxv;</span>&larr;&rarr;<span class="highlight-orange">&boxv;&rArr;&boxv; SQLite DB &boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; (LOCAL) &boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv; Algorithm &boxv; &boxv;</span> <span class="highlight-orange">&boxv; &boxv; patterns &boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; &boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv; &boxv; &boxv;</span> <span class="highlight-orange">&boxv; &boxv; q_values &boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; &boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr; &boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxv;</span> <span class="highlight-orange">&boxv; &boxv; experiences &boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; &boxv; TRM &boxv; &boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv;</span> <span class="highlight-orange">&boxv; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; &boxv; SONA &boxv; &boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr; &boxv;</span> <span class="highlight-orange">&boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; &boxv; Session &boxv; &boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv; HNSW &boxv; &boxv;</span> <span class="highlight-orange">&boxv; .agentic-qe/ &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; &boxv; Batch &boxv; &boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv; Adapter &boxv; &boxv;</span>&larr;&rarr;<span class="highlight-orange">&boxv;&rArr;memory.db &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv; (RuVector) &boxv; &boxv;</span> <span class="highlight-orange">&boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxv;</span> <span class="highlight-cyan">&boxv; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxv;</span> <span class="highlight-orange">&boxv; SHARED ACROSS &boxv;</span>
<span class="highlight-purple">&boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv;</span> <span class="highlight-orange">&boxv; ALL AGENTS &boxv;</span>
<span class="highlight-purple">&boxv; OR &boxv;</span> <span class="highlight-cyan">&boxv; Federated &boxv;</span> <span class="highlight-orange">&boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxv;</span> <span class="highlight-cyan">&boxv; Learning &boxv;</span> <span class="highlight-orange">&boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr; &boxv;</span> <span class="highlight-cyan">&boxv; (cross-agent) &boxv;</span> <span class="highlight-orange">&boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; Claude &boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv;</span> <span class="highlight-orange">&boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxv; OpenRouter &boxv; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv;</span> <span class="highlight-orange">&boxv; &boxv;</span>
<span class="highlight-purple">&boxv; &boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul; &boxv;</span> <span class="highlight-cyan">&boxv; &boxv;</span> <span class="highlight-orange">&boxv; &boxv;</span>
<span class="highlight-purple">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> <span class="highlight-cyan">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span> <span class="highlight-orange">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span>
&boxv; &boxv; &boxv;
&boxv; &boxv; &boxv;
&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&btee;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;
&boxv;
&blacktriangledown;
<span class="highlight-green">&boxdr;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxdr;</span>
<span class="highlight-green">&boxv; TASK RESULT &boxv;</span>
<span class="highlight-green">&boxv; TestSuite, Coverage Report, &boxv;</span>
<span class="highlight-green">&boxv; Quality Metrics, etc. &boxv;</span>
<span class="highlight-green">&boxur;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxh;&boxul;</span></div>
</div>
</section>
<!-- Section 7: Ruv Solutions Integration -->
<section id="integration">
<h2><span class="section-number">7</span> Ruv Solutions Integration Summary</h2>
<table>
<thead>
<tr>
<th>Solution</th>
<th>Component</th>
<th>Purpose</th>
<th>Location</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>RuvLLM</strong></td>
<td><code>RuvllmProvider</code></td>
<td>Local LLM inference with TRM/SONA/Sessions</td>
<td><code>src/providers/RuvllmProvider.ts</code></td>
</tr>
<tr>
<td><strong>RuVector</strong></td>
<td><code>HNSWPatternStore</code></td>
<td>O(log n) vector similarity search</td>
<td><code>src/memory/HNSWPatternStore.ts</code></td>
</tr>
<tr>
<td><strong>RuVector</strong></td>
<td><code>HNSWPatternAdapter</code></td>
<td>Bridge to LearningEngine</td>
<td><code>src/learning/HNSWPatternAdapter.ts</code></td>
</tr>
<tr>
<td><strong>RuVector</strong></td>
<td><code>HybridRouter</code></td>
<td>Cache-first routing</td>
<td><code>src/providers/HybridRouter.ts</code></td>
</tr>
<tr>
<td><strong>RuVector</strong></td>
<td><code>RuVectorClient</code></td>
<td>GNN cache client with LoRA/EWC++</td>
<td><code>src/providers/RuVectorClient.ts</code></td>
</tr>
<tr>
<td><strong>@ruvector/core</strong></td>
<td>VectorDB</td>
<td>HNSW index implementation</td>
<td><code>node_modules/@ruvector/core</code></td>
</tr>
<tr>
<td><strong>AgentDB</strong></td>
<td><code>ReasoningBank</code></td>
<td>Pattern storage and retrieval</td>
<td><code>node_modules/agentdb</code></td>
</tr>
</tbody>
</table>
<h3>Agent RuVector Methods</h3>
<p>All QE agents that extend <code>BaseAgent</code> have access to:</p>
<h4>Metrics & Status Methods</h4>
<table>
<tr><th>Method</th><th>Return</th><th>Description</th></tr>
<tr><td><code>hasRuVectorCache()</code></td><td><code>boolean</code></td><td>Check if HybridRouter with RuVector cache is enabled</td></tr>
<tr><td><code>getRuVectorMetrics()</code></td><td><code>Promise&lt;object | null&gt;</code></td><td>Get GNN/LoRA/cache metrics from RuVector</td></tr>
<tr><td><code>getCacheHitRate()</code></td><td><code>number</code></td><td>Get cache hit rate (0-1)</td></tr>
<tr><td><code>getRoutingStats()</code></td><td><code>object</code></td><td>Get routing decisions & latencies</td></tr>
<tr><td><code>getCostSavingsReport()</code></td><td><code>object</code></td><td>Get cost savings from cache and local routing</td></tr>
<tr><td><code>getLLMStats()</code></td><td><code>object</code></td><td>Get LLM provider status including RuVector</td></tr>
</table>
<h4>Learning Methods</h4>
<table>
<tr><th>Method</th><th>Return</th><th>Description</th></tr>
<tr><td><code>forceRuVectorLearn()</code></td><td><code>Promise&lt;{success, ...}&gt;</code></td><td>Trigger LoRA consolidation with EWC++</td></tr>
</table>
<h4>MCP Tools for RuVector</h4>
<table>
<tr><th>Tool Name</th><th>Description</th></tr>
<tr><td><code>ruvector_health</code></td><td>Check RuVector Docker health</td></tr>
<tr><td><code>ruvector_metrics</code></td><td>Get GNN/LoRA/cache metrics</td></tr>
<tr><td><code>ruvector_force_learn</code></td><td>Trigger LoRA consolidation</td></tr>
<tr><td><code>ruvector_store_pattern</code></td><td>Store pattern in GNN cache</td></tr>
<tr><td><code>ruvector_search</code></td><td>Search similar patterns</td></tr>
<tr><td><code>ruvector_cost_savings</code></td><td>Get cost savings report</td></tr>
</table>
<h4>Usage Example</h4>
<div class="code-block">
<code>// Configure agent with HybridRouter
const agent = new TestGeneratorAgent({
type: 'test-generator',
capabilities: [...],
context: {...},
memoryStore,
eventBus,
llm: {
enabled: true,
enableHybridRouter: true, // Enable Phase 0.5 features
ruvectorCache: {
baseUrl: 'http://localhost:8080',
cacheThreshold: 0.85,
learningEnabled: true,
loraRank: 8,
ewcEnabled: true,
},
},
});
// Check cache status
console.log('RuVector enabled:', agent.hasRuVectorCache());
console.log('Cache hit rate:', agent.getCacheHitRate());
// Get cost savings
const savings = agent.getCostSavingsReport();
console.log(`Saved: $${savings.savings} (${savings.savingsPercentage}%)`);
// Trigger learning
const result = await agent.forceRuVectorLearn();
console.log('Learning result:', result);</code>
</div>
</section>
<!-- Section 8: Benefits -->
<section id="benefits">
<h2><span class="section-number">8</span> Benefits of This Architecture</h2>
<div class="benefit-grid">
<div class="benefit-card">
<h4><span style="color: var(--accent-green);">$</span> Reduced LLM Costs</h4>
<ul>
<li>Pattern templates reduce LLM calls by up to 70%</li>
<li>Local RuvLLM provides zero-cost inference</li>
<li>Session reuse cuts latency by 50%</li>
<li>HybridRouter cache-first routing further reduces cloud calls</li>
</ul>
</div>
<div class="benefit-card">
<h4><span style="color: var(--accent-cyan);">↑</span> Continuous Improvement</h4>
<ul>
<li>Q-learning optimizes strategy selection</li>
<li>Patterns improve with each successful task</li>
<li>Federated learning shares knowledge across agents</li>
<li>LoRA + EWC++ enables continuous self-learning</li>
</ul>
</div>
<div class="benefit-card">
<h4><span style="color: var(--accent-blue);">⚡</span> Fast Pattern Retrieval</h4>
<ul>
<li>HNSW provides O(log n) vector search</li>
<li>&lt;1ms p95 latency for pattern matching</li>
<li>Scales to millions of patterns</li>
<li>Phase 0.5: GNN cache provides sub-ms pattern matching</li>
</ul>
</div>
<div class="benefit-card">
<h4><span style="color: var(--accent-purple);">🗄</span> Unified Data Store</h4>
<ul>
<li>Single SQLite database prevents fragmentation</li>
<li>All agents share learned patterns</li>
<li>CLI, MCP, and direct spawning all contribute</li>
<li>RuVector Docker provides distributed cache layer</li>
</ul>
</div>
<div class="benefit-card">
<h4><span style="color: var(--accent-orange);">↓</span> Graceful Degradation</h4>
<ul>
<li>If LLM unavailable &rarr; algorithmic fallback</li>
<li>If HNSW fails &rarr; SQLite-only mode</li>
<li>If patterns unavailable &rarr; full LLM generation</li>
<li>If RuVector unavailable &rarr; fallback to RuvLLM &rarr; Cloud</li>
</ul>
</div>
</div>
</section>
</div>
<footer>
<p>Agent Learning System Architecture &mdash; Agentic QE Fleet</p>
<p>Documentation: <a href="https://github.com/ruvnet/agentic-qe">GitHub Repository</a></p>
</footer>
</body>
</html>