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:
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 durability. 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.

What’s in development

This page is the platform surface, and it stays. In development on top of it: AgentClient, a browser SDK — browser clients connecting straight to an agent, automatic reconnect, and state sync driven by onStateChanged — with onConnect() on the Agent class as the seam it lands on. Until then, webSocket() is the supported path.