Skip to content

Sidecar protocol

atomic-agent serve is how a network client drives the agent. The sidecar is how another program embeds it: you spawn atomic-agent-sidecar as a child process and talk to it over its own stdin and stdout, with no port, no bearer token, and no HTTP stack in between.

The agent runs as a child of your app, dies with it, and streams its whole event feed (steps, tool calls, reasoning deltas, approval requests, logs, metrics) back up the pipe as it happens. The Atomic Agent desktop app does not use the sidecar: it runs atomic-agent serve on a local port with a per-launch key.

Terminal window
atomic-agent-sidecar

It takes no flags. Configuration comes from the usual config.json and ATOMIC_AGENT_* environment variables, resolved at boot exactly as they are for the CLI.

The envelope

Every frame in both directions is one JSON object on one line, terminated by \n. No length prefixes, no framing beyond the newline. A line that fails to parse does not kill the process: it comes back as an error event.

There are exactly three kinds of frame, distinguished by kind:

kindDirectionMeaning
requesthost → sidecarAsk the agent to do something. Carries id, type, payload.
eventsidecar → hostUnsolicited notification. Carries id, type, payload, optional correlationId.
responsesidecar → hostExactly one per request. Carries id, correlationId, ok, payload, optional error.

correlationId on a response is the request’s id: that is how you match a reply to what you asked. Every frame also carries its own fresh id (a UUID).

{"kind":"request","id":"a1b2","type":"send_message","payload":{"sessionId":"s-9f3","text":"List the TypeScript files here"}}

Events and responses interleave freely on stdout. A single send_message typically emits dozens of events before its one response lands, so a host must read the stream continuously rather than blocking on the reply.

Requests

typePayloadResponse payload
pingnone{ ok, llamaUrl, stateDir, version }
start_session{ workingDir, metadata? }{ sessionId }
send_message{ sessionId, text, maxSteps? }{ reason, turnCount, stepCount }
steer_message{ sessionId, text }{ steered }
cancel{ sessionId }{ cancelled }
approval_response{ approvalId, approved, reason?, grant?, grantHost?, answer? }{ resolved }
get_session{ sessionId }The SessionState object, or null
compact_session{ sessionId, instructions? }The compaction result
get_compaction{ sessionId }The session’s compaction state
skill_install{ sourcePath, force?, confirm?, acknowledgeRisk? }{ name, installedAt }
skill_uninstall{ name }{ removed }
skill_listnone{ skills: [{ name, version, description, source }] }
shutdownnone{ ok: true }

A few behaviours that are not obvious from the table:

  • One session at a time. The sidecar process hosts exactly one active session. A second start_session disposes the first (aborting its turn and shutting down its runtime) before building the new one. If your app needs concurrent sessions, spawn a sidecar per session or use serve instead.
  • send_message serialises per session. Two rapid messages on the same session queue through the turn controller FIFO rather than racing.
  • maxSteps is a hard ceiling. Without it, a turn works in legs of agent.maxSteps (25) and continues up to agent.task.maxSteps (1000), as in run or tui. Pass maxSteps only to stop a task earlier (or to raise the ceiling).
  • steer_message reaches the running turn. It folds text into the turn that is already running on the active session and returns { steered: true }, or { steered: false } when nothing is running (or the id is not the active session). On false, send it with send_message instead. It bypasses the per-session queue on purpose, so it does not wait behind the turn it is meant to reach.
  • cancel and get_session are scoped to the active session. cancel on any other id returns { cancelled: false } rather than an error (unless it stopped a compaction of that session). get_session falls back to reading SQLite for a non-active id, but only while a runtime exists; otherwise it returns null.
  • Skills and compaction need a session. skill_install, skill_uninstall, compact_session and get_compaction throw when no session is active; skill_list returns an empty list instead.
  • skill_install is scanned. The folder is security-scanned first. A caution verdict fails the request with a message that ends in [scanId <id>]; resend with confirm set to that id. A dangerous verdict needs acknowledgeRisk set to the id.
  • approval_response can remember the answer. With approved: true, grant is session (the whole category in this chat), shape (this command’s program in this chat) or always (save an allow rule for the project). Send only a grant the request’s canSession, canShape or canAlways allows; anything else fails and the approval stays pending. answer carries the picked options or your own words for a user_question request.

Events

Everything the agent does surfaces as an event. Hosts typically render the first group, log the middle group, and gate on approval_request.

typePayload
session_started{ sessionId, workingDir }
turn_started{ sessionId, turnIndex }
turn_finished{ sessionId, turnIndex, reason, stepCount, durationMs }
step_started{ sessionId, stepIndex }
step_finished{ sessionId, stepIndex, tokensUsed, durationMs }. tokensUsed is always 0 today.
session_completed{ sessionId, reason }
session_failed{ sessionId, error, category }

turn_finished.reason is one of reply, finish, max_steps, cancelled, failed.

The SidecarEventType union also declares llm_request, llm_response, pong and trace. Nothing emits them today; ping answers with a normal response, not a pong event.

Errors

A failed request still produces exactly one response, with ok: false and a populated error:

{"kind":"response","id":"r91a","correlationId":"a1b2","ok":false,"payload":{},"error":{"message":"no active session with id s-000","code":"handler_failed"}}
codeWhen
unknown_requestNo handler registered for that type (including run_step).
handler_failedThe handler threw. The message is the thrown Error.message.
step_error:<category>A step inside a turn failed (for example a model or tool error). Emitted as an error event (with the stack in stack), not a response; the turn’s own outcome still arrives in the send_message response.
parse_errorA stdin line was not valid JSON. Emitted as an event, not a response, because an unparseable line has no id to correlate against.

A handler_failed response is always accompanied by an error event carrying the same message plus a stack trace. For parse_error, the offending raw line is placed in the event’s stack field.

No handler failure kills the sidecar. Every route is wrapped, so a bad request degrades to one error frame and the process keeps serving.

ping returns the agent’s real version in version. Use it for diagnostics, and pin the release you built your host against.

A minimal session

The typical host lifecycle, start to finish:

  1. Spawn atomic-agent-sidecar; attach line-buffered readers to stdout.
  2. Send ping to confirm the process is alive and see which model server URL it resolved.
  3. Send start_session with the workingDir the tools should resolve against. Keep the returned sessionId.
  4. Send send_message. Render assistant_delta as it streams, answer any approval_request with approval_response, and wait for the response frame.
  5. Send cancel if the user interrupts.
  6. Send shutdown before exiting, so the runtime closes its databases cleanly.
host → {"kind":"request","id":"1","type":"ping","payload":{}}
← {"kind":"response","id":"…","correlationId":"1","ok":true,"payload":{"ok":true,…}}
host → {"kind":"request","id":"2","type":"start_session","payload":{"workingDir":"/Users/you/project"}}
← {"kind":"event","id":"…","type":"session_started","payload":{"sessionId":"s-9f3",…}}
← {"kind":"response","id":"…","correlationId":"2","ok":true,"payload":{"sessionId":"s-9f3"}}
host → {"kind":"request","id":"3","type":"send_message","payload":{"sessionId":"s-9f3","text":"…"}}
← {"kind":"event",…,"type":"turn_started",…}
← {"kind":"event",…,"type":"assistant_delta",…} ← many
← {"kind":"event",…,"type":"assistant_reply",…}
← {"kind":"response","id":"…","correlationId":"3","ok":true,"payload":{"reason":"reply",…}}

Get updates by email

One email when a new version comes out.