Complete Agent Lifecycle with RuvLLM, RuVector, and ReasoningBank Integration
When you use Claude Code's Task tool:
Key File: src/mcp/handlers/agent-spawn.ts:56-232
src/agents/BaseAgent.ts:216-276 (initialize)
src/learning/LearningEngine.ts:107-179 (constructor + init)
src/agents/BaseAgent.ts:668-727 (LLM initialization)
analyzeCodeWithConsciousness() - May use LLM for analysis
findApplicablePatterns() - Uses HNSW vector search O(log n), <1ms p95
recognizePatterns() - May use LLM
selectTestStrategy() - Algorithmic, no LLM
generateUnitTests(), generateIntegrationTests(), generateEdgeCaseTests() - LLM called via this.llmChat(prompt)
optimizeTestSelection() - Algorithmic
Extracts patterns for future reuse via this.llmEmbed() for embedding generation
Key File: src/agents/TestGeneratorAgent.ts:390-666 (generateTestsWithAI)
src/learning/LearningEngine.ts:227-345
TaskExperience {
state: encode(complexity, capabilities, resources)
action: encode(strategy, parallelization, retry)
reward: calculated from results
nextState: updated state
timestamp: when executed
}
| Condition | Reward |
|---|---|
| Success | +1.0 |
| Failure | -1.0 |
| Fast execution | +0.2 bonus |
| Errors | -0.3 penalty |
| Coverage (test gen) | +0.5 bonus |
| User feedback | -1 to +1 |
| Final: clamp to [-2, +2] | |
Q(s,a) ← Q(s,a) + α[r + γ·max(Q(s',a')) - Q(s,a)]
| Variable | Meaning | Value |
|---|---|---|
| α | Learning rate | 0.1 |
| γ | Discount factor | 0.95 |
| s | Current state | - |
| a | Action taken | - |
| r | Reward received | - |
| s' | Next state | - |
Persisted to: SwarmMemoryManager → q_values table
explorationRate *= 0.995
0.30 (start) → → → → → → → → 0.01 (min)
Over ~1000 tasks: EXPLORING → EXPLOITING
syncWithTeam() to get shared patternscodeSignature = {
functionName: "createUser"
complexity: "medium"
patterns: ["service", "async", "validation"]
}
learningEngine.searchSimilarPatterns("createUser test")
↓
hnswAdapter.searchSimilar(query, k=5)
↓
1. Generate query embedding (RuvLLM or hash fallback)
2. Search HNSW index (O(log n), <1ms)
3. Return top-k similar patterns
Results:
└─ Pattern: "service-async-test" (similarity: 0.92)
└─ Pattern: "validation-test" (similarity: 0.87)
└─ Pattern: "crud-service-test" (similarity: 0.81)
For each high-confidence pattern (applicability > 0.7):
| WITHOUT PATTERNS: | 10 tests → 10 LLM calls → ~5000ms |
| WITH PATTERNS: | 7 from patterns + 3 LLM calls → ~2000ms |
| 60% faster, 70% cost reduction | |
| Solution | Component | Purpose | Location |
|---|---|---|---|
| RuvLLM | RuvllmProvider |
Local LLM inference with TRM/SONA/Sessions | src/providers/RuvllmProvider.ts |
| RuVector | HNSWPatternStore |
O(log n) vector similarity search | src/memory/HNSWPatternStore.ts |
| RuVector | HNSWPatternAdapter |
Bridge to LearningEngine | src/learning/HNSWPatternAdapter.ts |
| RuVector | HybridRouter |
Cache-first routing | src/providers/HybridRouter.ts |
| RuVector | RuVectorClient |
GNN cache client with LoRA/EWC++ | src/providers/RuVectorClient.ts |
| @ruvector/core | VectorDB | HNSW index implementation | node_modules/@ruvector/core |
| AgentDB | ReasoningBank |
Pattern storage and retrieval | node_modules/agentdb |
All QE agents that extend BaseAgent have access to:
| Method | Return | Description |
|---|---|---|
hasRuVectorCache() | boolean | Check if HybridRouter with RuVector cache is enabled |
getRuVectorMetrics() | Promise<object | null> | Get GNN/LoRA/cache metrics from RuVector |
getCacheHitRate() | number | Get cache hit rate (0-1) |
getRoutingStats() | object | Get routing decisions & latencies |
getCostSavingsReport() | object | Get cost savings from cache and local routing |
getLLMStats() | object | Get LLM provider status including RuVector |
| Method | Return | Description |
|---|---|---|
forceRuVectorLearn() | Promise<{success, ...}> | Trigger LoRA consolidation with EWC++ |
| Tool Name | Description |
|---|---|
ruvector_health | Check RuVector Docker health |
ruvector_metrics | Get GNN/LoRA/cache metrics |
ruvector_force_learn | Trigger LoRA consolidation |
ruvector_store_pattern | Store pattern in GNN cache |
ruvector_search | Search similar patterns |
ruvector_cost_savings | Get cost savings report |
// 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);