Skip to main content

Overview

Agent Sentinel provides WebSocket endpoints for real-time updates of platform events. This enables:
  • Live dashboard updates as runs complete
  • Real-time approval notifications
  • Intervention alerts as they occur
  • Policy update broadcasts
  • Live statistics refreshes

WebSocket endpoints

Main WebSocket

Connects to the main WebSocket endpoint for all events.

Dashboard WebSocket

Dashboard-specific endpoint with pre-filtered events for dashboard views.

Authentication

WebSocket connections require JWT authentication via query parameter:
Tokens in query parameters are visible in logs. Use WSS (WebSocket Secure) in production and rotate tokens regularly.

Event types

run_created

Fired when a new run is created via ingest:

action_created

Fired when a new action is logged:

stats_updated

Fired when aggregate statistics change (debounced to prevent flooding):

policy_updated

Fired when a policy is created, updated, enabled, or disabled:

intervention_created

Fired when an intervention is recorded:

approval_created

Fired when a new approval request is created:

approval_updated

Fired when an approval status changes (approved, rejected, expired):

approval_expired

Fired when an approval times out:

heartbeat

Periodic keep-alive message (sent every 30 seconds):

Client implementation

JavaScript/TypeScript (Web)

Python client

Connection management

Heartbeat

The server sends heartbeat messages every 30 seconds to keep connections alive. Clients should:
  • Track last heartbeat time
  • Reconnect if no heartbeat received for 60+ seconds

Dead connection cleanup

The server automatically closes connections that:
  • Haven’t received a pong response to ping within 60 seconds
  • Are idle for 5+ minutes with no messages sent

Reconnection strategy

Implement exponential backoff for reconnections:
  1. First retry: 1 second
  2. Second retry: 2 seconds
  3. Third retry: 4 seconds
  4. Fourth retry: 8 seconds
  5. Fifth retry: 16 seconds
  6. Max delay: 30 seconds

Best practices

Implement reconnection logic: WebSocket connections can drop due to network issues - always implement automatic reconnection with exponential backoff.
Debounce rapid updates: Stats updates can fire frequently during high activity - debounce UI updates to prevent performance issues.
Don’t rely solely on WebSocket: Always support polling fallback - WebSockets may be blocked by firewalls or proxies.
Filter events client-side: Subscribe to the main WebSocket but filter events in your client based on what the user is viewing.

Troubleshooting

Connection fails immediately

  • Check token validity: curl -H "Authorization: Bearer $TOKEN" https://platform.agentsentinel.dev/api/v1/users/me
  • Verify WSS (not WS) for HTTPS deployments
  • Check firewall/proxy settings

No events received

  • Verify events are being created (check via REST API)
  • Confirm token has correct organization scope
  • Check for client-side filtering bugs

Frequent disconnections

  • Check network stability
  • Verify heartbeat handling
  • Review server logs for errors

See also