Vapora/examples/real-world/01-code-review-workflow.rs

98 lines
3.5 KiB
Rust
Raw Permalink Normal View History

2026-01-12 03:34:01 +00:00
//! # Real-World: Automated Code Review Pipeline
//!
//! Multi-agent code review with developer → reviewer → architect workflow.
//!
//! ## Business Problem
//! Review all pull requests within 2 hours, ensuring consistent quality standards.
//!
//! ## Solution Architecture
//! 1. Developer Agent: Code analysis (cheap model)
//! 2. Reviewer Agent: Quality assurance (mid-tier)
//! 3. Architect Agent: Design validation (premium)
//!
//! ## Cost Optimization
//! - Use Ollama for routine checks (free)
//! - GPT-4 for detailed review ($10/1M)
//! - Claude for architecture ($15/1M)
//!
//! ## Run
//! ```bash
//! cargo run --example 01-code-review-workflow
//! ```
fn main() {
println!("=== Real-World: Automated Code Review Pipeline ===\n");
println!("Business Goal: Review 50 PRs/day with consistent quality\n");
// Phase 1: Initial code analysis (cheap)
println!("Phase 1: Static Analysis (Ollama - Free)");
println!("Tasks:");
println!(" ✓ Lint & formatting checks");
println!(" ✓ Dead code detection");
println!(" ✓ Security rule violations");
println!("Cost: $0.00 (local execution)");
println!("Time: ~5 seconds/PR\n");
// Phase 2: Code quality review (mid-tier)
println!("Phase 2: Quality Review (GPT-4 - $10/1M tokens)");
println!("Tasks:");
println!(" ✓ Logic verification");
println!(" ✓ Test coverage analysis");
println!(" ✓ Performance implications");
println!("Cost: ~$0.08/PR");
println!("Time: ~15 seconds/PR\n");
// Phase 3: Architecture validation (premium)
println!("Phase 3: Architecture Review (Claude - $15/1M tokens)");
println!("Only triggered for:");
println!(" ✓ High-risk changes (10% of PRs)");
println!(" ✓ New modules/services");
println!(" ✓ Database schema changes");
println!("Cost: ~$0.20/PR (for 10% of PRs)");
println!("Time: ~30 seconds/PR\n");
// Cost-benefit analysis
println!("=== Economics ===");
println!("Volume: 50 PRs/day");
println!("Cost per PR: $0.012 average");
println!(" = Phase 1 (free): $0.00");
println!(" + Phase 2 (100%): $0.08");
println!(" + Phase 3 (10%): $0.02");
println!("Total daily cost: $0.60");
println!("Total monthly cost: $12.00\n");
println!("Manual review cost: ~$500/month (human time)");
println!("Savings: $488/month + faster feedback\n");
// Workflow example
println!("=== Example: Single PR Review ===");
println!("PR#1234: Add authentication module");
println!("\n[1/3] Ollama - Static analysis");
println!(" ✓ No lint errors");
println!(" ✓ Test coverage: 92%");
println!(" → Continue to next phase\n");
println!("[2/3] GPT-4 - Quality review");
println!(" ✓ Logic correct");
println!(" ⚠ Missing error handling in 2 places");
println!(" ⚠ Consider retry logic for failed auth\n");
println!("[3/3] Claude - Architecture review (triggered: new module)");
println!(" ✓ Design follows patterns");
println!(" ✓ Security best practices applied");
println!(" ✓ Approved for merge\n");
println!("Result: PR approved with 2 suggestions");
println!("Time: 50 seconds");
println!("Cost: $0.28");
println!("Human equivalent: 10+ minutes, $5+\n");
println!("=== Results ===");
println!("✓ 50 PRs reviewed daily");
println!("✓ Consistent quality standards");
println!("✓ 98% accuracy (matches human review)");
println!("✓ 60+ minute feedback time (vs 2+ hours manual)");
println!("✓ Cost: $12/month (vs $500+ manual)");
}