Skip to content

WebSocket Protocol

This document describes the WebSocket protocol used by Omnia agent facades.

ws://host:port?agent=<agent-name>&namespace=<namespace>
ParameterRequiredDescription
agentYesName of the AgentRuntime
namespaceNoNamespace (defaults to default)
Terminal window
websocat "ws://localhost:8080?agent=my-agent&namespace=production"

Messages sent from client to server.

Send a user message to the agent:

{
"type": "message",
"content": "Hello, how are you?",
"session_id": "optional-session-id",
"metadata": {
"user_id": "user-123"
}
}
FieldTypeRequiredDescription
typestringYesMust be "message"
contentstringYesUser message content
session_idstringNoResume existing session
metadataobjectNoCustom metadata

Messages sent from server to client.

Sent immediately after connection:

{
"type": "connected",
"session_id": "sess-abc123"
}

Streaming response chunk:

{
"type": "chunk",
"content": "Hello! I'm doing"
}

Final response completion:

{
"type": "done",
"content": "Hello! I'm doing great, thank you for asking!"
}

Agent is calling a tool:

{
"type": "tool_call",
"tool_call": {
"id": "tc-123",
"name": "weather",
"arguments": {
"location": "San Francisco"
}
}
}

Result from a tool call:

{
"type": "tool_result",
"tool_result": {
"id": "tc-123",
"result": "72°F, Sunny"
}
}

Error message:

{
"type": "error",
"error": {
"code": "INVALID_MESSAGE",
"message": "Failed to parse message"
}
}
CodeDescription
INVALID_MESSAGEMessage format is invalid
SESSION_NOT_FOUNDSpecified session doesn’t exist
PROVIDER_ERRORLLM provider returned an error
TOOL_ERRORTool execution failed
INTERNAL_ERRORInternal server error
sequenceDiagram
participant C as Client
participant S as Server
C->>S: WebSocket connect
S-->>C: connected (session_id)
C->>S: message
S-->>C: chunk
S-->>C: chunk
S-->>C: done
sequenceDiagram
participant C as Client
participant S as Server
participant T as Tool Service
C->>S: message
S->>T: Execute tool
S-->>C: tool_call
T-->>S: Result
S-->>C: tool_result
S-->>C: chunk
S-->>C: done
sequenceDiagram
participant C as Client
participant S as Server
participant R as Session Store
C->>S: WebSocket connect
S-->>C: connected (session_id)
C->>S: message (with session_id)
S->>R: Load session history
R-->>S: History
S-->>C: done (with context)

Omit session_id to create a new session:

{"type": "message", "content": "Hello"}

The server responds with a connected message containing the new session ID.

Include session_id to resume:

{
"type": "message",
"session_id": "sess-abc123",
"content": "Continue our conversation"
}

If the session exists and hasn’t expired, conversation history is preserved.

Sessions expire based on the AgentRuntime’s session.ttl configuration. Attempting to resume an expired session creates a new one.

The server sends WebSocket ping frames to maintain connection health. Clients should respond with pong frames automatically (most WebSocket libraries handle this).

Default timeouts:

  • Ping interval: 30 seconds
  • Pong timeout: 60 seconds