Skip to main content
Conditions let you control workflow branching based on runtime decisions.

Quick Start

1

Simple Condition

use praisonai::{Agent, when};

let route = when(|input| input.contains("urgent"))
    .then(priority_agent)
    .otherwise(standard_agent);

route.run("urgent: fix bug").await?;
// Routes to priority_agent
2

Multiple Conditions

use praisonai::when;

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

How It Works


Common Patterns

Intent-Based Routing

use praisonai::when;

let router = when(|input| classify(input) == "technical")
    .then(tech_support)
    .when(|input| classify(input) == "billing")
    .then(billing_support)
    .otherwise(general_support);

Priority Handling

use praisonai::when;

let router = when(|input| is_vip_customer(input))
    .then(vip_agent)
    .otherwise(standard_agent);

Best Practices

Complex conditions are hard to debug. Break into smaller checks.
Provide a fallback for unmatched conditions.