Conditions
Add conditional logic to agent workflows
Conditions let you control workflow branching based on runtime decisions.
graph TB
subgraph "Conditional Flow"
S[Start] --> C{Condition?}
C --> |Yes| A[Path A]
C --> |No| B[Path B]
A --> E[End]
B --> E
end
classDef start fill:#6366F1,stroke:#7C90A0,color:#fff
classDef condition fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef path fill:#10B981,stroke:#7C90A0,color:#fff
class S,E start
class C condition
class A,B pathQuick Start
- Simple Condition
rust 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 - Multiple Conditions
rust use praisonai::when; let router = when(|i| i.contains("code")) .then(coder) .when(|i| i.contains("write")) .then(writer) .otherwise(assistant);
How It Works
sequenceDiagram
participant User
participant Router
participant AgentA
participant AgentB
User->>Router: "urgent task"
Router->>Router: Check conditions
alt Contains "urgent"
Router->>AgentA: Route to Priority
AgentA-->>User: Result
else Default
Router->>AgentB: Route to Standard
AgentB-->>User: Result
endCommon 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
Keep conditions simple
Complex conditions are hard to debug. Break into smaller checks.
Always have an otherwise
Provide a fallback for unmatched conditions.