Standalone Bot Gateway
Run the WebSocket gateway without the praisonai wrapper — bot tier only
Register any Agent on a standalone WebSocket gateway with three imports and one asyncio.run().
Quick Start
- Install
bash pip install praisonaiagents "praisonai-bot[gateway]" - Set credentials
bash export OPENAI_API_KEY=your_openai_api_key - Register an agent on the gateway
python import asyncio from praisonaiagents import Agent from praisonaiagents import GatewayConfig from praisonai_bot.gateway import WebSocketGateway assistant = Agent(name="assistant", instructions="You are a helpful assistant.") config = GatewayConfig(host="127.0.0.1", port=8765) gateway = WebSocketGateway(config=config) gateway.register_agent(assistant, agent_id="assistant") if __name__ == "__main__": print("Gateway: ws://127.0.0.1:8765 health: http://127.0.0.1:8765/health") asyncio.run(gateway.start()) - Verify the gateway is running
bash curl http://127.0.0.1:8765/healthThe response confirms the gateway is live with the registered agent.
How It Works
The gateway routes messages from any connected channel to the registered agent. The agent never knows which channel the message came from — it just receives text and returns a response.
Configuration Options
GatewayConfig fields
| Field | Type | Default | Description |
|---|---|---|---|
host | str | "127.0.0.1" | Host to bind the WebSocket server |
port | int | 8765 | Port to listen on |
WebSocketGateway.register_agent() parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
agent | Agent | required | The agent instance to register |
agent_id | Optional[str] | None | Custom ID (auto-generated UUID if not provided) |
overwrite | bool | True | If False, raises ValueError on duplicate agent_id |
Returns: The agent_id string used for registration.
CLI Equivalent
# Canonical (bot-tier only)
praisonai-bot gateway start --host 127.0.0.1 --port 8765
praisonai-bot gateway doctor --config gateway.yaml
# Wrapper alias (requires pip install praisonai) — every subcommand works
praisonai gateway start --host 127.0.0.1 --port 8765
praisonai gateway doctor --config gateway.yamlCommon Patterns
Multiple agents on one gateway
import asyncio
from praisonaiagents import Agent
from praisonaiagents import GatewayConfig
from praisonai_bot.gateway import WebSocketGateway
support = Agent(name="support", instructions="Handle customer support tickets.")
sales = Agent(name="sales", instructions="Answer product and pricing questions.")
config = GatewayConfig(host="127.0.0.1", port=8765)
gateway = WebSocketGateway(config=config)
gateway.register_agent(support, agent_id="support")
gateway.register_agent(sales, agent_id="sales")
asyncio.run(gateway.start())Custom agent ID
from praisonaiagents import Agent
from praisonaiagents import GatewayConfig
from praisonai_bot.gateway import WebSocketGateway
agent = Agent(name="assistant", instructions="You are helpful.")
config = GatewayConfig(host="0.0.0.0", port=8765)
gateway = WebSocketGateway(config=config)
# Returns the registered agent_id
aid = gateway.register_agent(agent, agent_id="my-assistant")
print(f"Registered as: {aid}")Imports: bot-first and wrapper shims
# Canonical (bot-tier, no wrapper required)
from praisonai_bot.gateway import WebSocketGateway
# Wrapper shim (requires pip install praisonai)
from praisonai.gateway import WebSocketGatewayBest Practices
Use agent_id for stable routing
Assign explicit agent_id values. Channel clients connect by agent ID — changing it after deployment disconnects existing sessions.
gateway.register_agent(agent, agent_id="assistant-v2")Bind to 0.0.0.0 only on trusted networks
host="127.0.0.1" (loopback) is safe for local development. For production, bind to 0.0.0.0 only behind a reverse proxy with TLS termination.
Check /health before routing traffic
The health endpoint (http://host:port/health) returns 200 OK when the gateway is ready. Use it in your load balancer or process manager health check.
Use YAML for declarative configuration
For multi-agent, multi-channel setups, use the standalone YAML format instead of Python to keep credentials and topology out of code.
See Standalone Bot YAML for details.