Skip to content

Gateway WebSocket Protocol

The Gateway WebSocket Protocol defines how clients communicate with agents through the Aigentic gateway. Use this protocol to build custom frontends, automation scripts, or integrations that interact with agents outside of the Aigentic console.

Establish an authenticated session with the Aigentic platform before opening a WebSocket connection. The specific authentication mechanism depends on your integration type.

Connect to the gateway WebSocket endpoint:

wss://aigentic.life/ws?token=<session_token>

Upon successful connection, the server sends an acknowledgment:

{
"type": "connection.ack",
"data": {
"session_id": "sess_abc123",
"connected_agents": [
{
"agent_id": "agent-001",
"agent_name": "Research Assistant",
"status": "running"
}
]
}
}
Client Gateway Agent
│ │ │
│──── WebSocket connect ────────►│ │
│◄─── connection.ack ──────────│ │
│ │ │
│──── chat.message ─────────────►│──── forward to agent ────────►│
│ │ │
│◄─── chat.stream.start ───────│◄─── response stream ──────────│
│◄─── chat.stream.delta ───────│ │
│◄─── chat.stream.delta ───────│ │
│◄─── chat.stream.end ─────────│ │
│ │ │
│──── connection.close ─────────►│ │

All messages are JSON objects with a type field and a data field.

Send a message to an agent.

{
"type": "chat.message",
"data": {
"agent_id": "agent-001",
"content": "What are the latest trends in AI safety research?",
"session_id": "sess_abc123"
}
}
FieldTypeRequiredDescription
agent_idstringYesThe target agent’s ID
contentstringYesThe message text
session_idstringNoConversation session (auto-generated if omitted)

Cancel an in-progress response.

{
"type": "chat.cancel",
"data": {
"agent_id": "agent-001",
"session_id": "sess_abc123"
}
}

Keep-alive ping. The server responds with connection.pong.

{
"type": "connection.ping",
"data": {}
}

Indicates the agent has started generating a response.

{
"type": "chat.stream.start",
"data": {
"agent_id": "agent-001",
"session_id": "sess_abc123",
"message_id": "msg_xyz789"
}
}

A chunk of the agent’s response. These arrive incrementally as the model generates text.

{
"type": "chat.stream.delta",
"data": {
"agent_id": "agent-001",
"message_id": "msg_xyz789",
"content": "Based on recent research",
"index": 0
}
}

Concatenate all content values from delta messages in order to reconstruct the full response.

The response is complete.

{
"type": "chat.stream.end",
"data": {
"agent_id": "agent-001",
"message_id": "msg_xyz789",
"finish_reason": "complete",
"usage": {
"input_tokens": 1250,
"output_tokens": 487
}
}
}
finish_reasonMeaning
completeThe model finished its response naturally
max_tokensResponse reached the maximum token limit
cancelledResponse was cancelled by the client
errorAn error occurred during generation

Notifies the client that the agent is invoking a tool.

{
"type": "tool.invocation",
"data": {
"agent_id": "agent-001",
"message_id": "msg_xyz789",
"tool_name": "web_search",
"tool_input": {
"query": "AI safety research 2026"
},
"invocation_id": "inv_abc123"
}
}

The result of a tool invocation.

{
"type": "tool.result",
"data": {
"agent_id": "agent-001",
"invocation_id": "inv_abc123",
"status": "success",
"output": {
"results": [
{"title": "...", "url": "...", "snippet": "..."}
]
},
"duration_ms": 1200
}
}

An error occurred.

{
"type": "event.error",
"data": {
"code": "AGENT_UNAVAILABLE",
"message": "Agent agent-001 is not available.",
"agent_id": "agent-001",
"recoverable": true
}
}

Common error codes:

CodeDescription
AGENT_UNAVAILABLETarget agent is not available
AUTH_EXPIREDSession token has expired
RATE_LIMITEDToo many requests
TOOL_DENIEDTool invocation was blocked by permissions
INTERNAL_ERRORUnexpected server error

Response to a connection.ping.

{
"type": "connection.pong",
"data": {
"timestamp": "2026-01-15T08:30:00Z"
}
}

Send connection.ping messages at least every 30 seconds to keep the connection alive. If the server does not receive a ping within 60 seconds, it closes the connection.

The gateway rate-limits client messages to prevent overload:

LimitValue
Messages per second10
Messages per minute120
Concurrent streams per agent1

If rate-limited, the server sends an event.error with code RATE_LIMITED.

The current protocol version is v1. The version is included in the connection acknowledgment message.