Skip to main content

WebSocket Protocol

Aurora uses WebSocket connections for real-time, bidirectional communication with the AI agent. This enables streaming responses, live tool execution updates, and interactive confirmations.

Connection

Endpoint

(Use wss:// for production with TLS)

Authentication

Authentication is handled via the initialization message after connecting. Connection Example:

Message Protocol

All messages follow a consistent JSON structure:

Client → Server Messages

Initialization

Sent immediately after connection to authenticate the user.
string
default:"init"
Message type identifier
string
required
Authenticated user identifier
Example:

Chat Query

Send a message to the AI agent.
string
required
User’s message text
string
required
User identifier
string
required
Chat session UUID (for context continuity)
string
LLM model to use (e.g., “gpt-4”, “claude-3-opus”)
string
default:"agent"
Chat mode: agent (read-write) or ask (read-only)
string
Active cloud project ID
array
default:"[]"
File attachments (images, PDFs, etc.)
object
UI preferences to save with session
object
Direct tool invocation (bypasses AI decision-making)
Example:

Control Messages

Control ongoing operations.
string
default:"control"
Message type identifier
string
required
Control action: cancel
string
required
Session to control
string
required
User identifier
Example (Cancel):
Cancellation Behavior:
  • Stops ongoing AI workflow
  • Cancels pending infrastructure confirmations
  • Consolidates partial messages
  • Saves context for session resumption
  • Sends END status to client

Confirmation Response

Respond to infrastructure confirmation requests.
string
default:"confirmation_response"
Message type identifier
string
required
ID of the confirmation request
boolean
required
Whether the action is approved
string
required
User identifier
string
required
Session identifier
Example:

Server → Client Messages

Status Messages

Indicate connection and workflow status.
string
default:"status"
Message type
object
string
Status value: START or END
boolean
Whether workflow is complete (only for END)
Example (Start):
Example (End):

Message Chunks

Streamed response text from the AI agent.
string
default:"message"
Message type
object
string
Text content (single token or sentence)
boolean
default:true
Whether this is a streaming chunk
boolean
default:false
Whether the message is complete
boolean
default:true
Whether streaming is active
string
Associated session ID
Example:
Streaming Behavior:
  • Text is sent incrementally as LLM generates it
  • Chunks are split at sentence boundaries for smooth display
  • Multiple chunks combine to form complete messages
  • Large chunks (>100 chars) are automatically split

Tool Call Events

Notify client of tool invocations.
string
default:"tool_call"
Message type
object
string
Name of the tool being called
object
Tool parameters
string
Tool execution status: running, success, error
string
ISO 8601 timestamp
string
Unique identifier for this tool call
string
Tool execution result (when complete)
Example:

Tool Result Events

Report tool execution results.
string
default:"tool_result"
Message type
object
string
Tool that was executed
any
Tool execution result (structure varies by tool)
string
Associated session

Confirmation Requests

Request user approval for infrastructure changes.
string
default:"confirmation_request"
Message type
object
string
Unique confirmation identifier
string
Action requiring approval
object
Details about the proposed change
array
Resources that will be created/modified

Usage Info

API cost tracking information.
string
default:"usage_info"
Message type
object
number
Total API cost in USD (rounded to 2 decimals)
Example:

Error Messages

string
default:"error"
Message type
object
string
Error message
string
Error severity: error, warning
string
Error code (e.g., “READ_ONLY_MODE”)
string
Associated session
Example:

Rate Limiting

WebSocket connections are rate-limited:
  • Rate: 5 messages per 60 seconds per client
  • Enforcement: Token bucket algorithm
  • Response: Error message when limit exceeded

Connection Lifecycle

  1. Connect - Establish WebSocket connection
  2. Initialize - Send init message with user_id
  3. Ready - Receive START status
  4. Chat - Exchange messages and receive responses
  5. Tools - Receive tool call events during execution
  6. Complete - Receive END status when done
  7. Disconnect - Close connection gracefully

Best Practices

Connection Management

  • Implement automatic reconnection with exponential backoff
  • Handle connection drops gracefully
  • Send init message immediately after connecting
  • Monitor connection state and show status to user

Message Handling

  • Buffer message chunks for display
  • Update UI progressively as chunks arrive
  • Show tool execution status in real-time
  • Handle out-of-order messages by session_id

Error Recovery

  • Retry failed messages with exponential backoff
  • Show connection errors to user
  • Allow manual retry of failed operations
  • Preserve unsent messages across reconnections

Performance

  • Keep WebSocket connection alive between messages
  • Reuse connections for multiple sessions
  • Close connections after extended inactivity
  • Monitor memory usage from buffered chunks

Example Client