Graph Chat API

Reference for how a session's chat reaches its execution graphs: graph directives, the orchestrator brief, settlement events, and /graph requests.

This page is the field-level reference for what crosses between a session's chat and its execution graphs. The Orchestrator and Graph Proposals and Replies pages explain the flow; Graph Node API covers nodes, and Graph Service API the functions and remote messages.

Round Trip🔗

sequenceDiagram
  participant U as User
  participant C as Chat turn
  participant H as Host
  participant N as Node turn
  U->>H: chat message
  H->>C: prompt with orchestrator-status brief
  C->>H: response with graph_directives
  H->>U: [Graph Refused] notice for refused entries
  H->>H: apply pending directives
  H->>U: [Graph] or [Graph Refused] notice per directive
  H->>N: dispatch a started or resumed node
  N->>H: response, settled
  H->>U: [Graph] notice
  U->>H: next chat message
  H->>C: brief with the event and outcomes

A cancel_node directive adds a confirmation in the terminal before the apply step; only start_graph, expand_graph, answer_node, and resume_graph lead to a dispatch. An automatic turn takes the place of the chat message when the host starts one on unclaimed events.

Graph Directives🔗

A session turn's AgentResponse carries graph_directives. The host reads them only from the live result of a turn whose request carried a brief and drops them from every other turn. null reads as none, and a value that is not an array as one invalid entry.

FieldTypeRequired
callsinteger or nullyes
graphstring or nullyes
kindGraphDirectiveKindyes
labelstring or nullyes
nodestring or nullyes
nodesarray of GraphDirectiveNodeyes
textstring or nullyes

Where each key applies and what bounds it:

FieldUsed byBounds and meaning
kindallOne of the eight kinds below
graphall but start_graphA handle the brief lists, such as graph-2; null for start_graph
nodewithdraw_node, cancel_node, answer_node, accept_outputAn id the brief lists for that graph
labelstart_graphNeeds a letter or digit; cleaned to 48 characters
nodesstart_graph, expand_graph1 to 8 directive nodes; more makes the entry invalid; [] otherwise
textanswer_node1 to 2048 bytes once cleaned; null forwards the user's message
callsextend_budget1 to 100

A key a kind does not use is null, or [] for nodes. Each directive node:

FieldTypeRequired
agent_idstringyes
depends_onarray of stringyes
idstringyes
parent_idstring or nullyes
shares_session_worktreebooleanyes
taskstringyes
writesbooleanyes

The bounds of each node key:

FieldBounds and meaning
id1 to 32 lowercase letters, digits, and hyphens, starting with a letter or digit; unique in the graph
agent_idAn id from the brief's agents
task1 to 4096 bytes; becomes the node's objective
depends_onNo duplicates; nodes of this directive or, for expand_graph, listed nodes with exactly one output; each is read as an input named after it
parent_idA top-level node of this directive or a listed one, not itself; blank reads as null
writestrue makes an ExclusiveWrite node with SessionWorkflow post-processing, false a SharedRead reader
shares_session_worktreeRead but overridden: every writer works in the session worktree (ORCHESTRATOR_WRITERS_SHARE_SESSION_WORKTREE)

Every directive node is a task conversation answering with a session turn and produces one output, result. The fixture of crates/ag-protocol/tests/orchestrator.rs:

{
  "calls": null, "graph": null, "kind": "start_graph", "label": "research", "node": null,
  "nodes": [{
    "agent_id": "researcher", "depends_on": [], "id": "map", "parent_id": null,
    "shares_session_worktree": false, "task": "Map the parser.", "writes": false
  }],
  "text": null
}

Kinds🔗

KindFieldsApplied throughAsks the user
start_graphlabel, nodesAn orchestrator: proposal approved in one step; budget of the pool's calls left, at most 48, allotted from the poolNo
expand_graphgraph, nodesThe same kind of proposal, appended at the shown revision; spends the graph's own budget and takes nothing from the poolNo
withdraw_nodegraph, nodeCommand Gateway, WithdrawExecutionGraphNodeNo
cancel_nodegraph, nodeCommand Gateway, CancelExecutionGraphNode, after the user confirmsYes
answer_nodegraph, node, textCommand Gateway, ContinueExecutionGraphNode: OrchestratorReply for a written text, Reply when text is nullNo
accept_outputgraph, nodeCommand Gateway, AcceptExecutionGraphResultNo
resume_graphgraphCommand Gateway, ResumeExecutionGraphNo
extend_budgetgraph, callsA store transaction allotting from the session's poolNo

The worker reads at most 8 directives of a response, at most 2 of them start_graph or expand_graph, and one expand_graph per graph. When the host applies a batch, node and graph directives go first, in order, and structural ones last.

Refusals🔗

A directive is checked when its turn is saved and again when the host applies it.

