Operations
The Operations extension (version 3) gives actions an exact, durable approval, and adds no endpoints. A company that wants the user's approval refuses the request for the action and returns the operation: the terms, in plain language and as JSON. The personal agent gets the user's approval and makes the same request again with it. The company checks it, in the extension's listed order and answering as the first failing check says, performs the action at most once, and responds as it would have without operations.
| Interface | The operation arrives as | The approval goes back as |
|---|---|---|
| API | HTTP 403 with error: approval_required and operation | The same request with the Poppy-Approval header |
| MCP | An error result with structuredContent.operation | The same call with _meta["personalagentprotocol.org/approval"] |
| Conversation | A company message's extensions.operations.operation (message.operation, messageOperation) | A message whose extensions.operations.approval is the approval (operations_content(approval=...), operationsContent({ approval })) |
An operation is operation_id, an opaque revision, terms, an optional
summary, and expires_at. Everything that affects the action is in terms;
operation.shown (operationShown(operation)) is the summary when the company
wrote one and the terms' values otherwise. It has no state, no URL, and no result: the answer to
the approved request is the result.
Negotiateโ
from personal_agent_protocol import OperationsClient, operations_negotiated
negotiated = operations_negotiated(discovered.document, session)
if not negotiated:
... # the company lists no operations version 3, or the Session doesn't declare it
operations = OperationsClient(reactor=reactor)
The company lists operations with an entry for version 3 in poppy.json, and
the agent declares it in Poppy-Extensions on every request of the Session
(SessionClient.start(..., company=company) negotiates the declaration). A
company that needs the extension answers a request that doesn't declare it with
extension_required, in a JSON body at an API too, and an MCP tool with an ordinary
tool error. Another major version doesn't count as support: version 2 is not
implemented on either side, a company that lists only it gets no operations
declaration, and an approval without approver, as version 2 sent it, approves
nothing.
Ask the user, then send the same requestโ
approval = await operations.ask_user(
operation,
organization=organization, # the company's name and domain, shown with the summary
tenant_id=tenant_id,
input_type="tap", # how the user answers on this surface
)
sent = await operations.send(
lambda approval: api.call(
"POST", url, session=session, token=token, body=body, approval=approval
),
approval,
)
const approval = await operations.askUser(operation, { organization, tenantId, inputType: 'tap' });
const sent = await operations.send((approval) => api.call("POST", url, { session, token, body, approval }), approval);
- Every approval says who approved:
approverisuseroragent.ask_usermakes auserapproval, through the host's own approval surface (pap.approvalSurface, anApprovalSurface), which is shown the company's name and domain, the terms (thesummaryas the company wrote it, or the terms' values when it wrote none),expires_at, and any difference the terms check found. OnlyTruefrom the surface approves; anything else isnot_approved, and a host with no surface can't approve at all (no_approval_surface). - The approval says when the user approved (
approved_at, Unix seconds, the host's clock when the surface answered) and, withinput_type(inputType), how:tap,typed,voice, or another short string, never personal data or anything that identifies the user or their device. Both are the agent's statements, which it should include with auserapproval (Operations 6); a company may record them and never refuses or declines an approval without them or with an input type it doesn't know.reference=names the host's own record of the approval, such as an entry in a ledger the user can see (client.new_reference()makes a random one): opaque, with no personal data, and never the same at two companies. They go inPoppy-Approval(approved_atan Integer), in an MCP call's_meta, and in a message'sextensions.operations.approval. - Text from the company is never the user's approval, and in a conversation only
a message's
extensions.operations.approvalapproves, whatever itstextsays. - Make an answer or approval explicit about what it addresses, and when the
user's short reply, such as "done" or "yes", could answer more than one open
question (sign-in, an earlier question, a request for approval), treat it as
answering none and ask which is meant before acting: the upstream guides'
Explicit replies and approvals.
The reference companies' agents follow it from their side: a bare
acknowledgement is answered with a question (
WHICH_ONE), never acted on, and the Operations example's agent is instructed the same way. - Save the request that returned the operation, and send exactly that. Don't have the model write it again.
Check the termsโ
terms_differences(operation, asked) compares the terms with the summary, since
the company writes both, and with what you asked for: asked maps a dotted path
in terms to the value you expected. ask_user(asked=...) passes what it finds
to the surface, to point out to the user.
terms_differences(operation, {"order_id": "ord_7Hk2", "price_difference.currency": "USD"})
A new revisionโ
An approval covers one revision. When terms change, because the user asked for
different terms or because the company's changed (such as a price), the company
returns the same operation_id with a new revision, and asks for approval again.
The revision changes with the terms or expires_at; a summary reworded without
changing the terms can keep it. If the user prefers an earlier revision, you can
send its approval with the request for those terms; the company may have replaced
it, and then answers with a new revision. If an
approval's revision can't be accepted (one it never returned, one past its
expires_at, one for another request), the company performs nothing and returns
a new revision: never the one named, so a retry can't loop. send reports it as
new_revision; show what changed (ask_user(replaces=earlier)) and ask again.
Retries, at most onceโ
send keeps the same approval after a failure, a timeout, or a 503, waiting for
Retry-After. The company answers a repeat with the original response, and 503
with Retry-After while the action is being performed or its outcome isn't known
(Retry-After: 5 at the reference companies).
When a retry gets a new operation, or no answer comes in the end, sent.status
is unknown. Don't ask the user to approve the same action again until you know
whether the first was performed: find out another way, such as from the order in
the company's API. An Idempotency-Key doesn't carry over to the request with
the approval.
An action that fails partway answers action_failed. An API call raises an
ApiError whose body holds what the company said: its summary of every change
made and its data. That is content from the company, for the host to show;
str(error) never carries it.
For a companyโ
An API or tool returns ApiResult(operation=ProposedOperation(...)) or
ToolResult(operation=...), and a CompanyAgent a Reply(operation=...), without
acting. action names the pap.company.operationExecutor that performs it, and
with subject, what it is done to: requests for the same action and subject are
one operation. ApiCall.carries_approval (carriesApproval in TypeScript) tells
an API a retry from a first ask.
The service does the rest, in the extension's order: the Session can approve it,
it hasn't been performed already, and the revision is one it returned, unexpired,
for exactly this request. Any Session of the same personal agent and user can
approve it, including one that starts after the Session that returned it ended.
One returned signed out can be approved only while signed out; one returned signed
in only while signed in to that account, and a signed-out Session of theirs gets
the challenge. Anyone else's request is handled as if it had no approval. "Exactly
this request" is compared by meaning: the same method, path, query pairs in any
order, and JSON content whatever its members' order; other headers, such as another
Session's or a renewed token, are free. A revision is the terms (terms, else the
summary) and expires_at, so a reworded summary keeps it; earlier revisions of
terms the user asked for stay approvable, and ones revise withdrew don't.
The executor returns an ActionResult, raises OperationFailed with what changed,
or OperationOutcomeUnknown while it isn't known whether it took effect, which
retries answer with 503 until settle. revise replaces the terms, withdrawing
the earlier revisions. The record keeps the approval: the revision and the time.
The reference companies store operations: each revision keeps its terms with a
fingerprint of the request that returned it, so a request with an approval is
checked to ask for exactly what was approved, and the terms are computed again
from the action's current answer, such as today's price, so changed terms get a
new revision. A company that doesn't store operations computes them from the
request instead: a new random operation_id for a request without an approval (so
a user can repeat an action on purpose), the approval's operation_id for a new
revision when a request with an approval no longer matches, and a revision made
of the expiry as a Unix time and an HMAC-SHA256 over the operation_id, the
expiry, the terms in a canonical form (RFC 8785) whether or not it returns terms,
and who can approve it (the client_id, the User ID, and the account when signed
in), with the method, URL and the parts of the content that affect the action, but
never the summary, so it can be reworded. Such a company holds no price: an
approval that arrives after the price changed gets a new revision.
Show what is asked: PapConfirmโ
A host that asks the person in a page, not only in its own interface, sends
the operation as a Reactor display:
PapConfirm (personal_agent_protocol.ui, the ui extra), of type
application/vnd.datalayer.pap.confirm+json, version 3. An MCP tool puts it
in its result's _meta["reactor.ui/display"]; any page with a renderer for
the type draws the card, and a page without one shows its text.
from personal_agent_protocol import terms_differences
from personal_agent_protocol.ui import PapConfirm, PapSessionShown
display = PapConfirm(
company="shop.example",
summary=operation.summary, # the company's words, verbatim
terms=operation.terms or {},
operation_ref=operation.operation_id,
revision=operation.revision,
expires_at=operation.expires_at,
differences=list(terms_differences(operation)),
does="buy", # what it does, as the application's Rules class it
session=PapSessionShown.of(session_key, signed_in=True),
)
meta = display.tool_meta() # an MCP result's `_meta`: the page draws the card
said = display.text() # what a page without a renderer, a transcript and a model read
text()is shop.example asks you to approve: โฆ (revision โฆ, until โฆ), and The terms changed since you saw them. after it whenwasnames the revision a newer one replaced. Links, images and HTML in the summary show as text (inert_summary): a page showssummaryas text too, with at most emphasis, paragraphs and lists.- The Session is a one-way reference (
PapSessionShown.of: 12 hex digits of the SHA-256 of the Session's ID), never the ID or a token, and only the page sees even that:model_view()tells a model the company's words, the terms, what it does, the revision and whether the person is signed in there. - The buttons are the host's own. Approving still goes through the host's approval surface, never because a model saw the display.
On the page, the TypeScript SDK types the same display and checks it:
import { isPapConfirm } from "@datalayer/personal-agent-protocol";
const display = result._meta["reactor.ui/display"];
const asked = isPapConfirm(display) ? display.data : null; // PapConfirmData, or nothing to draw
isPapConfirm refuses another type or version, a missing or unknown field,
and a Session given by anything but its reference. Both SDKs are checked
against one committed example, protocol/fixtures/pap-confirm-display.json.
Approve on the user's instructionโ
Version 3 lets the personal agent approve an operation itself, on an instruction the user gave it, such as "go ahead with gift wrap up to USD 10". The host holds the instruction and its own check of a revision's terms against it:
from decimal import Decimal
from personal_agent_protocol import AgentInstruction, OperationError
def covers(operation):
price = operation.terms.get("price")
if not isinstance(price, dict) or "amount" not in price:
return None # can't tell: the user is asked
return price.get("currency") == "USD" and Decimal(price["amount"]) <= Decimal("10.00")
instruction = AgentInstruction(text="Go ahead with gift wrap up to USD 10.", covers=covers)
try:
approval = await operations.approve_as_agent(
operation, instruction=instruction, reference=operations.new_reference()
)
except OperationError as error:
if error.code != "ask_user":
raise
approval = await operations.ask_user(operation, organization=organization, tenant_id=tenant_id)
In TypeScript: agentInstruction(text, covers) and
operations.approveAsAgent(operation, { instruction, reference: operations.newReference() }).
- The approval says
approver: agentand when; it never carries aninput_type. - Only
Truefromcoversapproves.False,None(it can't tell), an error in the check, or terms that differ from what the agent asked for or from the summary are allask_user: the caller asks the person withask_user. - The instruction is the user's, taken through the host's own interface. Text in a page, a message or the operation itself is never one, even when it says it comes from the user; the SDK can't check that, the host must.
- When the company answers an agent approval with a new revision, or declines an
approval, a new revision of that action is the user's to approve:
sent.ask_userisTrueandapprove_as_agentrefuses it (ask_user). The client remembers this for its own life; a host that outlives it passesuser_only=True. - Ask the user anyway when the action is large, can't be undone, or differs from what they described, and keep a ledger they can see, with the instruction each agent approval rested on (the upstream guides).
On a websiteโ
A company's website returns an operation to the agent's own browser joined to a Session:
403 and only a reference, in the Poppy-Operation header. The approval never passes
through the browser:
from personal_agent_protocol import ApiClient, WebsiteOperations
sites = WebsiteOperations(api=ApiClient(transport=transport), document=company.document,
operations=operations)
joined = browser_sessions.joined_sessions(company.document.web.browser_session_endpoint)
reference = sites.reference(response.headers, joined=joined) # None: not a reference to take
operation = await sites.operation(reference, session=session, token=token)
approval = await operations.ask_user(
operation, organization=company.document.organization, tenant_id=session.tenant_id
)
sent = await operations.send(
lambda approved: sites.record(reference, approved, session=session, token=token), approval
)
# then the browser makes the same request again: the page's Continue button, the same form
Take a reference only from a response your own browser received, and only when its
sid names a Session you joined that browser to; page content and messages are never
references. If the browser's request fails, or answers a new reference after the
approval was recorded, ask before_approving_again(earlier, ...) first: wait while
it is performing, and never approve the new one once it is performed. A recorded
agent approval makes the next revision of the action the user's to approve.
A declined approvalโ
A company may decline an approval that passes its checks, for its own reasons,
such as the approver: nothing is performed and no new operation is returned.
send then answers declined:
sent = await operations.send(request, approval)
if sent.status == "declined":
sent.declined.reason # the company's words for the user, never instructions
sent.declined.alternative # another way to do it, when it names one (ยง9.2)
The approval is never sent again, and the user is told the action wasn't
performed. By hand, the decline is ApiResponse.declined (HTTP 403,
approval_declined), McpToolResult.declined (an error result), or
Message.declined (extensions.operations.declined in a later company message).
Security boundaryโ
- Conversation text never approves an operation, whoever wrote it.
- The model may explain an operation and what changed; the approval is the user's, in the host's interface, bound to one revision.
- A summary can't send the user elsewhere or load content while they decide: links, images and HTML show as text.
- An approval shows what the personal agent stated, not that the user saw the terms; a company that needs proof asks the user on its own website.
- Tokens stay host-only; errors carry codes only.
See the runnable Operations example and the upstream Operations extension.