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 outcomesA 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.
| Field | Type | Required |
|---|---|---|
calls | integer or null | yes |
graph | string or null | yes |
kind | GraphDirectiveKind | yes |
label | string or null | yes |
node | string or null | yes |
nodes | array of GraphDirectiveNode | yes |
text | string or null | yes |
Where each key applies and what bounds it:
| Field | Used by | Bounds and meaning |
|---|---|---|
kind | all | One of the eight kinds below |
graph | all but start_graph | A handle the brief lists, such as graph-2; null for start_graph |
node | withdraw_node, cancel_node, answer_node, accept_output | An id the brief lists for that graph |
label | start_graph | Needs a letter or digit; cleaned to 48 characters |
nodes | start_graph, expand_graph | 1 to 8 directive nodes; more makes the entry invalid; [] otherwise |
text | answer_node | 1 to 2048 bytes once cleaned; null forwards the user's message |
calls | extend_budget | 1 to 100 |
A key a kind does not use is null, or [] for nodes. Each directive node:
| Field | Type | Required |
|---|---|---|
agent_id | string | yes |
depends_on | array of string | yes |
id | string | yes |
parent_id | string or null | yes |
shares_session_worktree | boolean | yes |
task | string | yes |
writes | boolean | yes |
The bounds of each node key:
| Field | Bounds and meaning |
|---|---|
id | 1 to 32 lowercase letters, digits, and hyphens, starting with a letter or digit; unique in the graph |
agent_id | An id from the brief's agents |
task | 1 to 4096 bytes; becomes the node's objective |
depends_on | No 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_id | A top-level node of this directive or a listed one, not itself; blank reads as null |
writes | true makes an ExclusiveWrite node with SessionWorkflow post-processing, false a SharedRead reader |
shares_session_worktree | Read 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🔗
| Kind | Fields | Applied through | Asks the user |
|---|---|---|---|
start_graph | label, nodes | An orchestrator: proposal approved in one step; budget of the pool's calls left, at most 48, allotted from the pool | No |
expand_graph | graph, nodes | The same kind of proposal, appended at the shown revision; spends the graph's own budget and takes nothing from the pool | No |
withdraw_node | graph, node | Command Gateway, WithdrawExecutionGraphNode | No |
cancel_node | graph, node | Command Gateway, CancelExecutionGraphNode, after the user confirms | Yes |
answer_node | graph, node, text | Command Gateway, ContinueExecutionGraphNode: OrchestratorReply for a written text, Reply when text is null | No |
accept_output | graph, node | Command Gateway, AcceptExecutionGraphResult | No |
resume_graph | graph | Command Gateway, ResumeExecutionGraph | No |
extend_budget | graph, calls | A store transaction allotting from the session's pool | No |
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.
| Kind | When | Reason, as the chat reads it |
|---|---|---|
| any | Saved | "it names a graph the status did not list"; "it names a node the status did not list" |
| any | Saved | "a malformed directive"; "a directive with more than 8 nodes"; "N more past the limit of 8 per response" |
| any | Saved | "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 |
| any | Saved | "the orchestrator was switched off", for each directive that would be pending, in a turn that persists while it is off |
| any | Applied | "the application restarted before it applied this directive" |
| any | Applied | "the orchestrator was switched off", for every directive still pending or awaiting confirmation when the user switches it off |
start_graph, expand_graph | Saved | "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_graph | Applied | "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_graph | Saved | "a new graph names no existing graph" |
start_graph | Applied | "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_graph | Saved | "one expand_graph per graph fits in one response"; "the graph completed or was canceled" |
expand_graph | Applied | "the graph can no longer take more work"; "the graph changed since the chat saw it" |
withdraw_node | Saved | "the node started, so it can only be canceled" |
withdraw_node | Applied | The store's reason when a child or dependent of the node started |
cancel_node | Saved | "the node is neither queued nor running" |
cancel_node | Applied | "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_node | Saved | "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_node | Applied | "the node no longer waits for this answer" |
accept_output | Saved | "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_output | Applied | "the output no longer waits for acceptance" |
resume_graph | Saved | "the graph is not paused" |
resume_graph | Applied | "the graph is no longer paused at the revision the chat saw" |
extend_budget | Saved | "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_budget | Applied | "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.
| Field | Type | Present | Bounds and meaning | Written by |
|---|---|---|---|---|
agents | array of {description, id} | Always | At most 16; id 64 characters, description 200 | Agent definitions, which a repository can supply |
graphs | array of graphs | Always | The graphs a new graph request may extend, at most 8, oldest dropped first | See below |
limits | object | Always | calls_allotted_by_chat, worktrees, and writers as {limit, used}; writers_waiting | Host |
notes | array of {author, text} | Always | Newest session document entries with text, 3 KiB of text in all | author host, text its author |
outcomes | array of outcomes | Always | At most 8 | Host |
waiting | array of waiting items | Always | At most 8 | See below |
events | array of events | When not empty | At most 16 | See below |
omitted_events | integer | When above zero | Events left out | Host |
omitted_graphs | integer | Always | Graphs left out | Host |
omitted_waiting | integer | Always | Waiting items left out | Host |
is_partial | boolean | When true | A graph changed while the host read it | Host |
| Object | Fields | Values and writers |
|---|---|---|
| Graph | calls_left, handle, name, nodes, omitted_nodes, revision, status | handle 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 |
| Node | id, status; when known agent, environment, parent, error, pull_request, waiting | status 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 |
| Outcome | detail, graph, kind, node, state | state is applied, awaiting_confirmation, declined, or refused; graph, kind, and node are null when unknown, kind for an invalid entry |
| Waiting item | graph, kind, node, text | kind 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 |
| Event | excerpt, graph, kind, node | kind 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.
| Settlement | Chat 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 asked | The node's own question notice |
| An output awaits approval | The 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🔗
| Route | How it reaches graphs |
|---|---|
/graph request | A generation run answers with a GraphProposalResponse; only approving its exact version launches a graph |
| Reply to a pending proposal | Answers to a clarification go to that version; any other reply is decided as Approve, Revise, or Cancel |
| Answer to a node's questions | ContinueExecutionGraphNode with GraphNodeContinuation::Reply, the answers as one message |
| Reply to an output | Decided as accept, or revise as GraphNodeContinuation::Reply |
| Terminal message, orchestrated | Reaches the orchestrator unless n moved it to a waiting item |
| Session API or remote message | Answers 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):
| Value | Fields | Description |
|---|---|---|
clarification | questions | Ask only for information required to propose a complete graph. |
proposal | proposal | Supply the complete graph for host validation and inspection. |
A clarification asks 1 to 5 questions:
| Field | Type | Required | Description |
|---|---|---|---|
options | array of string | yes | 1-3 likely answers the user can pick, recommended first; no deferral or non-answer choices. |
text | string | yes | One 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:
| Field | Type | Required | Description |
|---|---|---|---|
nodes | array of GraphProposalNode | yes | Nonempty nodes whose references are local to this proposal. |
target | GraphProposalTarget | yes |
Its target:
| Field | Type | Required | Description |
|---|---|---|---|
graph_id | string or null | yes | The supplied graph's graph_id, exactly as given, for an expansion; null for a new graph. |
kind | GraphProposalTargetKind | yes | |
label | string or null | yes | Short purpose label shown beside a new graph, such as research; null for an expansion. |
revision | integer or null | yes | The supplied graph's revision, exactly as given, for an expansion; null for a new graph. |
Its kind is one of:
| Value | Description |
|---|---|
new_graph | Start a new graph for a separate deliverable or a new round of work. |
expansion | Append the nodes to one supplied existing graph, for more work toward the same deliverable. |
Each node:
| Field | Type | Required | Description |
|---|---|---|---|
agent_id | string | yes | Exact identifier from the host-supplied available agent catalog. |
dependencies | array of GraphProposalDependency | yes | All prerequisites required before this node may run. |
environment | GraphProposalEnvironment or null | yes | Workspace 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. |
execution | GraphProposalExecution | yes | |
id | string | yes | Logical identifier unique within this proposal, not a runtime ID. |
inputs | array of GraphProposalInput | yes | Named handoffs from declared outputs on prerequisite nodes. |
objective | string | yes | Desired outcome, separate from the referenced agent's instructions. |
outputs | array of GraphProposalOutput | yes | Named outputs containing the complete response under its schema. |
parent_id | string or null | yes | ID 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:
| Field | Type | Required | Description |
|---|---|---|---|
gate | GraphProposalGate | yes | |
node_id | string | yes | Producing node's logical identifier in this proposal. |
The gate is an object whose kind is one of:
| Value | Fields | Description |
|---|---|---|
execution_succeeded | Successful execution including ordered host effects and no questions. | |
result_validated | output_name | Successful, question-free execution with a validated named output. |
result_accepted | output_name | Explicit host-recorded acceptance of an exact validated output version. |
Its execution holds its requirements:
| Field | Type | Required |
|---|---|---|
context | GraphProposalContext | yes |
post_processing | GraphProposalPostProcessing | yes |
response_profile | ProtocolRequestProfile | yes |
workspace_access | GraphProposalWorkspaceAccess | yes |
The values of its context:
| Value | Description |
|---|---|
fresh | Isolated utility with a fresh context for each execution. |
task_conversation | Isolated, resumable task context allocated by the host. |
Of its post_processing:
| Value | Description |
|---|---|
none | No mutating host effects. |
session_workflow | Ordered session effects, if authorized by the host. |
The values of its workspace_access; resolution refuses background_read:
| Value | Description |
|---|---|
shared_read | Share read-only access with other graph readers. |
background_read | Fresh read-only utility that tolerates concurrent ordinary host work. |
exclusive_write | Serialize against all other Env work; writes still require permission. |
Of its response_profile, which a node's output schema also names:
| Value | Description |
|---|---|
FocusedReview | Isolated focused review with a direct structured review response. |
GraphProposal | Initial graph proposal or clarification, before host resolution. |
ReviewMetadata | Direct review-request title and description reconciliation. |
SessionTurn | Interactive session turn. |
UtilityPrompt | Isolated utility prompt. |
A node's inputs and outputs:
| Field | Type | Required | Description |
|---|---|---|---|
name | string | yes | Slot name unique on the consumer. |
output_name | string | yes | Declared output name on the producer. |
producer_node_id | string | yes | Logical producer node, protected by a matching result dependency gate. |
| Field | Type | Required | Description |
|---|---|---|---|
name | string | yes | Output name unique on the producer. |
schema | ProtocolRequestProfile | yes |