KindWhenReason, as the chat reads it
anySaved"it names a graph the status did not list"; "it names a node the status did not list"
anySaved"a malformed directive"; "a directive with more than 8 nodes"; "N more past the limit of 8 per response"
anySaved"the host does not apply this kind of directive yet", for a kind the turn's rules do not offer, such as cancel_node in an automatic turn
anySaved"the orchestrator was switched off", for each directive that would be pending, in a turn that persists while it is off
anyApplied"the application restarted before it applied this directive"
anyApplied"the orchestrator was switched off", for every directive still pending or awaiting confirmation when the user switches it off
start_graph, expand_graphSaved"at most 2 start_graph or expand_graph directives fit in one response"; "it names an agent the status did not list"; "the message is longer than a graph's request may be"; a node refusal below
start_graph, expand_graphApplied"the session's graphs have N nodes still to run or settle, and at most 32 may, so N more fit"; "the session cannot run graphs while it is …"; "a proposal of the user's awaits their approval"
start_graphSaved"a new graph names no existing graph"
start_graphApplied"the session's pool has N calls left, and a new graph needs at least one per node; raise it from the graph view"
expand_graphSaved"one expand_graph per graph fits in one response"; "the graph completed or was canceled"
expand_graphApplied"the graph can no longer take more work"; "the graph changed since the chat saw it"
withdraw_nodeSaved"the node started, so it can only be canceled"
withdraw_nodeAppliedThe store's reason when a child or dependent of the node started
cancel_nodeSaved"the node is neither queued nor running"
cancel_nodeApplied"the user is already asked to confirm this cancel"; "the node is no longer running"; after the confirmation, the gateway's error; a cancel whose execution ended first closes as refused
answer_nodeSaved"the node does not wait for an answer"; "its answer is empty or longer than 2048 bytes"; "only a message the user wrote in this turn, unchanged, can be forwarded; write the answer in text instead"
answer_nodeApplied"the node no longer waits for this answer"
accept_outputSaved"no output of the node waits for acceptance"; "several outputs of the node wait; accept them from the graph view"; "only a turn answering your own message may do this"
accept_outputApplied"the output no longer waits for acceptance"
resume_graphSaved"the graph is not paused"
resume_graphApplied"the graph is no longer paused at the revision the chat saw"
extend_budgetSaved"it asks for a number of calls outside 1 to 100"; "the graph completed or was canceled"; "the graph has no single budget to extend"
extend_budgetApplied"the session's pool has N calls left; raise it from the graph view"

The node refusals of start_graph and expand_graph are: "it adds no nodes"; "every node needs a task of 1 to 4096 bytes"; "node ids are 1 to 32 lowercase letters, digits, and hyphens, starting with a letter or digit"; "node ids must be unique within the graph, including the nodes it already has"; "a node lists the same dependency twice"; "depends_on may name only nodes of the same directive or, for expand_graph, nodes the status listed for that graph"; "parent_id may name only a top-level node of the same directive or, for expand_graph, one the status listed for that graph"; "a dependency names a listed node that has no single result to read"; "a new graph needs a label with a letter or digit"; and "it names an agent the status did not list".

When a turn is saved, the chat gets one [Graph Refused] notice: "The host refused N of this turn's M graph directive(s):", then one line - <count> × <reason> per reason, each reason prefixed with its kind in code. Each applied directive gets a [Graph] notice with its detail, or a [Graph Refused] notice of the form `<kind>` on <target>: <detail>. The next brief's outcomes shows the newest 8 outcomes not yet reported; older ones count as reported without being shown. A batch whose session's orchestrator reads off when the host applies it gets one [Graph Refused] notice instead: "The orchestrator is off, so the graph directives of the turn that just finished were not applied."

Orchestrator Brief🔗

The brief is one JSON object in an orchestrator-status block of the chat turn's prompt, preceded by the rules of the directive kinds the host applies on that turn. OrchestratorBrief::directive_kinds and is_host_started choose those rules and stay out of the object. Every string in the object is untrusted for the turn that reads it; the host strips hidden characters from each and escapes it. The "Written by" column says where each string comes from.

