ADR 0054: Agent writes are proposals the person approves on a Karyo page
Status: Accepted. Implements the proposal boundary that ADR 0041 planned and ADR 0047 left out. It adds six prepare tools and three proposal-state tools to the surface of ADR 0047, so ADR 0047's "twelve read-only tools" and "exactly one identity exception" are superseded in part: the proposal-state tools are a second, equally exact exception.
Context
ADR 0041 retired Karyo's Copilot and decided that an outside agent may only propose a change, and that a person decides on a page Karyo itself serves. ADR 0047 built the read half. Without a write half, an agent could describe a change and nothing more.
Three facts fix the shape of the write half. Karyo authorizes every call from stored grants (ADR 0048), so an agent must not hold authority of its own. A client's confirmation prompt belongs to the agent's channel, so it cannot be the person's decision. And a write the agent prepared may be approved minutes later, after a grant changed.
Decision
- Every agent write is a proposal. Six prepare tools exist: receive stock, put away, change a
stock state, create a unit load, release a pick order and manifest a shipment. Each mirrors the
REST operation its approval runs, declares that operation's catalogue action, and carries the
hints a client needs: not read-only, destructive, idempotent, closed-world. A prepare tool changes
no warehouse data. The mirror guard holds each one to a POST declared
OPERATIONAL_WRITEwith the same action as its target. - Preparing validates and records.
TenantFilter.forAgentWriteresolves the principal's current grants for the write action in one Facility, as the REST filter would. The tool then reads every record it names through the same read operations the console uses, so a missing or foreign id fails when the agent prepares, not when a person is asked. The proposal is one row inagent_proposals: the parameters, a summary Karyo wrote from its own lookups, and every outside string (names, notes, the agent's own carrier text) underuntrusted. - One person, one page. The proposal's own principal approves it at
/approvals/:idwith the console session. An MCP-audience token cannot reach/api/v1. Another principal's proposal is as absent as a missing one (404). A request whoseazpis the proposal's own agent client is refused, so an agent client cannot approve what it prepared even with a console-audience token. - Approval is single-shot and rechecks authority. Confirm locks the row, then checks, in order: ownership, expiry, state, the installation switch, the connection's approval, and the write action for the proposal's Facility. An authorization refusal (401, 403) leaves the proposal pending, so the rightful person can retry once the grant returns. The write action is evaluated again directly before the mirrored call, against the same request's reading of the grants, so a grant removed after the request began is not seen until the next one. A domain failure of that call rolls its work back in the same transaction and ends the proposal FAILED, with the reason kept for the person and the agent.
- Execution is the REST operation's own code. The executor calls the mirrored resource methods
in-process, in one transaction with the state change, so validation, locks, journals and events are
the ones the console produces.
TenantContext.actorClientIdnames the agent client, andJournalServicewrites it asinventory_journals.actor_client_idbeside the actor principal. The journal shows the person and the agent that prepared the change. - A retry never repeats a write.
(principal, client, idempotency key)is unique. The stored request fingerprint is a SHA-256 of the canonical request. The same key with the same request returns the same proposal without a second lookup; the same key with another request is a conflict (409). - Proposals expire. The default is 15 minutes, set by
karyo.agent.proposal-ttl-minutes(1 to 1,440) at Company configuration key 0 orKARYO_AGENT_PROPOSAL_TTL_MINUTES. An overdue proposal is expired by a once-a-minute sweep and also when anyone asks. An expired proposal never runs. Decided rows are kept for 90 days. - Writing needs its own scope.
karyo.writeis required to prepare or withdraw; a token withkaryo.readalone receives 403insufficient_scope. Reading proposal state does not need it. Preparing has its own per-principal, per-client budget,karyo.agent.prepares-per-minute(default 10), separate from reads. Approval of a connection, by the administrator who enables the exact principal and client, covers both reading and preparing. - The agent reads its own proposals through three tools that mirror the person's Approvals
routes: get one proposal's status, list its pending proposals, and withdraw one before the person
decides. They are self-service on the agent's own principal and client, authenticate without a
catalogue action as
whoamidoes, and are the second exact identity exception. The guard names the declaring class and target for each. - The link grants nothing. Each tool result carries
approvalUrl. When the client declared URL elicitation in its initialize handshake, Karyo also asks it to open that same link. The MCP library reads the declaration only from that handshake, so a request that carries its capabilities inline (protocol 2026-07-28) is never asked and relies onapprovalUrl. The link is never pre-authenticated: the page asks the person to sign in, and it shows the proposal only to its own principal. - The page is a console page of Core. It appears while agent access is on (capability
agent-access), declares IDENTITY scope with no catalogue action, and shows Karyo's summary above outside text, which sits in a block that says it is data.
Consequences
A prompt-injected order note or carrier string cannot change what the summary says, and the page never presents outside text as an instruction. If the person loses the write action after the agent prepared a change, approving it is refused with 403 and the proposal stays pending, so a grant that returns lets the same proposal run.
The approval page is the only place a proposal runs. The proposal names its Facility and the page shows it, so a person can approve a change in a Facility they were not looking at. A person can still approve a change they should have declined: the page's job is to show Karyo's own facts and to mark everything else as outside text, not to judge the change.
The sweep and the confirm lock assume the supported single application instance. agent_proposals
holds parameters and outside strings for up to 90 days after a decision.
An installation whose Keycloak realm was imported before this record has no karyo.write client
scope. --import-realm skips an existing realm, so the scope, its consent text and its place in the
agent registration policy must be added to that realm by hand. A new realm needs nothing.
Alternatives considered
- Run the write when the agent calls the tool, after an MCP elicitation. Rejected: the prompt travels through the agent's own channel and not every client declares elicitation, so the confirmation would be the agent's and could be skipped.
- A pre-authenticated approval link. Rejected: a link that carries the approval would let anyone holding it decide, and would leave the decision outside the person's session.
- A separate
approvals.decidecatalogue action. Rejected: the person's authority to run the change is the mirrored operation's own write action, which confirm already re-checks. A second action would be an authorization that could disagree with the first. - Execute through a copy of each service call. Rejected: it would repeat the drift ADR 0047 rejected for reads. The executor calls the mirrored resource methods.
- Keep the proposal in the agent's session. Rejected: a restart or a stateless client would lose it. The row survives a restart and is the same row every instance reads.
Evidence
services/karyo-app/src/main/resources/db/migration/agent/V1603__agent_proposals.sql,karyo.agent_proposals- the table, its state check and the idempotency key.services/karyo-app/src/main/resources/db/migration/inventory/V114__journal_actor_client.sql,actor_client_id- the agent client on journal rows.services/karyo-app/src/main/kotlin/com/karyo/app/agent/ProposalWriteTools.kt,ProposalWriteTools- the six prepare tools.services/karyo-app/src/main/kotlin/com/karyo/app/agent/ProposalStateTools.kt,ProposalStateTools- status, list and withdraw.services/karyo-app/src/main/kotlin/com/karyo/app/agent/AgentProposalService.kt,AgentProposalService.confirm- confirm: lock, order of checks, failure handling.services/karyo-app/src/main/kotlin/com/karyo/app/agent/AgentProposalExecutor.kt,AgentProposalExecutor- the in-process calls and the second write-action check.services/karyo-app/src/main/kotlin/com/karyo/app/agent/ApprovalsResource.kt,ApprovalsResource- the person's routes.services/karyo-app/src/main/kotlin/com/karyo/app/auth/TenantFilter.kt,TenantFilter.forAgentWrite- write grant resolution for an agent.services/karyo-app/src/main/kotlin/com/karyo/app/agent/AgentDispatchFilter.kt,AgentDispatchFilter.decide- write scope and prepare budget before conversion.services/karyo-app/src/test/kotlin/com/karyo/app/agent/AgentProposalRuntimeTest.kt,AgentProposalRuntimeTest- signed tokens through prepare, approval, refusal, expiry, replay and attribution.services/karyo-app/src/test/kotlin/com/karyo/security/guards/AgentToolMirrorTest.kt,AgentToolMirrorTest- write mirror rules and the exact exceptions.frontend/web/src/pages/approvals/approvals-page.tsx,ApprovalsPage- the Approvals page.tests/e2e/tests/approvals.spec.ts,Approvals- the agent prepares, the person approves and declines.