Orchestrator

How an orchestrated session's chat turn reads its graphs, asks for graph actions, and hears what settled.

The orchestrator is the chat turn of a session whose first graph proposal was approved: it reads a bounded status brief of the session's execution graphs and may answer with graph directives. The host checks each directive against what the brief showed and applies it through the control plane, so the user steers several graphs in plain chat while the model gains no authority the user lacks. Agentty implements it in its app layer; ag-protocol defines the brief and directive types.

Connections🔗

flowchart TD
  B[Brief and scope] -->|user message's turn| T[Session turn]
  T -->|pending or refused| D[(Directive records)]
  D -->|as orchestrator| G[Command Gateway]
  D -->|start, expand, extend| S[Store transaction]
  D -->|cancel| Q[User confirms] --> G
  G --> X[Execution graphs]
  S --> X
  X -->|settlements| E[(Events)]
  E -->|next brief| B
  E -->|session quiescent| A[Automatic turn] --> D

Turns🔗

  • A session orchestrates once its session orchestration row exists with is_enabled set, read from the row alone and never from a brief having been built, so a failed read cannot turn an orchestrated session's turn back into a writing one once those turns are read-only. Sessions without a row keep plain chat turns, and the user can switch the orchestrator off.
  • Each turn that answers a chat message the user wrote carries an OrchestratorBrief, which the worker builds when the turn starts: a new or queued message, answers to questions, or a shown message from a device. Prompts the host composes, such as /apply, automatic fixes, hidden durable messages, task messages, review-thread turns, and graph nodes, carry none, and a brief that cannot be read lets the turn run without one.
  • Besides such a message, only unclaimed settlement events start an orchestrator turn, as an automatic turn.
  • While the orchestrator is on, a terminal message reaches it unless n moved the message to a waiting item; the session API keeps answering waiting items first, and no orchestrator mutation is served to remote devices.

Brief and Scope🔗

The brief reads only this session's state, projecting each graph's progress once and saying it is partial when a graph changed meanwhile. It lists the graphs a new graph request may extend, each node's agent, status, parent, environment, error, and waits, the items waiting for a reply, the session document's newest entries, the agent catalog, outcomes of earlier directives, unclaimed events, and pool, worktree, and writer use.

PartBound
Graphs8, of up to 16 nodes each
Waiting items8
Notes3 KiB
Events16, their excerpts sharing 4 KiB
Whole brief12 KiB

Over the whole bound it drops notes, then agent descriptions, then nodes of settled graphs, then the oldest graphs; limits and waiting items stay. Each event's excerpt gets an equal share of 4 KiB, halved for the brief's size but never below a short start. Every string is cleaned, bounded, and escaped; a node error has home-directory paths shortened and credential-like words withheld, and a worktree conflict is worded without internal graph identities. limits.calls_allotted_by_chat counts the calls the chat allotted to graphs it started or extended, not calls graphs spend from budgets the user approved. The turn's OrchestratorScope keeps exactly the handles and identifiers the bounded brief lists, so a directive can name nothing the turn was not shown.

Directives🔗

The worker reads at most 8 directives of a response, at most 2 of them structural and one expansion per graph. It resolves each against the scope into the exact execution, output version, or revision the brief showed and records it pending or refused in the transaction that persists the turn. The reducer then applies the pending ones of that batch only, each under an action identity from its batch and position, after checking its target is still the one the turn saw.

DirectiveApplied throughRule
start_graphA proposal written and approved in one stepUp to 8 nodes, budgeted from the pool
expand_graphThe same, at the revision the brief showedUp to 8 nodes
withdraw_nodeCommand GatewayNode never started
cancel_nodeThe user's confirmation, then the gatewayWaits as awaiting_confirmation for that exact execution
answer_nodeCommand Gateway, as a node continuationA written answer, or the user's message unchanged
accept_outputCommand GatewayOne output waits
resume_graphCommand GatewayGraph paused
extend_budgetA store transaction allotting from the pool1 to 100 calls; a graph with one budget that neither completed nor was canceled
  • A structural directive becomes task-conversation nodes in a proposal whose identity starts with orchestrator:, which every surface of the user's pending proposal skips. It is refused when the session's graphs would hold more than 32 unsettled nodes, a new graph would get less than a call per node from the pool (up to 48), the session is in a state a /graph approval refuses, or the user's own proposal is generating or waiting.
  • Each node of a structural directive reads the user's message as its shared request while nothing was steered into the turn after it, and a neutral host sentence otherwise.
  • A written answer reaches the node framed as the orchestrator's, never the user's; its notice quotes a bounded line and says when it shortened it, while the node's conversation keeps the whole answer.
  • Accepting an output needs the user's own turn, and forwarding needs the user's message verbatim: a turn answering questions, or one a later prompt was steered into, has nothing to forward.
  • An extension refuses a completed graph as the gateway's budget mutation does, and a grant tells paired devices to refetch.
  • Every writer a directive adds works in the session worktree (ORCHESTRATOR_WRITERS_SHARE_SESSION_WORKTREE).