FieldTypePresentBounds and meaningWritten by
agentsarray of {description, id}AlwaysAt most 16; id 64 characters, description 200Agent definitions, which a repository can supply
graphsarray of graphsAlwaysThe graphs a new graph request may extend, at most 8, oldest dropped firstSee below
limitsobjectAlwayscalls_allotted_by_chat, worktrees, and writers as {limit, used}; writers_waitingHost
notesarray of {author, text}AlwaysNewest session document entries with text, 3 KiB of text in allauthor host, text its author
outcomesarray of outcomesAlwaysAt most 8Host
waitingarray of waiting itemsAlwaysAt most 8See below
eventsarray of eventsWhen not emptyAt most 16See below
omitted_eventsintegerWhen above zeroEvents left outHost
omitted_graphsintegerAlwaysGraphs left outHost
omitted_waitingintegerAlwaysWaiting items left outHost
is_partialbooleanWhen trueA graph changed while the host read itHost
ObjectFieldsValues and writers
Graphcalls_left, handle, name, nodes, omitted_nodes, revision, statushandle is graph-N; name is the graph's label, written by the model or user, or graph N; status is running, blocked, paused, completed, failed, or cancelled; at most 16 nodes, and a settled graph lists only each node's id, status, and pull_request
Nodeid, status; when known agent, environment, parent, error, pull_request, waitingstatus is pending, queued, running, awaiting_answers, succeeded, failed, uncommitted (its turn finished but its commit did not), cancelled, or withdrawn; environment is session worktree or own worktree; error is the node's, 200 characters, with credential-like words withheld and home paths shortened to ~; pull_request is where the node's branch's pull request stood when the host last read it, in the host's words such as PR #12 draft, 120 characters, with the same redaction as error, and never the forge's title or a remote's own lines; waiting is host wording, 300 characters
Outcomedetail, graph, kind, node, statestate is applied, awaiting_confirmation, declined, or refused; graph, kind, and node are null when unknown, kind for an invalid entry
Waiting itemgraph, kind, node, textkind is confirmation, output, proposal, or question; graph and node are null for a proposal; text, 500 characters, is the node's questions for question and a host sentence otherwise
Eventexcerpt, graph, kind, nodekind is node_succeeded, node_failed, node_asked, or graph_settled; graph is a handle; node is null for graph_settled; excerpt is the node's answer, error, or questions, at most 1024 bytes and an equal share of 4 KiB, empty for a completed graph

The whole object is held to 12 KiB by halving event excerpts, never below a short start, then dropping notes, agent descriptions, settled graphs' nodes with their pull requests, and the oldest graphs, then shortening waiting texts; limits, waiting items, events, and outcomes stay. 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 example below is assembled from the values of crates/agentty/src/app/orchestrator_brief_test.rs:

{
  "agents": [{"description": "Plans work.", "id": "planner"}],
  "events": [{"excerpt": "Build failed", "graph": "graph-1", "kind": "node_failed", "node": "first"}],
  "graphs": [{
    "calls_left": 12, "handle": "graph-1", "name": "research",
    "nodes": [{
      "agent": "planner", "environment": "session worktree", "error": "Build failed",
      "id": "first", "status": "failed"
    }, {
      "agent": "planner", "environment": "own worktree", "id": "second", "parent": "first",
      "status": "pending",
      "waiting": "Waiting for a worktree (10 of 10 in use); Waiting for build capacity (2 of 2 writers running)"
    }],
    "omitted_nodes": 0, "revision": 1, "status": "blocked"
  }],
  "limits": {
    "calls_allotted_by_chat": {"limit": 200, "used": 48},
    "worktrees": {"limit": 10, "used": 10},
    "writers": {"limit": 2, "used": 2},
    "writers_waiting": 2
  },
  "notes": [{"author": "node first of graph-1", "text": "The cache lives in src/cache.rs."}],
  "omitted_graphs": 1, "omitted_waiting": 0,
  "outcomes": [{"detail": "Resumed `graph-1`.", "graph": "graph-1", "kind": "resume_graph", "node": null, "state": "applied"}],
  "waiting": [{"graph": null, "kind": "proposal", "node": null, "text": "Graph proposal v1 waits for the user's approval."}]
}

Settlement Notices🔗

Events are recorded only for graphs a proposal launched; a canceled or withdrawn node records none. The notice names the graph by its display name, the event by its handle.

SettlementChat notice
A node succeeded[Graph] `<node>` of `<graph>` succeeded., unless its output waits for approval
A node failed[Graph] `<node>` of `<graph>` failed: <error>, the error cut to 200 characters
A node askedThe node's own question notice
An output awaits approvalThe output approval notice
A graph completed[Graph] `<graph>` completed.

A node that writes also commits when its turn ends. The commit's steps and attempts stay on the node (see Node Commits), and the chat gets one persisted line, on failure: [Commit Error] Node `<node>` could not be committed: <summary>. The summary is the `pre-commit` hook failed: <first line of its output>, or the first line of any other failure, cleaned and shortened like any other excerpt. The node fails with the same words, so its [Graph] failure notice and settled event repeat them. A commit that succeeds or finds no changes shows only a transient [Commit] notice in the output panel, and the transcript keeps neither.

/graph Requests and Other Routes In🔗

RouteHow it reaches graphs
/graph requestA generation run answers with a GraphProposalResponse; only approving its exact version launches a graph
Reply to a pending proposalAnswers to a clarification go to that version; any other reply is decided as Approve, Revise, or Cancel
Answer to a node's questionsContinueExecutionGraphNode with GraphNodeContinuation::Reply, the answers as one message
Reply to an outputDecided as accept, or revise as GraphNodeContinuation::Reply
Terminal message, orchestratedReaches the orchestrator unless n moved it to a waiting item
Session API or remote messageAnswers a waiting item first and never reaches the orchestrator while one waits

