Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

ADR 0049 — What the agent link and the gateway need for the Studio Assistant

Status: proposed (2026-11-14). Design: canvas row Assistant (AssistantAsk, Assistant, AssistantRun, AssistantDone, AssistantFailed, AssistantRights, AssistantDrawer). Studio side: studio/docs/design/specs/assistant.md. Extends ADR 0005 (AI surface) and ADR 0033 (agent command line); closes docs/studio.md §10 items 1, 3, 5, 11, 12.

Context

The Studio Assistant (phase 12, docs/studio.md §7.8) is a chat with the agent link (links/agent): ask streams the model’s lines and its reads, the task list follows tasks/* ~val, Reject and Cancel work. The boards show more than the broker can give today:

Board showsBroker today
The plan with every step, its arguments, level, check result and the model’s whyThe plan is in the task’s ~state document; the gateway has no op that reads documents (ws.rs: meta, children, list, subscribe, history, set, invoke, check)
Approve signs one token per ticked step with the user’s rightsapprove {approvals} wants one human ptok per request key, signed by the approver; a gateway user has no key. The action itself is level config
Unticked steps are left outapprove refuses unless every step that needs approval has a token (missing approval for …)
The assistant asks back with choice cards (AssistantAsk)No tool for asking the user, no state for it, no answer
WAIT / EXPECT steps (the plan proves itself)Agent plans hold set/invoke only; wait/expect exist only in wyrm_mcp::gw::Step (plans of wyrm-agent run / MCP plan_run)
Run card with the current step and its answer~val of a task is {state}; per-step results are only in ~state
Try Slave ID 4, Undo the plan, Make a plan for 2 unitsEvery ask starts from nothing
@ modbus/tcp-line2 chips, the Explorer drawer about the selectionask {task} takes text only
Today 182 k of 1 M tokens, API key set · never shownThe budget used is internal; secret names are not readable
A warning on a step (Slave ID 3 was used by ahu-old) with fixespropose returns ok or an error, nothing in between

Decision

  1. Documents through the gateway. A gateway op doc {key, suffix} (suffix ∈ ~state, ~def) answers a node’s document with the rights of list on that node (the agent’s tasks folder is restricted, so the asker or a config caller). Studio reads a task’s record with it after every state change.
  2. Approvals through the gateway. On invoke(<agent>/tasks/<id>, approve, {steps: [i…]}) from a user, the gateway reads the task’s plan (op 1), mints one user token per listed step for that step’s key and level, exactly as add_flow_proofs does for flow deploys, and refuses (before anything is sent) when the user’s grants do not reach a step. The token’s sub is the user, so the agent’s “approver = signer” check holds. Callers outside the gateway keep sending approvals.
  3. Approve at the step’s level. approve becomes level write on the task; what a person may approve is decided by the tokens (a token at config for a config step). An engineer with config on downstream/modbus/** approves a Modbus plan without config on the agent link.
  4. Partial approval. approve accepts a subset: the steps without a token are marked skipped (log line skipped by <sub>), never run; a step the model marked after: [n] is skipped when a step it depends on is. propose takes after (default: the previous step on the same key prefix). Approval tokens are keyed by step index (approvals: {"<i>": ptok}), not by request key, so two steps on one key both work; the key form stays accepted.
  5. Asking back. A model tool ask_user {question, options: [{id, label, detail}], multiple?, free_text?} (≤ 3 questions per turn, ≤ 6 options each, options must name things the model read). The task goes to a new state awaiting_answer (wire_enum! row in the task states; Studio maps it). tasks/<id>/~act/answer {answers: {<question>: [<option id>] | text}} (level write, asker or config) resumes the model with the answers. ~state carries questions[].
  6. Proof steps. Agent plans take the steps of wyrm_mcp::gw::Step: wait {key, timeout_s}, expect {key, equals | min/max | changes, timeout_s}, sleep. They need no approval (read). The plan format of ~state.plan[] becomes the wyrm-agent run format, so Save as a plan is the plan as it stands.
  7. Progress in ~val. A task’s public ~val becomes {state, step, of, last} (last = {n, ok, text} of the latest finished step), published at each step. ~state keeps per-step result (ok | failed | skipped, text, time).
  8. Checks and warnings on proposed steps. propose answers {ok, check, warn?}: check = now (checked against the live tree) or at_run (depends on an earlier step); warn = text the model must show (a slave id in use, a value at a limit). Studio draws warn on the step; the model offers fixes as an ask_user.
  9. Follow-up asks and context. ask {task, parent?, context?: [key…]}: parent hands the model the parent task’s ask, plan and results (a retry, an undo, the same for more rows); context are keys the person attached (@ chips, the Explorer selection), read first and within the asker’s rights. Undo is a follow-up ask the model plans like any other; nothing is reversed automatically.
  10. What it may do, readable. The agent root shows budget_used_today (u64, read). sys/links/<id> shows secrets (names only, level config), so Studio can say set / not set for api_key_ref (docs/studio.md §10 item 12).

Rules added when it was built (2026-11-14)

The decisions above stand. These rules make them safe; items 2, 3 and 7 are narrower than their first wording.

  • The gateway signs only what it read (§2). The plan is the one the agent link stores: the gateway reads tasks/<id>/~state itself, with the user’s own token. The client sends {steps: [n…], plan: <hash>} and nothing else of a step. With approvals in the arguments the caller brings its own tokens and the gateway adds nothing.
  • An approval is for the plan the user saw (§2). The plan’s hash is the SHA-256 (hex) of the canonical CBOR of ~state.plan, each step without approval, check, warn, model_warn, reason, result (model_warn since the amendment of 2026-11-14). Studio makes it from the plan it shows, the gateway from the plan it reads (never from ~state.plan_hash, which it only compares), the link from the plan it holds. approve {plan} is refused when they differ (invalid_parameter, “read it again”).
  • One token, one step (§2). A token’s subject is the user; its single grant is exactly the step’s request key (<node>/~set, <node>/~act/<action>); max is the level the step needs, not the user’s level; args is the SHA-256 of the step’s request body (spec 04), so it is good for those arguments only; jti is fresh (single use); exp is 5 min. The step’s node must be a plain key of the task’s site: no wildcard, no ~ segment.
  • An approval does not wait (§2). A token is made when the person approves and is spent when its step is sent; its life stays short (5 min from the gateway; spec 04 allows at most 15 min and one use). No token is made for later and none is made longer. So the agent link takes no step that needs a person into a plan when the waits before it (wait/expect timeouts, sleep) add up to more than 240 s: propose answers the model with the reason. And approve is refused (invalid_parameter, the task keeps waiting) when a token cannot outlive the waits before its step, among the steps that run, plus 30 s. The person leaves that step out and asks for the rest as a follow-up (§9) when the plan is done; it is approved then. A step that is still late (slow requests before it) fails closed: the target refuses the dead token and the run stops.
  • Only a person, only an agent link (§2). The gateway signs approvals for a person’s own session alone: a session of an MCP client (/mcp, ADR 0041) is refused, and the Claude connector (wyrm-mcp --gateway) never sends approve for a task. The level of approve is write, so the connector’s allow_config switch would not have stopped a config step. And it signs only for wy/<this site>/downstream/<link>/tasks/<id> where <link> has the driver agent in the broker’s registry (Gateway::set_agent_links, told at every router build): a link that only serves a plan-shaped ~state gets no token of the user.
  • A person is told by the login, not by the transport (§2, 2026-11-14). The gateway treats a session as a person’s only when its frames come over /api/ws (not the /mcp pipe) AND its login method is a person’s: Amr::is_person = Password or Device, an exhaustive match (OAuth and any later method are not a person until written there). The same helper decides the approve gate, POST /api/ws-ticket and the /api/ws upgrade (403, permission_denied, code: person_required) and every step-up check in devices.rs. It tells how a session was made, not who drives it: a password session that a tool uses (wyrm-mcp --gateway --user) is still a person’s, and that connector’s refusal to send approve stays its own rule.
  • The meta of approve (§2). approve declares approvals (not required), steps and plan, so a client that checks arguments against ~meta takes both forms. steps without approvals that reaches the link itself is refused: no gateway signed it.
  • Never beyond the user’s grants (§2). The gateway checks every named step against the user’s grants before it signs. If one fails, the whole call is refused before anything is sent, and the answer names the step and the right: step 3 needs config on wy/…/~act/deploy; you have write. The refusal is in the audit (Denied, op approve); a signed approval is too (approve, the request keys, the count left out).
  • Who approves (§3). approve is write on the task, so the caller may be a stranger to the task. The asker, or a caller with config on the link, decides for the task: a step that needs no human runs with the agent’s key, as it would without an approval. Anybody else decides only for what they sign: every step that changes something needs their own token (the steps the agent would run with its own key too); a step without it is skipped, with the steps that need it, and nothing runs with the agent’s key on their word. So an engineer with config on downstream/modbus/** approves a Modbus plan with write on the agent link, by signing its steps.
  • Proof steps (§6) read with the agent’s reader, inside allowed_prefixes, and take no token. A step on a node that an earlier step makes is check: at_run: taken at write, and checked against the live ~meta when it runs; a node that then asks for more, or for other arguments, stops the step before it is sent.
  • The public ~val holds no text (§7). ~val is read by anyone who may read the link; the record is restricted. So last is {n, ok, result} with result one of ok, failed, skipped: not {n, ok, text}. The text of a result, the value read and the node key are in ~state.plan[n].result {status, message, time}, which Studio reads through doc.
  • Asking back (§5). A restart ends a task that waits for an answer (interrupted by restart), as it ends planning: the model’s turns are in memory. answer is a stream like ask; the ask stream ends with awaiting_answer.
  • Follow-ups (§9). parent must be a task the caller asked, or the caller has config on the link. A context key must be inside what the agent may read and inside what the asker may read (auth of the caller’s token). The asker’s rights are read as every evaluator reads grants (spec 04): the first grant that touches the key decides (Caller::perm_on, wyrm_core::ptok::level_on), so a none before a wider grant keeps the value out of the model’s prompt.
  • Secret names (§10) are the action sys/links/<id> ▸ secrets (level config, names only), not a value: a ~val is read at read.
  • Task states are the agent link’s own table (TaskState, wire_enum!, by name in ~val.state); they are not in spec/. The gateway’s frame protocol is documented in crates/wyrm-gateway/src/ws.rs and docs/broker.md; no spec/ text changed.

Amendment (2026-11-14): what the model offers next, a replaced plan, fixes on a step

Studio built specs/assistant.md §2 steps 1–4 and found three cards without data: the ways out of a stopped run and the Same for more units? rows (and the second button of the Explorer drawer), the old plan shown as replaced, and the fixes in a step’s warning. The owner delegated the design (ADR 0029). One tool, three record fields and one rule close them; no spec/ text changed.

1. Suggestions. A model tool suggest {label, detail?, changes?, step?, rows?: [{path, label, detail?}]} adds one entry to the task’s record: ~state.suggestions[] = {id, label, detail, changes, step?, rows?: [{key, label, detail}]}.

  • It is what the person may ask next: a way out of a run that stopped, the same change for more nodes (rows, one per node), a fix for the warning of plan step step, the drawer’s second button. changes is the model’s count of the changes it would take (0: nothing changes): the tag on the tile, nothing more.
  • A suggestion is data and runs nothing. The link never acts on one, and the gateway never reads one. A person who picks it sends a follow-up ask {parent, task, context?} (§9) whose text is what they saw on the card (label, detail, the labels of the ticked rows) and whose context is the keys of the ticked rows. What that changes is a new plan, checked as any plan and approved step by step with the person’s own tokens (§2–4).
  • Bounded. At most 8 suggestions in a task at a time, 16 rows each (the context limit of ask), label ≤ 80 bytes, detail ≤ 300 bytes (longer text is cut), changes ≤ 50. step must be a step of the plan so far.
  • Inside the asker’s rights. A row names a plain node key of the task’s site that the agent may read (allowed_prefixes, pub/**) and that the asker of the task may read (Caller::perm_on(<node>/~val) over the person’s grants that the token carries as auth, spec 04). Fail closed: the rights are known only from a token with auth (a token without it means unknown rights, and the row is refused, as the flow engine refuses sources), they are kept in memory only (after a restart of the link nobody’s rights are known), and they hold only until that token’s exp. The asker’s own later answer or approve on the task renews them (their newer token); a call of somebody else does not. So a row of a planning turn after a long wait, or of a review after a restart, is refused, and the model offers the way out without rows. Any other row refuses the whole suggestion to the model. ask {context} needs auth in the same way (permission_denied). The follow-up ask checks its context against its own caller again. The follow-up ask checks its context against its own caller again.
  • Texts stay in the record. The public ~val gains suggestions (their count, absent at 0) and no word of them. Studio reads them through doc with the reader’s rights.
  • After a run stopped. The model has no turn in a task that ended, so a run that stops at a step (a step failed; not a reject, a cancel or a restart) gets one: a review, at most review_turns LLM calls (param, default 4, 0 = none), with the read tools and suggest only. No propose, no ask_user: nothing is planned and nobody is asked. The model gets the task’s ask, plan with results and error, reads why, and offers ways out. The task stays failed and its error stays the run’s; ~val and ~state show reviewing: true while the turn runs; the model’s last words are ~state.review (≤ 600 bytes). The turn spends the daily budget like planning; without budget or model it is skipped with a log line. cancel (asker or config) while reviewing ends the turn: reviewing goes, no review, the task stays failed with the run’s error. A task removed to make room (eviction) ends its review with it.
  • Suggestions follow the plan they were made for. A task that fails (a stopped run, reject, cancel, replaced, restart) drops what planning offered; after a stopped run the review’s ways out take their place. A task that is done keeps them: the Same for more units? table of the result card.

2. A replaced plan. ask {parent} where the parent waits for a person (awaiting_approval or awaiting_answer) takes the parent’s place: under the same lock that creates the new task, the parent goes to failed with error: "replaced by <id>" and the field replaced_by: <id>, in ~state and in the public ~val (a task id the link made, no text). No new state: failed is already how a plan ends that will not run (reject, cancel), so every reader of states stays right.

  • approve on a replaced task is refused with invalid_parameter (0x23), task was replaced by <id>: … approve that task. The gateway refuses the same way from the record it reads, before it signs anything. answer, reject and cancel are refused as for any task that ended.
  • A parent that is planning, running, done or failed is not touched: a follow-up of it replaces nothing (a run goes on until cancel; an undo of a done task is a new plan beside it).
  • If the follow-up fails while planning, the parent stays replaced: the person asks again (the failed follow-up or the old task as parent). An old plan that came back after another one was asked for could be approved by mistake.
  • The mark is in the stored record, so it holds after a restart.

3. Fixes on a step. §8 said warn is text and fixes are an ask_user. Two things were missing: only the link could warn (a value at a limit), and nothing tied a fix to a step. Now propose takes warn (≤ 300 bytes), kept in the step’s own field model_warn: warn stays the link’s own finding (a value at a limit), so a reader always tells the link’s words from the model’s, and Studio shows model_warn as the model’s (a different label or style, never as a check of the link). A fix is a suggestion with step: n. Studio draws the suggestions of step n in that step’s warning box. A fix is picked like any suggestion: a follow-up ask {parent}, which replaces the waiting plan (rule 2) with a plan the person approves. So the plan with its warning can be approved as it is, or a fix picked, as the board Assistant shows; the spec’s “each fix = answer” does not hold (an answer exists only in awaiting_answer, where nothing can be approved). warn and model_warn stay outside the plan’s hash (UNHASHED in the link and the gateway, planUnhashed in wyrm_client). A client that still hashes model_warn makes another hash, and its approval is refused (“read it again”): it fails closed.

Old records and old clients. The three fields live in the record’s plan bytes beside questions, parent and context (store schema 1 unchanged); a record without them reads as no suggestions, not replaced, no review (test a_task_written_before_the_suggestions_still_loads, fixed bytes). A link of the version before reads the new records too (an ADR 0048 rollback): it skips the keys it does not know, and a replaced task is failed for it as well. A client that does not know the fields ignores them.

Which card shows which suggestions (specs/assistant.md §6): a PlanStepCard those with step = its number while the task is awaiting_approval; the ResultCard of a done task those with rows; the StoppedCard all of them with review; the Explorer drawer’s second button the first one without step. While the task is awaiting_approval, that button shows the suggestion’s detail as a draft to copy and sends no ask: a follow-up ask {parent} would replace the plan the person still means to approve (rule 2). After the task has ended, it is a follow-up ask like any way out. Picking a fix tile does replace the waiting plan, and the tile says so.

Tests: links/agent/tests/agent.rs a_stopped_run_gets_ways_out_and_a_step_gets_fixes, a_suggestion_is_bounded_and_inside_the_askers_rights, a_follow_up_replaces_a_task_that_waits_for_a_person; crates/wyrm-gateway a_replaced_plan_is_not_signed_and_suggestions_are_read_through_doc and the unit test of approve::Plan::select; dart/wyrm_client/test/agent_test.dart.

Amendment 2 (2026-11-14): what the model found

Studio built specs/assistant.md §2 step 6 and found one more card without data: the rows of What I found in the Explorer drawer (board AssistantDrawer). The model’s findings were only its text. The owner delegated the design (ADR 0029). One tool, one record field and one count close it; no spec/ text changed.

  • A model tool found {path, label, detail?} adds one row to the task’s record: ~state.findings[] = {key, label, detail}. It is in the planning turns and in the turn after a stopped run (both only read). One row per node, in the order the model noted them.
  • The model’s words, no verdict. label and detail are model text: a client shows them as plain text, never as a link, a check or a button. A row carries no mark good or bad. The board’s ✓ and ✕ are drawn by the client from the node’s live value (its quality), read with the viewer’s own rights; without a value the row has no mark. So a mark is never the model’s claim.
  • Bounded. At most 12 findings in a task; label ≤ 80 bytes, detail ≤ 300 bytes (longer text is cut, the … inside the bound; the same for suggestions). One row per node: a second finding on a node replaces the words of its row in place (same order, same count), so the turn after a run corrects what planning noted instead of keeping a stale good.
  • Inside the asker’s rights, as the rows of a suggestion. The key is a plain node key of the task’s site (no wildcard, no ~ segment) that the agent may read (allowed_prefixes, pub/**) and that the asker may read (Caller::perm_on(<node>/~val) ≥ read over the grants of their token’s auth). Fail closed: unknown rights (a token without auth, a restart) or rights past their token’s exp refuse the finding, and the model is told to note none (not to put the node into its answer). The same rule as amendment 1.
  • Why rows are missing. Each refusal is counted in ~state.findings_refused {rights_unknown | rights_expired | outside_rights | limit | invalid: <count>}: fixed words, no model text. Studio says from it why rows are missing. The rights last as long as the asker’s last call on the task (ask, their own answer or approve): 5 min from the gateway (PTOK_TTL). Nothing renews them on its own (no rights-renewal code, by design), so findings are refused as rights_expired when (1) the turn after a stopped run starts after another person approved the plan (the run’s end starts it, not a person, and that approval does not renew the asker’s rights), or (2) the run took more than about 5 min after the approval.
  • Texts stay in the record. The public ~val gains findings (their count, absent at 0) and no word of them, so a reader of ~val learns that the record changed, not what it says. Studio reads them through doc with the reader’s rights.
  • They stay. A finding says what was read, not what to do: unlike suggestions, findings are kept when the task fails (reject, cancel, replaced, a stopped run). They are no part of the plan and not in its hash.
  • Old records. findings lives in the record’s plan bytes beside the fields of amendment 1 (store schema 1 unchanged). A record without it reads as no findings (test a_task_written_before_the_findings_still_loads, fixed bytes of the richest record of the version before). A link of the version before skips the key. The gateway is not touched: doc passes the record through, and no gateway code reads findings.

Tests: links/agent/tests/agent.rs findings_are_bounded_inside_the_askers_rights_and_stay; store unit tests; dart/wyrm_client/test/agent_test.dart (TaskFinding, findingCount).

Consequences

  • One gateway op (doc), one gateway rewrite of approve (like flow proofs), and agent link changes in store.rs (task schema: questions, after, per-step result; old tasks read with defaults) and lib.rs (ask_user, answer, awaiting_answer, wait/expect, ~val progress).
  • docs/studio.md §10 items 1, 3, 5, 11, 12 close when this is built; §7.8’s “built now” paragraph is replaced by studio/docs/design/specs/assistant.md.
  • e2e: ask → ask_user → answer → plan → partial approve (one step skipped, its dependant skipped) → wait/expect → done; approve refused for a user without the level; doc refused without list.

Not decided here

  • Approvals through the gateway for a task on a downstream site. The gateway knows the agent links of its own site only, so approve {steps} there is refused; Studio must lock Approve with that reason when the viewed site is not the gateway’s own. Open: the downstream broker tells its agent links upward, or the user’s gateway asks the downstream gateway to sign.
  • A second model for the Assistant (Claude through the user’s own connector, ADR 0041, instead of the agent link’s API key). The Studio screens stay the same; only who writes the plan changes.
  • Generated views in the chat (A2UI, specs/genui-views.md): a later card type.