> ## 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.

# Flow

> Create conditional agent workflows

Agents can follow conditional flows - branch based on conditions and data.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TB
    subgraph "Conditional Flow"
        A[🤖 Start] --> B{Condition?}
        B -->|yes| C[Path A]
        B -->|no| D[Path B]
        C --> E[🏁 End]
        D --> E
    end

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff
    class B agent
    class A,C,D,E tool
    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff

```

## Quick Start

**1. Simple Usage**

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
import { Agent, Flow, when } from 'praisonai';

const classifier = new Agent({ instructions: 'Classify requests' });
const support = new Agent({ instructions: 'Handle support' });
const sales = new Agent({ instructions: 'Handle sales' });

const flow = new Flow()
  .start(classifier)
  .when('support', support)
  .when('sales', sales);

await flow.run('I need help with billing');
// Classifier routes to appropriate agent
```

**2. With Configuration**

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
const flow = new Flow()
  .start(classifier)
  .when('support', support)
  .otherwise(generalAgent);
```

***

## User Interaction Flow

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Flow
    participant Classifier
    participant Handler
    
    User->>Flow: Request
    Flow->>Classifier: Classify
    Classifier-->>Flow: Category
    Flow->>Handler: Route to handler
    Handler-->>User: Response
```

***

## Configuration Levels

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
// Level 1: Method chain - Simple flow
const flow = new Flow()
  .start(classifier)
  .when('A', agentA)
  .when('B', agentB);

// Level 2: Array - Multiple conditions
const flow = new Flow({
  routes: [
    { condition: 'support', agent: support },
    { condition: 'sales', agent: sales }
  ]
});

// Level 3: Instance - Full control
const flow = new Flow({
  start: classifier,
  routes: [
    {
      condition: (output) => output.includes('urgent'),
      agent: urgentHandler,
      priority: 1
    }
  ],
  fallback: generalAgent
});
```

***

## Flow Methods

| Method | Description |
| - | - |
| `.start()` | Set starting agent |
| `.when()` | Add conditional branch |
| `.otherwise()` | Set fallback handler |
| `.run()` | Execute the flow |

***

## API Reference

> [card] [Workflows Module](https://praison.ai/docs/sdk/reference/typescript/modules/workflows.md)
>
> Workflow and flow patterns

> [card] [Conditions Module](https://praison.ai/docs/sdk/reference/typescript/modules/conditions.md)
>
> Conditional routing

***

## Best Practices

> [accordion] Keep flows simple
>
> Start with 2-3 branches, add complexity as needed.

> [accordion] Always have a fallback
>
> Use `.otherwise()` to catch unmatched cases.

> [accordion] Test each path
>
> Verify all branches work before production.

***

## Related

> [card] [Routing](https://praison.ai/docs/js/routing.md)
>
> Request routing

> [card] [Workflows](https://praison.ai/docs/js/workflows.md)
>
> Multi-step workflows


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.