A GraphProposalResponse is {"outcome": …}, where outcome is an object whose kind is one of the following (crates/ag-protocol/schema/graph_proposal.all_properties.json is the schema):

ValueFieldsDescription
clarificationquestionsAsk only for information required to propose a complete graph.
proposalproposalSupply the complete graph for host validation and inspection.

A clarification asks 1 to 5 questions:

FieldTypeRequiredDescription
optionsarray of stringyes1-3 likely answers the user can pick, recommended first; no deferral or non-answer choices.
textstringyesOne specific, actionable question in Markdown, about a single decision.

A proposal holds at most 16 nodes and 32 edges, and the response at most 65,536 bytes:

FieldTypeRequiredDescription
nodesarray of GraphProposalNodeyesNonempty nodes whose references are local to this proposal.
targetGraphProposalTargetyes

Its target:

FieldTypeRequiredDescription
graph_idstring or nullyesThe supplied graph's graph_id, exactly as given, for an expansion; null for a new graph.
kindGraphProposalTargetKindyes
labelstring or nullyesShort purpose label shown beside a new graph, such as research; null for an expansion.
revisioninteger or nullyesThe supplied graph's revision, exactly as given, for an expansion; null for a new graph.

Its kind is one of:

ValueDescription
new_graphStart a new graph for a separate deliverable or a new round of work.
expansionAppend the nodes to one supplied existing graph, for more work toward the same deliverable.

Each node:

FieldTypeRequiredDescription
agent_idstringyesExact identifier from the host-supplied available agent catalog.
dependenciesarray of GraphProposalDependencyyesAll prerequisites required before this node may run.
environmentGraphProposalEnvironment or nullyesWorkspace of a top-level node: null or "shared" for the session's shared workspace, or "standalone" for a separate worktree whose work stays on its own branch, only for work the request asks to keep on separate branches or in separate pull requests. A child always works in its parent's workspace.
executionGraphProposalExecutionyes
idstringyesLogical identifier unique within this proposal, not a runtime ID.
inputsarray of GraphProposalInputyesNamed handoffs from declared outputs on prerequisite nodes.
objectivestringyesDesired outcome, separate from the referenced agent's instructions.
outputsarray of GraphProposalOutputyesNamed outputs containing the complete response under its schema.
parent_idstring or nullyesID of the top-level node, in this proposal or the extended graph, that this node is a child of: a step of the same deliverable that shares its parent's workspace. Null for a top-level node. Children cannot have children. A parent adds no ordering: a child that runs after its parent depends on it, a parent does not wait for its children, and depending on a parent does not wait for them, so a node that needs a child's work depends on that child.

A node's dependencies, each a gate and the node_id that produces it:

FieldTypeRequiredDescription
gateGraphProposalGateyes
node_idstringyesProducing node's logical identifier in this proposal.

The gate is an object whose kind is one of:

ValueFieldsDescription
execution_succeededSuccessful execution including ordered host effects and no questions.
result_validatedoutput_nameSuccessful, question-free execution with a validated named output.
result_acceptedoutput_nameExplicit host-recorded acceptance of an exact validated output version.

Its execution holds its requirements:

FieldTypeRequired
contextGraphProposalContextyes
post_processingGraphProposalPostProcessingyes
response_profileProtocolRequestProfileyes
workspace_accessGraphProposalWorkspaceAccessyes

The values of its context:

ValueDescription
freshIsolated utility with a fresh context for each execution.
task_conversationIsolated, resumable task context allocated by the host.

Of its post_processing:

ValueDescription
noneNo mutating host effects.
session_workflowOrdered session effects, if authorized by the host.

The values of its workspace_access; resolution refuses background_read:

ValueDescription
shared_readShare read-only access with other graph readers.
background_readFresh read-only utility that tolerates concurrent ordinary host work.
exclusive_writeSerialize against all other Env work; writes still require permission.

Of its response_profile, which a node's output schema also names:

ValueDescription
FocusedReviewIsolated focused review with a direct structured review response.
GraphProposalInitial graph proposal or clarification, before host resolution.
ReviewMetadataDirect review-request title and description reconciliation.
SessionTurnInteractive session turn.
UtilityPromptIsolated utility prompt.

A node's inputs and outputs:

FieldTypeRequiredDescription
namestringyesSlot name unique on the consumer.
output_namestringyesDeclared output name on the producer.
producer_node_idstringyesLogical producer node, protected by a matching result dependency gate.
FieldTypeRequiredDescription
namestringyesOutput name unique on the producer.
schemaProtocolRequestProfileyes