Multi-Agent Orchestration
octos can run more than one agent at a time in two distinct shapes. Pick by who owns the work and when you need the result:
| Model | Entry | Ownership | Result | Lifetime |
|---|---|---|---|---|
| Sub-agent | spawn tool | Child of the current turn | Returns in this turn (sync) or as a new inbound message (background) | Dies with the turn |
| Peer | peer_handoff tool | Sovereign session | Returns asynchronously, via files | Survives; closes on disconnect |
Sub-agents are function calls; peers are independent coworkers. The rest of this page focuses on peers — the durable, detached agents. For spawn sub-agent internals, see Architecture → Sub-Agents & Peers.
What a peer is
A peer is a sovereign session with its own durable brief, workspace, and lifecycle, running independently of the turn that created it. Unlike a sub-agent — a child of the current turn that returns its result inline — a peer:
- receives a self-contained brief and cannot see the originating conversation;
- runs its own
session/open+turn/startlifecycle; - survives turn completion — there is no per-turn auto-close; it closes only when its client disconnects;
- writes a durable
result.md(plus versionedresult-N.mdand aturns.txtindex) underpeers/<slug>/on every turn, so its output is reviewable, diffable, and respawnable.
Use a peer when the work should live on its own — a parallel investigation, a long-running task, a second agent you check in on. Use a sub-agent (spawn) when this turn needs the result to keep reasoning.
The peer tools
An agent works with peers through five tools that cover the full lifecycle — create (peer_handoff), steer (peer_send_input), read (peer_gather), list (peer_list), and close (peer_close). They are only available on the gateway/serve runtimes (not in a plain one-shot octos chat).
peer_handoff — create a peer
Promotes work out of the current conversation into a new sovereign peer.
- Arguments:
nameandbrief(required),worktree(optional),token_budget(optional positive integer, only when the user requests a limit), andinputs(optional). - Inputs:
inputslists the files the peer needs to begin — paths as the peer would read them, or{path, kind, required, sha256}. They are checked at handoff (a required file that is not in the peer’s working directory refuses the handoff) and placed in the peer’s first model request: text and data whole, images as attachments, plus a manifest of what was delivered and what was left out and why. A file is delivered whole or not at all, and only if the peer’s own session may read it. Keep naming the paths in the brief as well. - Behavior: stages the peer and returns immediately with a pointer to
peers/<slug>/result.md. Fire-and-forget — you do not get the result back in this turn. A turn may hand off as many peers as it needs; there is no count limit.
peer_send_input — steer a running peer
Injects a follow-up turn into an already-open peer.
- Arguments:
slug(required),message(required, ≤ 64 KB), andinputs(optional). - Inputs:
inputslists the files the task in this message needs — the same declaration aspeer_handoff’s, with paths as the peer would read them. They are checked against the peer’s working directory when the message is sent (a required file that is not there refuses the send, and nothing is queued), travel with the queued message, and are placed in the first model request of the turn that runs it, read at that moment: a repair round gets the page as it is now, while the files an earlier message brought stay in the conversation as they were read then. Only the serve continuation queue carries them; a send to a host-owned app peer or a gateway-served peer that declares inputs is refused, not sent bare. - Behavior: the message is delivered as the peer’s next user turn, rendered verbatim (as if an operator typed it) and persisted as a real user message. Only the peer’s originator may send input (see Rails). Repeated sends carry a unique occurrence id, so distinct messages never collapse but a genuine retry still de-dupes.
peer_gather — collect results
Reads the peer “blackboard” (fan-in).
- Arguments:
slugs(optional array; omit to read every peer). - Behavior: returns each named peer’s brief and latest result as text; peers that have not finished are reported as still running. Read-only. This is the only cross-peer channel — peers do not share context in-band.
peer_list — see what exists
A compact status index of your peers (the companion to peer_gather).
- Arguments: none — it always lists every peer you have staged.
- Behavior: returns one line per peer — slug, status (running / done / closed), last-updated time, turn count, and whether it has its own worktree. Use
peer_listto see what exists and which peers have finished; usepeer_gatherto read a peer’s actual output. Read-only.
peer_close — retire a peer
Gracefully closes a running peer you created.
- Arguments:
slug(required). - Behavior: marks the peer closed (a durable marker) and evicts its live connection, so it receives no further input;
peer_listandpeer_gatherthen report it closed, andpeer_send_inputrefuses it. Only the peer’s originator may close it. This is a graceful retire — the peer finishes any in-flight turn; it does not abort a running turn — and itsresult.mdstays readable viapeer_gather.
Creating and gathering from the client
Humans drive peers through two server methods, surfaced as /peer and /gather in octoscode:
peer/prepare— stage 1–8 peers as a fleet (all-or-nothing). Settoken_budgetto give each staged peer the same cumulative token limit; omit it to leave peer-specific spend unrestricted. The response echoes the limit. The client then opens each session and starts its first turn.peer/gather— the human-facing side of the blackboard; composes the peers’ results into the caller’s session.
For example, peer/prepare accepts {"brief":"Review the API change","cwd":"/workspace/octos","token_budget":250000}. The limit is stored with the peer and survives OUP reconnects, even if the client opens it under a new session id. Completed, failed, and interrupted turns contribute to its usage; once the total reaches the limit, the next turn ends with peer_token_budget_exceeded. Enforcement is at turn boundaries, so one turn can exceed the limit. A goal-bound peer also charges the master’s separate shared goal budget.
Lifecycle
- Stage — reserve
peers/<slug>/(atomic directory claim), optionally add a git worktree, writebrief.md, and stamp anoriginatorfile recording which session owns the peer. Any failure rolls back cleanly. - Notify — a durable
peer/stagedevent asks the client to open the peer session in the background. Because it is durable, a reconnect replays it; the client de-dupes if the session is already open. - Open & track — when the peer’s session opens, its live connection is recorded in a process-global peer wire registry (
{profile}:peer:{slug}→ live session, latest-open-wins, capped at 8192 entries). - Run — the peer runs its own turns, writing
result.mdeach time. It persists across turn completion. - Close — two ways. Explicitly, an agent calls
peer_close(originator-only): it writes a durableclosedmarker and evicts the wire, so the peer receives no further input — a graceful retire in which an in-flight turn still finishes. Implicitly, on WebSocket disconnect the wire mapping is evicted (only if it still points at this session, so a concurrent reopen wins), and deleting the session purges its actor and inbox.
Sending input: the delivery path
peer_send_input must reach a running peer that may be on a different connection or even a different process, so delivery is more than a function call:
- Authorize — the caller must be the peer’s recorded originator; a mismatch is rejected (fail-closed).
- Two paths, by process:
- In the gateway, the message is pushed straight to the peer actor’s inbox (fast path).
- In serve, that inbox lives in a different process, so delivery falls through to a durable continuation queue: the message is enqueued as a peer continuation (keyed by a unique occurrence id) and persisted. If the persist fails, the enqueue is rolled back and the tool returns an error rather than a false “sent.”
- Drain — a per-connection drainer runs about every 2 seconds, backed by a connection-independent global drain every 5 seconds as a safety net when no client is attached. Continuations run only when the peer is idle.
- Freshness gate — the injection dispatches only if the target is still the slug’s current registered wire; otherwise it is re-queued.
- Dispatch — delivered as the peer’s next user turn (verbatim, persisted as a real user message).
- Re-home on reopen — if the peer closed and reopened, stranded injections are moved onto the new wire (crash-safe: the new durable record is written before the old one is retired).
- Retry with a cap — a message that fails to dispatch is re-queued, but advanced behind newer work so it can never starve other messages, and capped at 5 attempts (~10 s) — past the cap it is dropped and logged rather than retried forever.
Delivery guarantees & known limitations
Peer input delivery is best-effort, single-user. In normal operation it behaves at-least-once, with de-dup collapsing retries; under adversarial races it can occasionally lose or (with a durable store) duplicate a message. Three limitations are documented and accepted:
- Close-reopen race — the freshness check is not atomic with dispatch, so a peer that closes and reopens in a narrow window can have one message delivered to the closing session (lost) or, on a crash mid-window, replayed on restart (duplicated).
- Power-loss durability — the durable queue flushes to the OS but does not
fsync, so a hard power cut or kernel panic (not an ordinary process crash) can lose the most recently queued message. This is a store-wide property, not peer-specific. - Failed-tombstone leak — if a disk write fails while re-homing a message on reopen, the old record can linger durably (re-dropped on each restart). It does not cause a duplicate in normal operation — only a small leak.
These are acceptable under the single-user model below; closing them fully would require cross-subsystem atomic locking or per-write fsync, disproportionate for a best-effort local channel.
Rails, authorization & limits
- Depth-1 — peers cannot
peer_handoff,peer_send_input, orpeer_close(those tools are not offered on peer sessions), so a peer cannot recursively spawn, inject, or retire peers. Peers canpeer_gatherandpeer_list(read-only, no recursion hazard). - No count limit on
peer_handoff— a turn may hand off as many peers as it names, each staged or refused on its own. Apeer/preparefleet is bounded to 1–8 peers. - Originator-only injection — only the session that created a peer may send it input; enforced fail-closed against the peer’s
originatorfile. - Size caps — 64 KB for both a brief and an injected message.
- Single-user-per-profile threat model — in serve, the authenticated identity is the profile, so a profile is one user’s trust domain. The LLM cannot inject across sessions (its caller identity is captured server-side and it cannot open sessions); cross-user injection is blocked by profile scoping. The residual case — a user deliberately acting across their own sessions — is treated as the user exercising their own authority, accepted by design. A non-spoofable capability model is deferred until serve gains multi-user identities.