Major Features: - Complete Nightly-Learner implementation with 4 phases: - Phase 0: Baselines (180 benchmark tasks for 19 agents) - Phase 1: Experience Capture (automatic agent learning) - Phase 2: Sleep Cycle (N1-N2-N3-REM processing) - Phase 3: Dream Engine (insight generation) - BaseAgent integration for automatic experience capture - New CLI commands: learn, dream, transfer Fixes: - Process hanging in aqe init (ExperienceCapture not stopped) - TypeScript errors in TrendAnalyzer and BaseAgent - Removed duplicate code in dashboard/ directory Files Added: - src/learning/baselines/* - Performance baseline collection - src/learning/metrics/* - Trend analysis and alerting - src/cli/commands/dream/* - Dream engine commands - src/cli/commands/transfer/* - Pattern transfer commands - src/cli/init/learning-init.ts - Learning initialization - tests/integration/learning/* - Integration tests 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
10 KiB
Phase 3 Metrics Implementation Summary
Status: ✅ COMPLETE
Date: 2025-12-11
Location: /workspaces/agentic-qe-cf/src/learning/metrics/
Overview
Phase 3 Metrics for the Nightly-Learner system has been successfully implemented. The system tracks learning effectiveness across discovery, quality, transfer, impact, and system health dimensions.
Implemented Components
1. LearningMetrics.ts (935 lines)
Purpose: Collect and track learning effectiveness metrics
Key Features:
- ✅ Discovery metrics (patterns discovered, discovery rate)
- ✅ Quality metrics (accuracy, actionability, false positive rate)
- ✅ Transfer metrics (success rate, adoption rate, negative transfers)
- ✅ Impact metrics (time reduction, coverage improvement, bug detection)
- ✅ System health metrics (cycle completion rate, error rate)
- ✅ Comprehensive breakdown by category
- ✅ Trend calculation using linear regression
- ✅ Historical comparison (first half vs second half)
Core Metrics Tracked:
interface LearningMetricsData {
// Discovery
patternsDiscoveredTotal: number;
patternsDiscoveredToday: number;
discoveryRate: number; // patterns/hour
// Quality
patternAccuracy: number; // 0-1
insightActionability: number; // 0-1
falsePositiveRate: number; // 0-1
// Transfer
transferSuccessRate: number; // 0-1
adoptionRate: number; // % of transferred patterns used
negativeTransferCount: number;
// Impact
taskTimeReduction: number; // % improvement
coverageImprovement: number; // % improvement
bugDetectionImprovement: number; // % improvement
// System health
sleepCycleCompletionRate: number;
avgCycleDuration: number;
errorRate: number;
}
Database Integration:
- ✅ Uses
better-sqlite3for queries - ✅ Connects to
.agentic-qe/memory.db - ✅ Queries existing tables:
patterns- Pattern discovery datadream_insights- Insight generation datadream_cycles- Sleep cycle datatransfer_registry- Transfer validation datacaptured_experiences- Agent execution data
2. MetricsStore.ts (606 lines)
Purpose: Persist metrics to SQLite for historical analysis
Key Features:
- ✅ Snapshot capture with timestamps
- ✅ Historical querying by time range
- ✅ Rolling averages calculation
- ✅ Linear regression for trend analysis
- ✅ Metric aggregations (avg, min, max, stdDev)
- ✅ Period comparison (before/after)
- ✅ Auto-snapshot with configurable interval
- ✅ Retention policy with automatic cleanup
- ✅ Export to JSON
Database Schema:
CREATE TABLE metrics_snapshots (
id TEXT PRIMARY KEY,
snapshot_time INTEGER NOT NULL,
period_hours INTEGER NOT NULL,
-- Discovery metrics
patterns_discovered_total INTEGER,
patterns_discovered_today INTEGER,
discovery_rate REAL,
-- Quality metrics
pattern_accuracy REAL,
insight_actionability REAL,
false_positive_rate REAL,
-- Transfer metrics
transfer_success_rate REAL,
adoption_rate REAL,
negative_transfer_count INTEGER,
-- Impact metrics
task_time_reduction REAL,
coverage_improvement REAL,
bug_detection_improvement REAL,
-- System health
sleep_cycle_completion_rate REAL,
avg_cycle_duration REAL,
error_rate REAL,
-- Metadata
calculated_at INTEGER,
period_start INTEGER,
period_end INTEGER,
created_at INTEGER
);
Advanced Features:
- ✅ Rolling averages with configurable window
- ✅ Trend detection using linear regression
- ✅ Statistical aggregations (mean, std dev)
- ✅ Comparative analysis between time periods
- ✅ Auto-cleanup based on retention policy
3. index.ts (34 lines)
Purpose: Export all metrics components
Exports:
- ✅
LearningMetrics(main collector) - ✅
MetricsStore(persistence layer) - ✅ All interface types
- ✅ MetricsCollector, TrendAnalyzer, AlertManager (original Phase 3)
Integration with Nightly-Learner
Phase 1: Experience Capture
- ✅ Metrics read from
captured_experiencestable - ✅ Tracks agent execution quality, duration, success rates
- ✅ Links patterns used to execution outcomes
Phase 2: Dream Engine
- ✅ Metrics read from
dream_cyclesanddream_insightstables - ✅ Tracks dream cycle completion, insights generated
- ✅ Measures pattern discovery rate
Phase 3: Transfer Protocol
- ✅ Metrics read from
transfer_registrytable - ✅ Tracks transfer success, validation, adoption
- ✅ Identifies negative transfers
Usage Examples
Basic Metrics Collection
import { LearningMetrics } from './learning/metrics';
// Initialize
const metrics = new LearningMetrics({
dbPath: '.agentic-qe/memory.db'
});
// Get current metrics (last 24 hours)
const current = await metrics.getCurrentMetrics(24);
console.log(`Discovery rate: ${current.discoveryRate.toFixed(2)} patterns/hour`);
console.log(`Transfer success: ${(current.transferSuccessRate * 100).toFixed(1)}%`);
console.log(`Time reduction: ${current.taskTimeReduction.toFixed(1)}%`);
// Get comprehensive summary with breakdown
const summary = await metrics.getMetricsSummary(24);
console.log('Trends:');
console.log(` Discovery: ${summary.trends.discoveryTrend > 0 ? '📈' : '📉'}`);
console.log(` Quality: ${summary.trends.qualityTrend > 0 ? '📈' : '📉'}`);
console.log(` Transfer: ${summary.trends.transferTrend > 0 ? '📈' : '📉'}`);
console.log(` Impact: ${summary.trends.impactTrend > 0 ? '📈' : '📉'}`);
Historical Analysis
import { MetricsStore } from './learning/metrics';
// Initialize with auto-snapshot every hour
const store = new MetricsStore({
autoSnapshotInterval: 1, // 1 hour
retentionDays: 90 // Keep 90 days
});
// Capture a snapshot manually
await store.captureSnapshot(24);
// Get last 7 days of history
const history = await store.getHistory({
startTime: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000),
limit: 100
});
// Get rolling average for discovery rate (24-hour window)
const rollingAvg = await store.getRollingAverage('discoveryRate', 24);
// Get aggregations
const aggs = await store.getAggregations(
['discoveryRate', 'transferSuccessRate', 'taskTimeReduction'],
{
startTime: new Date(Date.now() - 7 * 24 * 60 * 60 * 1000)
}
);
for (const [metric, data] of aggs) {
console.log(`${metric}:`);
console.log(` Average: ${data.avg.toFixed(2)}`);
console.log(` Min: ${data.min.toFixed(2)}`);
console.log(` Max: ${data.max.toFixed(2)}`);
console.log(` Trend: ${data.trend > 0 ? 'improving' : 'declining'}`);
}
Period Comparison
// Compare this week vs last week
const thisWeekStart = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
const thisWeekEnd = new Date();
const lastWeekStart = new Date(Date.now() - 14 * 24 * 60 * 60 * 1000);
const lastWeekEnd = thisWeekStart;
const comparison = await store.compareMetrics(
['discoveryRate', 'transferSuccessRate', 'taskTimeReduction'],
lastWeekStart,
lastWeekEnd,
thisWeekStart,
thisWeekEnd
);
for (const [metric, data] of comparison) {
console.log(`${metric}:`);
console.log(` Last week: ${data.period1.toFixed(2)}`);
console.log(` This week: ${data.period2.toFixed(2)}`);
console.log(` Change: ${data.changePercent.toFixed(1)}%`);
}
Architecture Patterns
1. Database-First Design
- All metrics stored in SQLite for persistence
- No in-memory state (except caches)
- Survives process restarts
2. Separation of Concerns
- LearningMetrics: Collection and calculation
- MetricsStore: Persistence and historical analysis
- Clear interface boundaries
3. Real-Time + Historical
- Real-time metric calculation on demand
- Historical snapshots for trend analysis
- Flexible time windows
4. Error Handling
- All database operations wrapped in try-catch
- Graceful degradation on missing tables
- Debug logging for troubleshooting
5. Performance Optimization
- Indexed columns for fast queries
- Prepared statements for repeated queries
- Transaction-based batch operations
Files Summary
| File | Lines | Purpose | Status |
|---|---|---|---|
| LearningMetrics.ts | 935 | Metric collection & calculation | ✅ Complete |
| MetricsStore.ts | 606 | Persistence & historical analysis | ✅ Complete |
| index.ts | 34 | Export interface | ✅ Complete |
| MetricsCollector.ts | 338 | Original Phase 3 collector | ✅ Complete |
| TrendAnalyzer.ts | 263 | Original Phase 3 analyzer | ✅ Complete |
| AlertManager.ts | 313 | Original Phase 3 alerts | ✅ Complete |
Total: 2,489 lines of production-quality TypeScript
Verification
Type Safety
npm run typecheck
# No errors in src/learning/metrics/
Build
npm run build
# Compiles successfully
Database Schema
- ✅
metrics_snapshotstable created on initialization - ✅ Indexes on
snapshot_time,calculated_at,period_start/end - ✅ All columns properly typed (INTEGER, REAL, TEXT)
Next Steps
Integration with CLI
Add CLI commands for metrics:
aqe metrics status # Show current metrics
aqe metrics history --days=7 # Show last 7 days
aqe metrics trends # Show trends
Dashboard Visualization
- Expose metrics via REST API
- Create web dashboard for visualization
- Real-time metric updates via WebSocket
Alerting System
- Integrate with AlertManager
- Configure thresholds for alerts
- Email/Slack notifications
Export & Reporting
- CSV export for spreadsheets
- PDF reports for stakeholders
- Grafana/Prometheus integration
Conclusion
Phase 3 Metrics implementation is COMPLETE and production-ready. The system provides:
✅ Comprehensive metrics across all learning dimensions
✅ Real-time calculation and historical analysis
✅ SQLite-based persistence with .agentic-qe/memory.db
✅ Advanced analytics (rolling averages, trends, comparisons)
✅ Clean architecture with separation of concerns
✅ Full TypeScript type safety
✅ Graceful error handling and logging
The metrics system is ready for integration with CLI commands, dashboards, and alerting systems.
Generated: 2025-12-11 System: Agentic QE Fleet v2.3.3 Module: Nightly-Learner Phase 3 - Metrics