Skip to main content
Gateway provides a WebSocket-based control plane for coordinating multiple agents, managing sessions, and enabling real-time communication between agents and clients.

Quick Start

1

Configure Gateway

from praisonaiagents import GatewayConfig

config = GatewayConfig(
    host="127.0.0.1",
    port=8765,
    auth_token="your-secret-token"
)
2

Start Gateway Server

praisonai serve gateway --port 8765
3

Connect Agents

from praisonaiagents import Agent

agent = Agent(
    name="assistant",
    instructions="You help users with tasks"
)

# Agent automatically connects to gateway

How It Works

ComponentRole
GatewayCentral hub managing connections and routing
SessionIsolated conversation context per client
AgentAI worker processing requests
EventStructured message for communication

Configuration Options

from praisonaiagents import GatewayConfig, SessionConfig

config = GatewayConfig(
    host="127.0.0.1",           # Bind address
    port=8765,                   # WebSocket port
    auth_token="secret",         # Authentication token
    max_connections=1000,        # Max concurrent connections
    heartbeat_interval=30,       # Heartbeat in seconds
    session_config=SessionConfig(
        timeout=3600,            # Session timeout (1 hour)
        max_messages=1000,       # Message history limit
    )
)
OptionTypeDefaultDescription
hoststr"127.0.0.1"Host to bind to
portint8765WebSocket port
auth_tokenstrNoneAuthentication token
max_connectionsint1000Maximum concurrent connections
heartbeat_intervalint30Heartbeat interval in seconds
reconnect_timeoutint60Reconnection timeout
ssl_certstrNoneSSL certificate path
ssl_keystrNoneSSL key path

Event Types

Gateway uses typed events for communication:
from praisonaiagents import GatewayEvent, EventType

# Create an event
event = GatewayEvent(
    type=EventType.MESSAGE,
    data={"content": "Hello!"},
    source="agent-1",
    target="client-1"
)
Event TypeDescription
MESSAGEText message between parties
CONNECTClient/agent connected
DISCONNECTClient/agent disconnected
ERRORError notification
HEARTBEATKeep-alive ping
BROADCASTMessage to all clients

Common Patterns

from praisonaiagents import Agent, GatewayConfig

# Configure gateway
config = GatewayConfig(port=8765)

# Create specialized agents
researcher = Agent(
    name="researcher",
    instructions="Research topics thoroughly"
)

writer = Agent(
    name="writer", 
    instructions="Write clear content"
)

# Agents coordinate via gateway

CLI Commands

# Start gateway server
praisonai serve gateway --port 8765

# Start with authentication
praisonai serve gateway --port 8765 --auth-token "secret"

# Check gateway status
praisonai serve gateway status

# Start with SSL
praisonai serve gateway --ssl-cert cert.pem --ssl-key key.pem

Best Practices

Always set auth_token when exposing the gateway beyond localhost. This prevents unauthorized access to your agents.
Set session_config.timeout based on your use case. Long-running tasks need longer timeouts, while chat applications can use shorter ones.
Use ssl_cert and ssl_key when the gateway is accessible over the network. This encrypts all WebSocket traffic.
Set max_connections based on your server capacity. Monitor active connections to prevent resource exhaustion.