Skip to main content
Routing directs requests to appropriate agents.

Quick Start

1

Route Requests to Agents

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

use praisonai::when;

let router = when(|i| i.contains("code"))
    .then(coder)
    .when(|i| i.contains("write"))
    .then(writer)
    .otherwise(general);