- CoverageAnalyzerAgent: Add ExperienceCapture integration for Nightly-Learner - New loadAndCachePatternsForConfidence() for startup pattern loading - New getConfidenceBoostFromPatterns() for 30% max confidence boost - New captureExperienceForLearning() for experience capture - QualityGateAgent: Add complete learning stack - Add LearningEngine for Q-learning pattern discovery - Add PerformanceTracker for metrics tracking - Add ExperienceCapture for Nightly-Learner integration - New confidence boosting (25% max) from cached patterns - Add comprehensive documentation: - docs/guides/DREAM-ENGINE-ARCHITECTURE.md - docs/reports/learning-flow-deep-analysis.md - docs/reports/agent-learning-implementation-report.md - Add scripts/run-agents.js for testing agent execution All 18 QE agents now have proper learning integration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
19 KiB
QE Agent Learning Flow - Deep Analysis Report
Date: 2024-12-12 Analysis Scope: Complete learning pipeline from agent execution to Nightly-Learner processing
Executive Summary
This analysis traces the complete learning flow for QE agents, identifying critical gaps where agents are missing learning capabilities. The investigation reveals:
- 16 of 18 core agents have full learning integration via BaseAgent
- 2 agents (CoverageAnalyzerAgent, QualityGateAgent) extend EventEmitter instead of BaseAgent, missing ExperienceCapture integration
- Pattern retrieval works correctly for BaseAgent derivatives
- The DreamEngine successfully synthesizes patterns from captured experiences
1. Learning Architecture Overview
1.1 Two Parallel Learning Systems
The codebase implements TWO complementary learning mechanisms:
┌──────────────────────────────────────────────────────────────────────┐
│ DUAL LEARNING ARCHITECTURE │
├──────────────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────────────────┐ ┌─────────────────────────────────┐ │
│ │ REAL-TIME LEARNING │ │ NIGHTLY-LEARNER (BATCH) │ │
│ │ (LearningEngine) │ │ (DreamEngine) │ │
│ ├─────────────────────────┤ ├─────────────────────────────────┤ │
│ │ • Q-Learning algorithm │ │ • Sleep cycle pattern synthesis │ │
│ │ • SARSA, Actor-Critic │ │ • Spreading activation │ │
│ │ • Pattern discovery │ │ • Cross-agent transfer │ │
│ │ • Strategy recommend │ │ • ConceptGraph building │ │
│ │ │ │ │ │
│ │ Tables: │ │ Tables: │ │
│ │ • learning_experiences │ │ • captured_experiences │ │
│ │ • patterns │ │ • synthesized_patterns │ │
│ │ • q_values │ │ • concept_nodes/edges │ │
│ │ │ │ • dream_insights │ │
│ └─────────────────────────┘ └─────────────────────────────────┘ │
│ │ │ │
│ └──────────────────┬────────────────┘ │
│ │ │
│ ┌─────────▼─────────┐ │
│ │ memory.db │ │
│ │ (unified storage) │ │
│ └───────────────────┘ │
└──────────────────────────────────────────────────────────────────────┘
2. Agent Classification by Learning Capability
2.1 Full Learning Integration (16 agents)
These agents extend BaseAgent and have complete learning:
| Agent | Extends | ExperienceCapture | LearningEngine | Pattern Retrieval |
|---|---|---|---|---|
| TestGeneratorAgent | BaseAgent | ✅ | ✅ | ✅ (onPreTask) |
| QualityAnalyzerAgent | BaseAgent | ✅ | ✅ | ✅ |
| FlakyTestHunterAgent | BaseAgent | ✅ | ✅ | ✅ |
| SecurityScannerAgent | BaseAgent | ✅ | ✅ | ✅ |
| ChaosEngineerAgent | BaseAgent | ✅ | ✅ | ✅ |
| VisualTesterAgent | BaseAgent | ✅ | ✅ | ✅ |
| TestExecutorAgent | BaseAgent | ✅ | ✅ | ✅ |
| IntegrationTesterAgent | BaseAgent | ✅ | ✅ | ✅ |
| PerformanceValidatorAgent | BaseAgent | ✅ | ✅ | ✅ |
| PerformanceTesterAgent | BaseAgent | ✅ | ✅ | ✅ |
| RegressionRiskAnalyzerAgent | BaseAgent | ✅ | ✅ | ✅ |
| ApiContractValidatorAgent | BaseAgent | ✅ | ✅ | ✅ |
| RequirementsValidatorAgent | BaseAgent | ✅ | ✅ | ✅ |
| TestDataArchitectAgent | BaseAgent | ✅ | ✅ | ✅ |
| ProductionIntelligenceAgent | BaseAgent | ✅ | ✅ | ✅ |
| DeploymentReadinessAgent | BaseAgent | ✅ | ✅ | ✅ |
2.2 Partial/Missing Learning (2 agents) - ⚠️ CRITICAL GAPS
| Agent | Extends | ExperienceCapture | LearningEngine | Issue |
|---|---|---|---|---|
| CoverageAnalyzerAgent | EventEmitter | ❌ MISSING | ✅ (has it) | Has LearningEngine but NO ExperienceCapture - won't feed Nightly-Learner |
| QualityGateAgent | EventEmitter | ❌ MISSING | ❌ MISSING | NO learning at all - completely isolated from learning system |
3. Learning Data Flow Analysis
3.1 BaseAgent Learning Flow (Working)
┌────────────────────────────────────────────────────────────────────────┐
│ BaseAgent TASK EXECUTION FLOW │
├────────────────────────────────────────────────────────────────────────┤
│ │
│ executeTask(assignment) │
│ │ │
│ ├──► onPreTask() │
│ │ ├─► AgentDB.retrieve() - Load similar task patterns │
│ │ └─► VerificationHookManager.preTaskVerification() │
│ │ │
│ ├──► performTask() - Actual task execution │
│ │ │
│ ├──► onPostTask() │
│ │ ├─► LearningEngine.learnFromExecution() │
│ │ │ ├─► storeLearningExperience() → learning_experiences │
│ │ │ ├─► upsertQValue() → q_values table │
│ │ │ └─► storePattern() → patterns table │
│ │ │ │
│ │ └─► AgentDB.store() - Save execution pattern │
│ │ │
│ └──► captureExperience() ─────────────────────────────────────┐ │
│ │ │ │
│ └──► ExperienceCapture.captureExecution() │ │
│ └──► captured_experiences table │ │
│ │ │ │
│ ▼ (Nightly-Learner processes) │ │
│ DreamEngine.runSleepCycle() │ │
│ │ │ │
│ └──► synthesized_patterns, concept_nodes │ │
│ │ │
└────────────────────────────────────────────────────────────────────────┘
Key File: src/agents/BaseAgent.ts:1301-1349 - captureExperience() method
private async captureExperience(data: {...}): Promise<void> {
// Get the shared ExperienceCapture instance
const capture = await ExperienceCapture.getSharedInstance();
// Build the execution event
const event: AgentExecutionEvent = {
agentId: this.agentId.id,
agentType: this.agentId.type,
taskId: data.taskId,
taskType: data.taskType,
input: data.input,
output: data.output,
duration: data.duration,
success: data.success,
error: data.error,
metrics: data.metrics,
timestamp: new Date(),
};
// Capture the execution
await capture.captureExecution(event);
}
3.2 CoverageAnalyzerAgent Learning Flow (BROKEN)
┌────────────────────────────────────────────────────────────────────────┐
│ CoverageAnalyzerAgent TASK EXECUTION FLOW │
├────────────────────────────────────────────────────────────────────────┤
│ │
│ executeTask(task) - Direct implementation, NOT via BaseAgent │
│ │ │
│ ├──► optimizeCoverage() │
│ │ ├─► learningEngine.recommendStrategy() ✅ Works │
│ │ └─► Actual optimization logic │
│ │ │
│ ├──► learningEngine.learnFromExecution() ✅ Works │
│ │ └──► Persists to learning_experiences, q_values │
│ │ │
│ └──► ❌ NO captureExperience() call! │
│ │ │
│ └──► Nightly-Learner NEVER receives these experiences │
│ DreamEngine can't synthesize patterns │
│ No cross-agent transfer learning │
│ │
└────────────────────────────────────────────────────────────────────────┘
Issue Location: src/agents/CoverageAnalyzerAgent.ts:105
export class CoverageAnalyzerAgent extends EventEmitter { // ❌ Should extend BaseAgent
What's Missing:
- No
captureExperience()method (defined in BaseAgent) - No integration with ExperienceCapture singleton
- Experiences never reach
captured_experiencestable - DreamEngine can't include CoverageAnalyzer patterns in sleep cycles
3.3 QualityGateAgent Learning Flow (COMPLETELY MISSING)
┌────────────────────────────────────────────────────────────────────────┐
│ QualityGateAgent TASK EXECUTION FLOW │
├────────────────────────────────────────────────────────────────────────┤
│ │
│ executeTask(task) │
│ │ │
│ └──► evaluateQualityGate() │
│ ├─► DecisionEngine.evaluate() │
│ ├─► ConsciousnessEngine.evaluate() │
│ └─► RiskAnalyzer.analyze() │
│ │
│ ❌ NO LearningEngine │
│ ❌ NO ExperienceCapture │
│ ❌ NO pattern learning at all │
│ │
│ Result: Agent makes decisions but NEVER learns from them │
│ Quality gate decisions are NOT improving over time │
│ │
└────────────────────────────────────────────────────────────────────────┘
Issue Location: src/agents/QualityGateAgent.ts:73
export class QualityGateAgent extends EventEmitter { // ❌ Should extend BaseAgent
4. Pattern Retrieval During Task Execution
4.1 BaseAgent Pattern Retrieval (onPreTask)
File: src/agents/BaseAgent.ts:832-927
Pattern retrieval happens in two places:
-
AgentDB Integration (lines 838-906):
- Generates embedding from task data
- Queries AgentDB for similar tasks
- Enriches context with
relevantPatternsandsimilarTasks
-
LearningEngine Strategy (via
recommendStrategy()):- Uses Q-table to recommend optimal strategy
- Returns confidence scores and alternatives
4.2 LearningEngine Pattern Retrieval
File: src/learning/LearningEngine.ts:386-410
async getPatterns(): Promise<LearnedPattern[]> {
// Query patterns from memoryStore if available
const dbPatterns = await this.memoryStore.queryPatternsByAgent(this.agentId, 0);
return dbPatterns.map((p: any) => ({
id: p.id,
pattern: p.pattern,
confidence: p.confidence,
successRate: p.metadata?.success_rate || 0.5,
usageCount: p.usageCount || 0,
contexts: p.metadata?.contexts || [],
// ...
}));
}
5. Database Tables Used
5.1 Real-Time Learning (LearningEngine)
| Table | Purpose | Written By |
|---|---|---|
learning_experiences |
Individual task experiences | LearningEngine.learnFromExecution() |
patterns |
Discovered patterns | LearningEngine.updatePatterns() |
q_values |
Q-table state-action values | LearningEngine.upsertQValue() |
5.2 Nightly-Learner (DreamEngine)
| Table | Purpose | Written By |
|---|---|---|
captured_experiences |
Raw agent executions | ExperienceCapture.captureExecution() |
synthesized_patterns |
Clustered meta-patterns | PatternSynthesis.synthesize() |
concept_nodes |
ConceptGraph vertices | ConceptGraph.buildFromExperiences() |
concept_edges |
ConceptGraph relationships | ConceptGraph.addEdge() |
dream_insights |
Generated insights | InsightGenerator.generate() |
6. Critical Findings Summary
6.1 Agents Missing ExperienceCapture (Nightly-Learner)
| Agent | LearningEngine | ExperienceCapture | Impact |
|---|---|---|---|
| CoverageAnalyzerAgent | ✅ Has | ❌ Missing | Can learn real-time but NOT contribute to cross-agent patterns |
| QualityGateAgent | ❌ Missing | ❌ Missing | NO learning whatsoever |
6.2 Impact Assessment
-
CoverageAnalyzerAgent (Severity: HIGH)
- Coverage optimization experiences are NOT available for Nightly-Learner
- Other agents can't learn from coverage analysis patterns
- Q-learning works but is isolated
-
QualityGateAgent (Severity: CRITICAL)
- Quality gate decisions never improve
- No learning from past pass/fail patterns
- Cannot adapt thresholds based on project history
7. Recommendations
7.1 Fix CoverageAnalyzerAgent
Option A: Extend BaseAgent (Recommended)
- Refactor to extend BaseAgent instead of EventEmitter
- Inherit full learning integration automatically
- Estimated effort: 2-3 hours
Option B: Add ExperienceCapture manually
- Keep current architecture
- Add
captureExperience()method like BaseAgent - Estimated effort: 30 minutes
7.2 Fix QualityGateAgent
Option A: Extend BaseAgent (Recommended)
- Full refactor to extend BaseAgent
- Add LearningEngine configuration
- Estimated effort: 3-4 hours
Option B: Add minimal learning
- Add LearningEngine and ExperienceCapture manually
- Keep EventEmitter inheritance
- Estimated effort: 1 hour
7.3 Future Improvements
- Type Safety: Add abstract base requirement or interface to ensure all agents implement learning
- Monitoring: Add metrics for experience capture rate per agent type
- Testing: Add integration tests that verify ExperienceCapture receives events from all agents
8. Verification Commands
# Check experiences captured per agent type
sqlite3 .agentic-qe/memory.db "SELECT agent_type, COUNT(*) FROM captured_experiences GROUP BY agent_type"
# Check Q-values per agent
sqlite3 .agentic-qe/memory.db "SELECT agent_id, COUNT(*) FROM q_values GROUP BY agent_id"
# Verify Nightly-Learner patterns
sqlite3 .agentic-qe/memory.db "SELECT pattern_key, confidence, usage_count FROM synthesized_patterns ORDER BY confidence DESC LIMIT 10"
Appendix: File References
| Component | File | Key Lines |
|---|---|---|
| BaseAgent learning | src/agents/BaseAgent.ts |
217-240, 304-313, 1301-1349 |
| ExperienceCapture | src/learning/capture/ExperienceCapture.ts |
97-282 |
| LearningEngine | src/learning/LearningEngine.ts |
207-325, 580-673 |
| CoverageAnalyzerAgent | src/agents/CoverageAnalyzerAgent.ts |
105, 167-192, 445-448 |
| QualityGateAgent | src/agents/QualityGateAgent.ts |
73, 91-131 |
| DreamEngine | src/learning/dream/DreamEngine.ts |
Full file |
Report generated by deep analysis of the agentic-qe-cf codebase learning pipeline.