Skip to main content
The gateway now ships in the praisonai-bot package. praisonai serve gateway still works exactly as documented here; for a standalone install see praisonai-bot Migration.
The PraisonAI Gateway enables multi-channel agent deployment through a WebSocket server that coordinates communication between agents and various platforms. The user starts the gateway and sends a message on a channel; the gateway routes it to the right agent and returns the reply.

Quick Start

1

Install Gateway Dependencies

Install both bot and API dependencies for gateway functionality:
The [api] extra provides uvicorn, fastapi, and starlette required by the gateway server.
2

Create Gateway Configuration

Create a gateway.yaml file:
3

Start the Gateway

Launch the gateway server:
The gateway starts on port 8765 with WebSocket and HTTP health endpoints.

How It Works


Architecture Principles

Single Instance Rule

Critical: Only run one gateway process per machine. Multiple processes conflict:
  • Both try to bind port 8765
  • Both poll the same Telegram token (causes 409 conflicts)
  • Session state becomes inconsistent

Channel Isolation

Each channel operates independently:
  • Separate token per platform
  • Independent routing rules
  • Isolated session management
  • Per-channel error handling

Live Config Reload

The gateway diffs gateway.yaml against the running config and restarts only affected agents or channels — and for three timing/logging keys, applies the change in place with no restart at all. Invalid YAML saves keep the last-known-good config. The WebSocket server is never restarted. See Gateway Hot-Reload.

Fail-Safe Design

The gateway implements fail-safe patterns:
  • Health checks at /health endpoint
  • Automatic reconnection for platform polling
  • Graceful degradation when agents are unavailable
  • Request timeout handling (25-30 seconds for RAG)
  • Versioned hello handshake with capability negotiation — see Handshake Protocol. Connecting from Python, the bundled praisonai-bot client performs this handshake automatically and exposes the negotiated client.features / client.policy / client.heartbeat_ms — see Client-side wiring.
  • Shutdown forensics — on every exit, one log line and one diagnostic file record why the gateway stopped. See Crash Forensics.
  • Opt-in close-the-loop notice on permanent delivery failure — see Undelivered Message Notice.

Config Validation

A typo in gateway.yaml won’t start a broken gateway — it fails fast with exit 78 before your users notice. praisonai gateway start and praisonai bot serve now validate the same gateway.yaml to the same standard: canonical configs start, legacy configs auto-migrate then start, and typos exit 78. The validator consults the platform registry — built-in platforms plus any published via praisonai.channels / praisonai.bots entry points plus any registered at runtime with register_platform().
Before: warns, gateway starts, /health returns 200 — but Telegram is silently dead.
After: rejected before startup, exit 78 — the supervisor does not crash-loop.
Before: spurious “not a known platform” warning, then starts.After: accepted with no warning — linear is a shipped adapter on the registry.
Before: warned “not a known platform”, gateway started, channel silently dead on the runtime path.After: accepted on both praisonai bot serve and praisonai gateway start.
See Gateway Exit Codes for how to wire your supervisor so a fatal config error alerts instead of restart-looping.

Gateway Modes

Run multiple platforms simultaneously:
Each channel requires a unique token and can route to different agents.
Pure WebSocket server without chat platforms:
Provides WebSocket endpoint for custom client integration.
Load agents from separate configuration:
Separates agent definitions from gateway configuration.

Health Monitoring

The gateway exposes health information:
Response:

Health Check Limitations

Current implementation limitations:
  • "running": true doesn’t guarantee platform polling health
  • No detection of Telegram 409 conflicts until PraisonAI fix ships
  • Manual verification required for silent bot issues

Configuration Options

For complete configuration reference, see the auto-generated SDK documentation. The table below shows common options.

Best Practices

You can change agent instructions, models, or a single channel section while the gateway runs. Agent-only edits recreate agents without restarting channels. See Hot-Reload.
Never hardcode tokens in configuration files:
Store tokens in .env file or environment variables.
Monitor gateway logs for platform-specific errors:
Set appropriate limits based on expected load:
Each channel must have its own platform token:
Never reuse tokens across channels.

Cost Optimization

Running a PraisonAI gateway on serverless hosts (Fly.io Machines, Modal, Cloud Run) charges for every second the machine is alive — even when no users are chatting. The Scale-to-Zero feature lets the gateway stand transports down after a configurable period of silence and wake back up on the next inbound message, so you pay only for active time.

Scale-to-Zero Gateway

Suspend the gateway when idle and wake on the next message — pay only for active time.

Lifecycle

Three opt-in lifecycle policies wire into the primary WebSocketGateway through a lifecycle: block in gateway.yaml, matching CLI flags, and a Python surface. Each is off unless enabled, and configured features surface under health()["lifecycle"].

Scale to Zero

Quiesce when idle for idle_minutes and self-wake on the next message.

Drain Trigger

Epoch-safe external drain marker with a built-in watcher.

Crash-Loop Guard

Halt auto-resume of a channel that keeps crashing on resume.

Event-Loop Watchdog

Detect a wedged asyncio loop and restart before it becomes a zombie.

Admission Control

Bound concurrent inbound agent runs with a fair queue and overflow policy

Session Persistence

Survive restarts and resume mid-conversation

Windows Deployment

Complete Windows setup guide

Multi-Channel Telegram

Hermes-style workforce deployment

Scale to Zero

Pay only for active time — idle-dormancy for serverless hosts

Tracing Hook

Emit OpenTelemetry spans across each pipeline stage

Undelivered Notice

Notify users and operators when a reply can’t be delivered