Skip to main content
An Agent can terminate WebSockets today. The capability comes from StatefulActor: define one method, webSocket(), and the agent owns the live socket — frames dispatch one at a time, serialized with RPCs and tasks like every other call, with history, state, and timers right there in the handler.
Actor WebSocket support is in beta — the platform guide carries the full contract and current caveats.

The shape

A function terminates the handshake — authenticate once, pick the agent, hand off — and the agent handles every frame after that:
That front door is hand-written, and it serves whatever shape you give it. To get the /agents/<mount>/<name> address the AgentClient examples use — with the upgrade check, credential extraction, name encoding, and health routes already written — mount the agent instead: see Mounting Agents and mountAgents. The frame handler follows the same rule as the webhook path in the Quickstart: append to history, queue() the LLM turn, return. A message handler runs under the 30-second method budget, and while it runs every other frame, RPC, and task on this agent waits — so respond() does the slow thinking in a task, then pushes the reply to every open socket with this.ctx.broadcast().

Pushing without an inbound frame

Tasks run inside the agent, so a timer can push. Use the scheduler — not raw alarms, which the SDK reserves for the task queue:

What to know before shipping

  • Connections are capped at about five minutes today, measured from the handshake, even on a socket actively exchanging frames — surfacing as an abnormal close (code 1006). The cap will be raised in a future update. Reconnecting is the client’s job: back off and reopen the same name. idFromName routes the new socket to the same agent, where history, state, and pending tasks all survived — only the socket is new.
  • Sends aren’t held for persistence. ws.send() and broadcast() are immediate; a handler that sends and then throws leaves the client holding a frame about state that never committed. Frames that carry the message log’s seq let a client detect gaps and re-derive on reconnect.
  • Bound per-frame work. Frames that arrive while a handler runs queue up to 256 events or 1 MiB; overflow closes the socket with 1013. Batch chatty clients into fewer, larger frames.
Close codes, reconnect strategy, and the full contract: actor WebSockets and Connection Lifecycle.

The agent connection layer

This page is the platform surface, and it stays. On top of it (SDK ≥ 0.10.0): AgentClient (@telnyx/edge-runtime/client), a browser SDK with automatic reconnect, state/message sync, and cursor-based resume, paired with AgentSocketServer (@telnyx/edge-runtime/agent-socket) on the agent side — including token authorization via an authorize hook and claim-gated RPC. Client-callable methods are opt-in via the @rpc() decorator. Full reference pages for the connection layer are in progress.