Run-loop WebSocket
The run-loop endpoint moves the agent loop server-side. Instead of you calling the model, parsing tool calls, and re-prompting, the server runs the model↔tool iteration and streams you frames. Your client’s job is to execute tool calls and send results back — a tool-executor.This is a bespoke JSON-over-WebSocket protocol, not OpenAI-wire. Each frame
is a single JSON object with a
type field.Lifecycle
Connect & authenticate
Open the socket, then send an
auth frame with your aius_… token. You have
~5 seconds; an invalid token closes the socket (code 1008).Execute tools
For each
tool_call frame, run the tool locally and reply with a
tool_result frame. Render any assistant_message frames as they arrive.Client → server frames
auth (required, first)
start (required, second)
| Field | Type | Required | Notes |
|---|---|---|---|
type | string | Yes | Must be "start". |
agent | string | No | Agent profile to run (e.g. build). Influences server-side config. |
model | string | No | Anthropic Claude slug. Defaults server-side if omitted. |
messages | array | Yes | OpenAI-wire seed messages for the conversation. |
generate_title | boolean | No | If true, the server emits a one-off title frame for the session. |
session_id / run_id / step_run_id | string | No | Provide to resume / correlate; otherwise the server generates them. |
tool_result (in response to each tool_call)
| Field | Type | Notes |
|---|---|---|
tool_call_id | string | Must match the tool_call frame’s tool_call_id. |
status | string | "ok" on success; anything else is treated as a failure. Defaults to "ok". |
result | any | The tool output. Strings are passed through; other JSON values are stringified before being fed back to the model. |
Server → client frames
ready
Sent once after a valid start. Capture these IDs for correlation/resume.
title (optional)
Only when generate_title: true was sent — a generated, human-readable session
title. Best-effort; may not arrive.
assistant_message
The agent’s prose for an iteration. Emitted mid-run alongside tool calls, and
again at the end for the final message. Use id to key/dedupe blocks so
successive messages render as distinct turns.
tool_call
The server wants your client to execute a tool. Run it, then reply with a
matching tool_result.
| Field | Notes |
|---|---|
tool_call_id | Echo this back in your tool_result. |
name | Tool/function name to execute. |
arguments | The model’s arguments. Typically a JSON string (OpenAI function-call style) — parse before use. |
run_completed
Terminal frame: the loop finished. The socket closes shortly after.
status is "completed" when the model stopped requesting tools, or
"max_iterations" if the loop hit its iteration cap.
error
Something went wrong during the run.
Close codes
| Code | Meaning |
|---|---|
1008 | Policy violation — run loop disabled, auth failed/timed out, or a malformed auth/start frame. |