> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Conditions

> Add conditional logic to agent workflows

Conditions let you control workflow branching based on runtime decisions.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 path
```

## Quick Start

<Steps>
  <Step title="Simple Condition">
    ```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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
    ```
  </Step>

  <Step title="Multiple Conditions">
    ```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    use praisonai::when;

    let router = when(|i| i.contains("code"))
        .then(coder)
        .when(|i| i.contains("write"))
        .then(writer)
        .otherwise(assistant);
    ```
  </Step>
</Steps>

***

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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
    end
```

***

## Common Patterns

### Intent-Based Routing

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
use praisonai::when;

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

***

## Best Practices

<AccordionGroup>
  <Accordion title="Keep conditions simple">
    Complex conditions are hard to debug. Break into smaller checks.
  </Accordion>

  <Accordion title="Always have an otherwise">
    Provide a fallback for unmatched conditions.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Loops" icon="rotate" href="/docs/rust/loops">
    Repeated execution
  </Card>

  <Card title="Workflows" icon="sitemap" href="/docs/rust/flow">
    Complex flows
  </Card>
</CardGroup>
