Examples
Explore real-world examples of organizational patterns and multi-agent coordination.
1use agentropic_patterns::hierarchy::*;23 // Define the organizational hierarchy4 let org = Hierarchy::new()5 .with_root(CeoAgent::new("Alice"))6 .add_child("Alice", DepartmentAgent::new("Engineering"))7 .add_child("Alice", DepartmentAgent::new("Sales"))8 .add_child("Engineering", EmployeeAgent::new("Bob"))9 .add_child("Engineering", EmployeeAgent::new("Charlie"));1011 // CEO broadcasts a directive12 org.broadcast_down(Directive::new("Q4 Goals")).await?;1314 // Employees report up the chain15 org.report_up("Bob", Report::new("Feature shipped")).await?;
1use agentropic_patterns::swarm::*;23 // Create a swarm of drone agents4 let swarm = Swarm::new(SwarmConfig {5 size: 50,6 neighborhood_radius: 10.0,7 alignment_weight: 1.0,8 cohesion_weight: 1.0,9 separation_weight: 1.5,10 });1112 // Spawn drones with position13 for i in 0..50 {14 swarm.spawn(DroneAgent::new(random_position())).await?;15 }1617 // Drones automatically coordinate via local rules18 swarm.start().await?;
1use agentropic_patterns::market::*;23 let market = Market::new(AuctionRules::english());45 // Register participants6 market.register_seller(SellerAgent::new("Alice", item)).await?;7 market.register_buyer(BuyerAgent::new("Bob", budget: 1000)).await?;8 market.register_buyer(BuyerAgent::new("Charlie", budget: 1500)).await?;910 // Run the auction11 let result = market.run_auction(Duration::from_secs(60)).await?;12 println!("Winner: {} at price {}", result.winner, result.price);
1use agentropic_patterns::coalition::*;23 // Agents with different capabilities4 let agents = vec![5 Agent::new("Alice").with_skills(["rust", "ml"]),6 Agent::new("Bob").with_skills(["python", "data"]),7 Agent::new("Charlie").with_skills(["devops", "k8s"]),8 ];910 // Form coalition for a task11 let task = Task::new("Deploy ML Model")12 .requires(["ml", "devops"]);1314 let coalition = CoalitionFormation::greedy()15 .form(&agents, &task).await?;1617 println!("Coalition: {:?}", coalition.members());
1use agentropic_patterns::blackboard::*;23 let blackboard = Blackboard::new();45 // Specialist agents contribute knowledge6 let hypothesis_agent = HypothesisAgent::new();7 let analyzer_agent = AnalyzerAgent::new();8 let validator_agent = ValidatorAgent::new();910 // Agents react to blackboard changes11 blackboard.on_change(|entry| {12 match entry.level {13 Level::Raw => hypothesis_agent.process(entry),14 Level::Hypothesis => analyzer_agent.analyze(entry),15 Level::Analysis => validator_agent.validate(entry),16 }17 });1819 blackboard.post(RawData::new(sensor_reading)).await?;