Each outcome is a [Graph] or [Graph Refused] notice in chat, and the next brief reports it. The Command Gateway admits only its allowlist from the orchestrator initiator; the store transactions of structural directives and extensions guard the rest.

Settlement Events🔗

The host reconciles an orchestrated session's events with the stored state of each graph a proposal launched: when its driver starts, after every pass, as nodes settle, and after a withdrawal, which may complete a graph no driver runs. A success, a failure, and a completed graph each get a [Graph] notice in chat; a question or an output awaiting approval keeps its own notice. When the last reconcile in flight for a session ends and any of them recorded events, the session is reported updated once. The next user turn's brief lists the unclaimed events, oldest first, and that turn claims them when it persists. A user turn also shows and claims the events of an automatic turn that ended before it finished. See Session Orchestration for the records and Execution Graphs for the design reasons.

Switching Off🔗

O in the graph view switches a session's orchestrator, and its automatic turns with it, off or on through the Command Gateway's SetOrchestration mutation; in a session that never orchestrated it says there is nothing to switch. A [Graph] notice says which, and the graph view's header shows Orchestrator off while it is off.

  • Switching off refuses every directive of the session still pending or awaiting confirmation with the orchestrator was switched off, and the notice says how many.
  • While it is off, no turn reads a brief, no automatic turn is claimed, and one already queued is released before it runs. No settlement is recorded as an event.
  • A turn that persists while it is off, a user turn or an automatic one, records each directive it sent that would be pending as refused with the same reason, and an automatic one stops counting. Applying a batch whose row reads off applies nothing and says so in the chat.
  • A terminal message then answers the first waiting item, as in a session without an orchestrator, and a message through the session API is an ordinary turn that reads no brief. Running graphs keep running, and /graph still works.
  • Switching on again keeps the events recorded before the switch went off for the next brief, never records what settled while it was off, and records work still running then when it settles.

Automatic Turns🔗

The app starts an automatic orchestrator turn in a session that has an unclaimed event younger than an hour once the whole session is quiescent; older events wait for the user's next brief. It looks at a session:

  • once for every session of every loaded page when the app starts, so events no turn claimed before a quit start a turn if they are that young;
  • whenever the app reports the session updated, which includes when a turn of the session ends, when the user cancels a proposal or a graph or withdraws a node, and when the session's last settlement reconcile in flight ends having recorded events or after a look found it reconciling;
  • when the user raises the pool in the graph view, so the turn a stop notice promises starts;
  • 10 seconds after a look whose read failed.

Quiescent means all of these hold:

  • the session is in review or watching;
  • its worker neither runs nor holds work, no message is queued, and no chat turn's operation is queued or running, so a message the user just sent keeps the session busy before its turn shows in the status;
  • no reconcile is in flight;
  • no proposal of the user's generates or waits for approval;
  • no cancel waits for a confirmation;
  • no node is queued, running, or settling, asks a question, or has an output waiting for acceptance;
  • no pending node waits only for a resource the host frees itself (the workspace, worker or writer capacity, a parent's worktree, a worktree conflict, or disk space), or for a resume.

A failed node or graph counts as quiescent, and so does a pending node with a reason the brief reports and only a directive or the user lifts, whatever else it waits for: a spent budget, the worktree limit, an unmet dependency, or a withdrawal. The host then queues the turn under a new batch, counts it, allots its 3 calls from the pool, and claims the 16 newest unclaimed events for it, as many as a brief lists, oldest first, so the event that started it is among them; older ones stay for the next turn or the user's brief.

  • Brief: it lists exactly the claimed events and offers only start_graph, expand_graph, resume_graph, and extend_budget, and its rules say the host started the turn and that it can only direct graphs. The prompt is host text that names nothing a model or node wrote.
  • Run: read-only and offline, as the backends page states for each backend, with its branch effects withheld and a budget of 3 provider attempts. A message the user sends meanwhile waits behind it instead of being steered into it. The nodes of the graphs it starts or extends run with their own permissions, network included.
  • Finish: its directives carry its batch, and it gives back the held events its record does not list. A turn that applied none, because it sent none or the host refused them all, no longer counts; its calls stay allotted, since the pool never takes calls back.
  • Release: a turn that fails, is stopped, or is skipped, and one a restart left queued, is released: a notice says so, its events never start another automatic turn, and the next user turn's brief shows them. A failed turn stays counted, so failing turns stop at the cap; a stopped, skipped, or restarted one gives its count back. A turn is never queued for a session in Question, and one that finds its session there, or cannot build its brief, is released before it runs.
  • Row: a [Automatic Turn] notice names each turn's place in the row and the settlements that started it. Three counted turns in a row, or a pool with fewer than 3 calls left, stop automatic turns with one notice until a message the user writes to the chat, queued or not, or their answers to its questions, start a new row; a reply to a node's waiting item does not.