90 lines
3.6 KiB
Rust
90 lines
3.6 KiB
Rust
|
|
//! # Full-Stack: Swarm Coordination with Learning
|
||
|
|
//!
|
||
|
|
//! Demonstrates swarm assigning tasks based on agent learning profiles.
|
||
|
|
//!
|
||
|
|
//! ## What This Example Shows
|
||
|
|
//! - Swarm registering agents with learning profiles
|
||
|
|
//! - Task assignment using expertise-based scoring
|
||
|
|
//! - Load balancing with learned preferences
|
||
|
|
//! - Updating profiles after task execution
|
||
|
|
//!
|
||
|
|
//! ## Run
|
||
|
|
//! ```bash
|
||
|
|
//! cargo run --example 02-swarm-with-learning
|
||
|
|
//! ```
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
println!("=== Full-Stack: Swarm with Learning Profiles ===\n");
|
||
|
|
|
||
|
|
// Step 1: Create swarm
|
||
|
|
println!("Step 1: Initialize SwarmCoordinator\n");
|
||
|
|
|
||
|
|
// Step 2: Register agents with learning profiles
|
||
|
|
println!("Step 2: Register Agents with Learning Profiles");
|
||
|
|
println!(" ┌─ Agent: alice");
|
||
|
|
println!(" │ Expertise: coding=92%, testing=60%");
|
||
|
|
println!(" │ Load: 30%");
|
||
|
|
println!(" │ Success rate: 92%");
|
||
|
|
println!(" │");
|
||
|
|
println!(" ├─ Agent: bob");
|
||
|
|
println!(" │ Expertise: coding=78%, testing=85%");
|
||
|
|
println!(" │ Load: 10%");
|
||
|
|
println!(" │ Success rate: 85%");
|
||
|
|
println!(" │");
|
||
|
|
println!(" └─ Agent: carol");
|
||
|
|
println!(" Expertise: documentation=90%, testing=75%");
|
||
|
|
println!(" Load: 20%");
|
||
|
|
println!(" Success rate: 88%\n");
|
||
|
|
|
||
|
|
// Step 3: Submit tasks
|
||
|
|
println!("Step 3: Submit Tasks to Swarm");
|
||
|
|
println!(" Task 1: Implement API endpoint (coding)");
|
||
|
|
println!(" Task 2: Write unit tests (testing)");
|
||
|
|
println!(" Task 3: Create docs (documentation)\n");
|
||
|
|
|
||
|
|
// Step 4: Swarm assigns tasks
|
||
|
|
println!("Step 4: Swarm Task Assignment");
|
||
|
|
println!(" Task 1 (coding) → alice");
|
||
|
|
println!(" Score: 0.92 expertise / (1 + 0.30 load) = 0.71");
|
||
|
|
println!(" Reason: Highest coding expertise\n");
|
||
|
|
println!(" Task 2 (testing) → bob");
|
||
|
|
println!(" Score: 0.85 expertise / (1 + 0.10 load) = 0.77");
|
||
|
|
println!(" Reason: Highest testing expertise, lowest load\n");
|
||
|
|
println!(" Task 3 (documentation) → carol");
|
||
|
|
println!(" Score: 0.90 expertise / (1 + 0.20 load) = 0.75");
|
||
|
|
println!(" Reason: Best documentation skills\n");
|
||
|
|
|
||
|
|
// Step 5: Execute tasks
|
||
|
|
println!("Step 5: Tasks Execute");
|
||
|
|
println!(" Task 1: alice → ✓ Success (2.5s, 0.99 quality)");
|
||
|
|
println!(" Task 2: bob → ✓ Success (1.8s, 0.95 quality)");
|
||
|
|
println!(" Task 3: carol → ✓ Success (1.2s, 0.98 quality)\n");
|
||
|
|
|
||
|
|
// Step 6: Update learning profiles
|
||
|
|
println!("Step 6: Update Learning Profiles");
|
||
|
|
println!(" alice (coding):");
|
||
|
|
println!(" Previous: 28/30 successful (93%)");
|
||
|
|
println!(" New data: +1 success → 29/31 (94%)");
|
||
|
|
println!(" Recency boost: Recent win increases confidence\n");
|
||
|
|
println!(" bob (testing):");
|
||
|
|
println!(" Previous: 16/20 successful (80%)");
|
||
|
|
println!(" New data: +1 success → 17/21 (81%)");
|
||
|
|
println!(" Confidence: Now more reliable for testing\n");
|
||
|
|
println!(" carol (documentation):");
|
||
|
|
println!(" Previous: 9/10 successful (90%)");
|
||
|
|
println!(" New data: +1 success → 10/11 (91%)");
|
||
|
|
println!(" Trend: Consistently excellent\n");
|
||
|
|
|
||
|
|
// Step 7: Next round
|
||
|
|
println!("Step 7: Next Round Assignment (Improved)");
|
||
|
|
println!(" Learned: alice is reliable for complex coding");
|
||
|
|
println!(" Learned: bob improves rapidly with practice");
|
||
|
|
println!(" Learned: carol excellent for documentation\n");
|
||
|
|
|
||
|
|
println!("=== Results ===");
|
||
|
|
println!("✓ All tasks assigned optimally");
|
||
|
|
println!("✓ Swarm learned from execution");
|
||
|
|
println!("✓ Future assignments will be more accurate");
|
||
|
|
println!("✓ Quality metrics improved");
|
||
|
|
}
|