Routing

Route requests between agents

Routing directs requests to appropriate agents.

Diagram

Routing

📥 Request

🔀 Route

🤖 Agent A

🤖 Agent B

🤖 Agent C

Quick Start

  1. Route Requests to Agents
    rust
    use praisonai::{Agent, when};
    
    // Create specialized agents
    let coder = Agent::new()
        .name("Coder")
        .instructions("You help with programming tasks")
        .build()?;
    
    let writer = Agent::new()
        .name("Writer")
        .instructions("You help with writing tasks")
        .build()?;
    
    // Route based on input content
    let router = when(|input: &str| input.contains("code"))
        .then(coder)
        .otherwise(writer);
    
    router.run("Help me write code").await?;
    // Routes to coder agent
  2. Multi-Route Configuration
    rust
    use praisonai::when;
    
    let router = when(|i| i.contains("code"))
        .then(coder)
        .when(|i| i.contains("write"))
        .then(writer)
        .otherwise(general);

Related