Bot Message Routing
Route messages from different chat contexts (DMs, groups, channels) to specific AI agents.
Quick Start
- Define your agents
python from praisonaiagents import Agent personal_agent = Agent(name="personal", instructions="Handle personal questions.") support_agent = Agent(name="support", instructions="Handle support requests.") personal_agent.start("Route DMs to me, group messages to support.") - Serve with routing
bash praisonai bot serveThe user messages in a DM or group; the gateway matches the chat context and forwards the turn to the configured agent.
routes: is the preferred field name for gateway routing configuration — gateway runtime accepts both routing: and routes: interchangeably in YAML.
Message routing lets you send different types of messages to different AI agents. For example, direct messages go to your personal assistant, while group messages go to a support agent.
How Routing Works
The user sends a message; the gateway detects the chat context, looks up the matching route, and forwards the turn to that agent.
- Message Arrives
A user sends a message on Telegram, Discord, or Slack.
- Context Detection
The gateway detects where the message came from — a DM, group, or channel.
- Route Lookup
The gateway checks the
routestable ingateway.yamlfor that context. - Agent Handles Message
The matched agent receives the message and responds.
A user messages from a DM or group; the gateway detects the context, picks the matching agent, and returns its reply.
Route Contexts
| Context | Description | Example |
|---|---|---|
| dm | Direct / private message | User sends a DM to your bot |
| group | Group chat message | Message in a Telegram group or Discord server |
| channel | Channel message | Message in a Slack channel |
| default | Fallback for any unmatched context | Any message that doesn’t match above |
Configuration
Define routes in the channels section of gateway.yaml:
channels:
telegram:
token: ${TELEGRAM_BOT_TOKEN}
routes:
dm: personal # DMs → personal agent
group: support # Groups → support agent
default: personal # Everything else → personal agent
discord:
token: ${DISCORD_BOT_TOKEN}
routes:
dm: personal
group: support
default: personal
slack:
token: ${SLACK_BOT_TOKEN}
app_token: ${SLACK_APP_TOKEN}
routes:
dm: support
channel: support
default: support
whatsapp:
mode: web # or: token: ${WHATSAPP_ACCESS_TOKEN}
routes:
dm: personal
group: support
default: personalRouting Examples
Personal + Support
Route DMs to a personal assistant and group messages to support:
agents:
personal:
instructions: "You are a helpful personal assistant"
model: gpt-4o-mini
support:
instructions: "You are a customer support agent"
model: gpt-4o
channels:
telegram:
token: ${TELEGRAM_BOT_TOKEN}
routes:
dm: personal
group: support
default: personalSingle Agent
Route all messages to one agent:
agents:
assistant:
instructions: "You are a helpful assistant"
model: gpt-4o-mini
channels:
discord:
token: ${DISCORD_BOT_TOKEN}
routes:
default: assistantMulti-Channel
Different agents per platform:
agents:
telegram_agent:
instructions: "Telegram-optimized assistant"
model: gpt-4o-mini
slack_agent:
instructions: "Slack workspace assistant"
model: gpt-4o
channels:
telegram:
token: ${TELEGRAM_BOT_TOKEN}
routes:
default: telegram_agent
slack:
token: ${SLACK_BOT_TOKEN}
routes:
default: slack_agentWorkforce (one platform, many roles)
Multiple specialized bots on the same platform:
agents:
cfo:
instructions: "You are a CFO agent. Help with financial analysis and budget planning."
model: gpt-4o-mini
ops:
instructions: "You are an ops agent. Help with system monitoring and deployment."
model: gpt-4o-mini
content:
instructions: "You are a content agent. Help with writing and content strategy."
model: gpt-4o-mini
channels:
telegram_cfo:
platform: telegram
token: ${TELEGRAM_CFO_BOT_TOKEN}
routes:
default: cfo
telegram_ops:
platform: telegram
token: ${TELEGRAM_OPS_BOT_TOKEN}
routes:
default: ops
telegram_content:
platform: telegram
token: ${TELEGRAM_CONTENT_BOT_TOKEN}
routes:
default: contentGoing further: per-peer, per-role, per-channel, per-thread or per-server bindings
When chat-type routing isn’t specific enough — e.g. one specific user, a Discord role, a specific channel id, a single thread, or a whole server — use the priority-ordered bindings surface.
Gateway Route BindingsRoute by sender, role, channel id, thread, or whole server — with priority ordering.
channels:
telegram:
routes:
default: general
bindings:
- { peer: "12345678", agent: vip }
- { role: support, agent: support }
- { channel_id: "-100999", agent: ops }
- { thread_id: "77", agent: escalations } # one specific thread/forum-topic
- { guild_id: "9001", agent: support, profile: acme } # a whole server/workspaceRouting Flow Diagram
Best Practices
Always define a default route
Set default on every channel so unexpected contexts (new group types, API changes) still reach an agent instead of failing silently.
Isolate agents by context
Route dm and group to different agents when personal and support workflows must not share memory or tools. See Platform-Aware Agents.
Use bindings for fine-grained routing
When chat-type routing is not enough, add priority-ordered Gateway Route Bindings for specific users, roles, channels, threads, or whole servers.
Scope tools per route
Pair routing with Gateway Tool Policy so public group chats cannot invoke dangerous tools available to trusted DMs.