Agent Presence
Track AI agent status with Protocol V2 presence updates and optional disconnect grace.
Agent presence lets every device in a session see what the agent is doing right now (idle,
thinking, or streaming) and whether it is still connected. It uses ordinary presence channels plus
one V2 frame, sockudo:presence_update, which changes a member’s data in place instead of making
it leave and re-join. Use it to drive typing indicators, “agent is thinking” spinners, and
handoff UIs.
How it works
A presence channel tracks who is subscribed and carries a small JSON payload per member. With
Protocol V1, the only way to change that payload is to leave and re-enter the channel, which every
other member sees as a departure followed by an arrival. sockudo:presence_update replaces the
payload for an existing member without that flap.
sequenceDiagram participant A as Agent worker participant S as Sockudo participant U as User devices A->>S: subscribe presence-ai-session-123 S-->>U: member_added A->>S: sockudo:presence_update (thinking) S-->>U: presence update (thinking) A->>S: sockudo:presence_update (streaming) S-->>U: presence update (streaming) Note over S,U: late joiners get latest data in the snapshot
Status convention
Sockudo does not interpret member data. The SDKs and examples use a status field:
{ "status": "idle" }{ "status": "thinking" }{ "status": "streaming" }Keep the payload small. Put run identifiers or progress details in channel events, not in presence data.
Send an update
-
Connect with Protocol V2 and subscribe to a
presence-channel. Capability-token connections need thepresenceoperation for that channel. -
Wait until the subscription succeeds; the connection must already be a member of the presence channel before it can update its data.
-
Send the update frame with the channel name and the new member data:
{"event": "sockudo:presence_update","data": {"channel": "presence-ai-session-123","data": { "status": "thinking" }}}
Other V2 members receive a sockudo_internal:presence_update event whose data contains user_id
and the new user_info. If presence history is enabled for the channel, the transition is
recorded there too, and apps subscribed to the member_updated webhook are notified.
Late joiners see the latest member data in the presence snapshot returned with
subscription_succeeded.
Limits and access
| Rule | Behavior when violated |
|---|---|
| Protocol V2 only. | Rejected with 104009 ai_presence_update_invalid. |
The target must be a presence- channel, and the connection must already be a member. | Rejected with 104009. |
Capability-token connections need presence permission for the channel. | Rejected as a capability failure. |
Member data is capped at 1 KiB (1024 bytes, JSON-encoded). | Rejected with 40009 payload_too_large. |
Updates are rate limited per app/channel/member by [presence].update_rate_limit_per_member_per_second, default 10. | Rejected with the client-event rate-limit error. |
V1/Pusher clients do not receive update events.
Disconnect grace
Agents and mobile clients drop connections for a few seconds all the time. Presence can hold a member during a short grace window so a brief network loss does not look like the agent left.
| Setting | Default | Applies to |
|---|---|---|
[presence].ungraceful_timeout_seconds | 0 | Protocol V1 abnormal disconnects. 0 preserves legacy immediate member_removed timing. |
[presence].v2_ungraceful_timeout_seconds | 15 | Protocol V2 abnormal disconnects, so transient transport loss does not produce a leave/enter flap. |
Clean unsubscribe and clean WebSocket close still remove immediately. A V2 client that resumes within the window keeps its membership without a flap.
[presence]update_rate_limit_per_member_per_second = 10ungraceful_timeout_seconds = 0v2_ungraceful_timeout_seconds = 15