Quick Start
How It Works
| Component | Role |
|---|---|
| Gateway | Central hub managing connections and routing |
| Session | Isolated conversation context per client |
| Agent | AI worker processing requests |
| Event | Structured message for communication |
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
host | str | "127.0.0.1" | Host to bind to |
port | int | 8765 | WebSocket port |
auth_token | str | None | Authentication token |
max_connections | int | 1000 | Maximum concurrent connections |
heartbeat_interval | int | 30 | Heartbeat interval in seconds |
reconnect_timeout | int | 60 | Reconnection timeout |
ssl_cert | str | None | SSL certificate path |
ssl_key | str | None | SSL key path |
push | PushConfig | PushConfig() | Push notification service configuration (disabled by default) |
Push Notifications
Gateway hosts real-time push notification channels for WebSocket and polling-based pub/sub communication between clients.Real-Time Push Notifications
Learn about channel-based pub/sub, presence tracking, and delivery guarantees
YAML Configuration (gateway.yaml)
Configure the gateway with a gateway.yaml file for multi-platform deployment:
Multi-Instance Platforms
Run multiple bots on the same platform using theplatform: field:
Channel Configuration Reference
Every entry underchannels: accepts these fields:
| Field | Type | Default | Description |
|---|---|---|---|
platform | str | inferred from key | Platform name (telegram, discord, slack, whatsapp, email, agentmail). Used by gateway runtime when channel key doesn’t match a platform name (e.g. telegram_cfo). |
token | str | "" | Bot token. Supports ${ENV_VAR} interpolation. |
allowed_users | str or list[str] | [] | User IDs allowed to message this channel. Can be comma-separated string (for ${ENV_VAR}) or list. |
allowed_channels | str or list[str] | [] | Channel IDs where bot responds. Can be comma-separated string or list. |
group_policy | str | "mention_only" | Group chat behaviour: respond_all, mention_only, or command_only. |
auto_approve_tools | bool | true | Whether safe tools are automatically approved without user confirmation. |
default_tools | list[str] | [] | Default tools available to agents in this channel. |
routing / routes | dict[str, str] | {"default": "default"} | Context-to-agent routing — keys are dm / group / channel / default, values are agent IDs from the agents: block. Both field names work. |
Routing Rules
Route messages to different agents based on context:| Context | Description | Example |
|---|---|---|
dm | Direct/private messages | Personal assistant |
group | Group/guild messages | Team support |
channel | Channel messages | Announcements |
default | Fallback for unmatched | General agent |
routes: field on each channel block — routing: and routes: are interchangeable in gateway.yaml. Both field names work at runtime; routes: is the preferred name in examples.
Event Types
Gateway uses typed events for communication:| Event Type | Description |
|---|---|
MESSAGE | Text message between parties |
CONNECT | Client/agent connected |
DISCONNECT | Client/agent disconnected |
ERROR | Error notification |
HEARTBEAT | Keep-alive ping |
BROADCAST | Message to all clients |
Common Patterns
- Multi-Agent Chat
- Secure Gateway
- Session Management
Graceful Shutdown
Long-running servers can stop the wrapper’s background async loop explicitly:shutdown() is also registered via atexit, so it runs automatically on interpreter exit. Call it manually when you need deterministic cleanup (flushing telemetry exporters, closing async HTTP/DB clients) before the process exits.
Single-Instance Enforcement
PraisonAI enforces one gateway per host:port combination using PID locks to prevent conflicts and ensure reliable bot operation. PID Lock File:~/.praisonai/gateway-<host>-<port>.pid
Each lock file contains:
- Process ID of the running gateway
- Host and port being used
- Timestamp of lock creation
- Automatic cleanup of stale locks
GATEWAY_PORT or --port to avoid conflicts.
CLI Commands
Best Practices
Use authentication in production
Use authentication in production
Always set
auth_token when exposing the gateway beyond localhost. This prevents unauthorized access to your agents.Configure appropriate timeouts
Configure appropriate timeouts
Set
session_config.timeout based on your use case. Long-running tasks need longer timeouts, while chat applications can use shorter ones.Enable SSL for remote access
Enable SSL for remote access
Use
ssl_cert and ssl_key when the gateway is accessible over the network. This encrypts all WebSocket traffic.Monitor connection limits
Monitor connection limits
Set
max_connections based on your server capacity. Monitor active connections to prevent resource exhaustion.Single instance per bot token
Single instance per bot token
Each Telegram/Discord/Slack bot token must be polled by exactly one process. PraisonAI enforces a PID lock at
~/.praisonai/gateway-<host>-<port>.pid — start a second instance and you’ll get a clear error pointing at the running PID. Use GATEWAY_PORT=<other> to run a second gateway on another port.Related
Multi-Agent Workflows
Coordinate multiple agents
Sessions
Manage conversation state

