Is WebSockets enough for AI chat?
Blog post from Ably
WebSockets are considered the optimal protocol for production AI chat due to their bidirectional and persistent nature, which supports live steering and tool calls, unlike Server-Sent Events (SSE), which is unidirectional. However, WebSockets are stateless at the session level, meaning that when a connection closes due to a proxy timeout, page reload, or device switch, all session state is lost. Reconnection logic can re-establish the transport layer quickly but fails to recover any tokens, tool call results, or agent context that were in progress when the connection dropped. The solution to this issue lies in implementing a session layer that persists conversation state with a session ID, allowing reconnection clients to retrieve all missed information. Ably AI Transport offers a durable session layer that addresses these challenges by storing tokens, agent states, and tool call outputs against a session ID, ensuring that reconnection clients receive complete context. This approach overcomes the limitations of infrastructure defaults like AWS ALB and Cloudflare, which can lead to connection drops, and it supports multi-device sessions, offset-based replays, and protocol fallback to maintain continuity across various network conditions.