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

Quick Start

1

Create Router Agent

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
2

With Conditions

const router = new Router({
  routes: [
    { agent: salesAgent, keywords: ['buy', 'price', 'purchase'] },
    { agent: techAgent, keywords: ['error', 'bug', 'help'] }
  ]
});

User Interaction Flow


Configuration Levels

// 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

OptionDescription
agentsList of agents to route to
routesRoute definitions with conditions
defaultAgentFallback when no match
priorityRoute priority (lower = first)

API Reference

Conditions Module

Routing conditions module

Best Practices

Always have a fallback for unmatched requests.
Distinct keywords for each route prevent confusion.
Start with keyword matching, add complexity only if needed.