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

# Routing

> Direct requests to specialized agents

Agents can route user requests to the most appropriate specialist automatically.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    User([User]) --> Router[Router]
    Router --> Specialist([Specialist Agent])

    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef tool fill:#189AB4,stroke:#7C90A0,color:#fff

    class Router agent
    class User,Specialist tool
    classDef agent fill:#8B0000,color:#fff
    classDef tool fill:#189AB4,color:#fff
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    import { Agent, Router } from 'praisonai';

    const salesAgent = new Agent({ instructions: 'You handle sales inquiries' });
    const techAgent = new Agent({ instructions: 'You provide tech support' });

    const router = new Router({
      agents: [salesAgent, techAgent],
      defaultAgent: techAgent
    });

    // Automatically routes to the right agent
    const response = await router.route("I'd like to buy your product");
    // → Sales agent responds
    ```
  </Step>

  <Step title="With Configuration">
    ```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    const router = new Router({
      routes: [
        { agent: salesAgent, keywords: ['buy', 'price', 'purchase'] },
        { agent: techAgent, keywords: ['error', 'bug', 'help'] }
      ]
    });
    ```
  </Step>
</Steps>

***

## User Interaction Flow

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant User
    participant Router
    participant Agent
    
    User->>Router: "I want to buy"
    Router->>Router: Match keywords
    Router->>Agent: Route to Sales
    Agent-->>User: "Happy to help..."
```

***

## Configuration Levels

```typescript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
// Level 1: Array - Simple agent list
const router = new Router({
  agents: [salesAgent, techAgent]
});

// Level 2: Dict - With keywords
const router = new Router({
  routes: [
    { agent: salesAgent, keywords: ['buy', 'price'] }
  ]
});

// Level 3: Instance - Full control
const router = new Router({
  routes: [
    {
      agent: salesAgent,
      condition: (input) => input.includes('purchase'),
      priority: 1
    }
  ],
  defaultAgent: generalAgent
});
```

***

## Routing Options

| Option         | Description                       |
| -------------- | --------------------------------- |
| `agents`       | List of agents to route to        |
| `routes`       | Route definitions with conditions |
| `defaultAgent` | Fallback when no match            |
| `priority`     | Route priority (lower = first)    |

***

## API Reference

<Card title="Conditions Module" icon="code" href="/docs/sdk/reference/typescript/modules/conditions">
  Routing conditions module
</Card>

***

## Best Practices

<AccordionGroup>
  <Accordion title="Set a default agent">
    Always have a fallback for unmatched requests.
  </Accordion>

  <Accordion title="Use clear keywords">
    Distinct keywords for each route prevent confusion.
  </Accordion>

  <Accordion title="Keep routes simple">
    Start with keyword matching, add complexity only if needed.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Handoffs" icon="hand" href="/docs/js/handoffs">
    Transfer conversations
  </Card>

  <Card title="Teams" icon="users" href="/docs/js/teams">
    Multi-agent teams
  </Card>
</CardGroup>
