Skip to main content
Router directs requests to the most appropriate agent.

Quick Start

1

Create Agent Router

use praisonai::{Agent, when};

// Create specialized agents
let tech_agent = Agent::new()
    .name("Tech Support")
    .instructions("Help with technical issues")
    .build()?;

let sales_agent = Agent::new()
    .name("Sales")
    .instructions("Handle sales inquiries")
    .build()?;

let support_agent = Agent::new()
    .name("Support")
    .instructions("General customer support")
    .build()?;

// Create router with conditions
let router = when(|input: &str| input.contains("API") || input.contains("error"))
    .then(tech_agent)
    .when(|input: &str| input.contains("price") || input.contains("buy"))
    .then(sales_agent)
    .otherwise(support_agent);

router.run("I need help with an API error").await?;
// Routes to tech_agent

Routing Strategies

StrategyDescription
KeywordMatch keywords in input
SemanticUse embeddings to classify
LLMUse LLM to decide
RulesCustom routing rules