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.
Flow control bounds per-session inboxes and disconnects slow consumers so a single misbehaving client can’t degrade the whole gateway.
The user sends bursts of messages; per-client inbox and outbound byte limits queue, drop, or close connections before the agent is overwhelmed.

Quick Start

1

Defaults work out of the box

Flow control is enabled by default — no configuration needed. Every session gets a 256-message inbox and the gateway disconnects clients whose transport buffer exceeds 1 MB or whose outbound frame queue exceeds 1000 frames.
2

Tune the limits

Adjust thresholds to match your workload.

How It Works

Two checks protect the gateway from overload: A frame is rejected when either ceiling would be exceeded, or a single frame already exceeds max_buffered_bytes on its own.

Configuration Options

max_inbox is set on SessionConfig; max_buffered_bytes and max_queued_frames are set on GatewayConfig.
These options are also available in gateway.yaml:

Client-Side Error Contract

When the inbox is full, the gateway sends this JSON frame before rejecting the message:
When either transport ceiling is exceeded for a critical event, the gateway closes the WebSocket with:
  • Code: 1013 (Try Again Later)
  • Reason: "slow_consumer" (the value of GatewayCloseCode.SLOW_CONSUMER)
Use the typed enum from Python clients:
Clients should reconnect and resume from the last known message. The gateway preserves session state during the resume_window (default 24 h), so conversation context is not lost.

Common Patterns

Chat-heavy workloads — Tighten the inbox to shed load early and fail fast:
Long-running tools — Loosen both limits to avoid spurious disconnections during slow AI responses:
Stream-heavy workloads — Lower max_queued_frames to shed load on backpressure earlier:
Local development — Disable slow-consumer checks so network hiccups don’t interrupt debugging:

Best Practices

An unlimited inbox (max_inbox=0) lets a slow or malicious client queue messages indefinitely, eventually exhausting gateway memory. Reserve it for local testing only.
A typical chat message is a few kilobytes. Set max_buffered_bytes to at least 10× your largest expected event payload. For file-transfer or streaming use cases, increase to 4–8 MB.
When your client receives {"code": "inbox_full"}, pause new sends and retry with exponential backoff (e.g., 1 s → 2 s → 4 s). Do not flood the gateway with immediate retries.
On receiving WebSocket close code 1013 with reason "slow_consumer", reconnect after a short delay and replay any messages that were in-flight. The gateway preserves session state during the resume_window (default 24 h), so conversation context is not lost.
Set max_queued_frames=0 to bound only by bytes (good for large but infrequent payloads); set max_buffered_bytes=0 to bound only by frame count.
The same max_payload limit is surfaced client-side as client.policy["max_payload"] by the bundled praisonai-bot client, which raises PayloadTooLarge locally before an oversized frame hits the wire. See Client-side wiring.

Flow control bounds outbound send throughput and per-session inbox depth. For bounding inbound concurrent agent runs across all users, see Admission Control.

Gateway Admission Control

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

Gateway

Full gateway configuration and YAML reference

Gateway Error Handling

Error handling patterns for the gateway

Gateway Rate Limit

Bound inbound turns per identity/scope — the inbound admission-side counterpart