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().

Diagram

Standalone Bot Gateway

🤖 Agent

🗼 praisonai-bot\nGateway

💬 Telegram

🎮 Discord

📱 Slack

🔌 Custom Channel

Quick Start

  1. Install
    bash
    pip install praisonaiagents "praisonai-bot[gateway]"
  2. Set credentials
    bash
    export OPENAI_API_KEY=your_openai_api_key
  3. 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())
  4. Verify the gateway is running
    bash
    curl http://127.0.0.1:8765/health

    The response confirms the gateway is live with the registered agent.


How It Works

Diagram
AgentWebSocket GatewayChannel (Telegram/Discord)UserAgentWebSocket GatewayChannel (Telegram/Discord)UserSend messageWebSocket messageagent.chat(message)response textWebSocket replyDisplay response

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

FieldTypeDefaultDescription
hoststr"127.0.0.1"Host to bind the WebSocket server
portint8765Port to listen on

WebSocketGateway.register_agent() parameters

ParameterTypeDefaultDescription
agentAgentrequiredThe agent instance to register
agent_idOptional[str]NoneCustom ID (auto-generated UUID if not provided)
overwriteboolTrueIf False, raises ValueError on duplicate agent_id

Returns: The agent_id string used for registration.


CLI Equivalent

bash
# 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.yaml

Common Patterns

Multiple agents on one gateway

python
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

python
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

python
# Canonical (bot-tier, no wrapper required)
from praisonai_bot.gateway import WebSocketGateway

# Wrapper shim (requires pip install praisonai)
from praisonai.gateway import WebSocketGateway

Best 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.

python
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.


Related