Approvals and roles
The model is never the last word on something that can't be undone. Every side effect the agent asks for is an action, saved before it runs, and the template's policy decides on it: it runs, it is denied, or it is held until a person approves.
Holding a tool for approval
export const refundOrder = defineTool({
description: "Refund one of the customer's orders in full.",
input: z.object({ number: z.string() }),
trust: "tool_verified",
effect: "write",
requiresApproval: true,
run: async ({ number }, ctx) => payments.refund({ customer: ctx.external_ref, number, idempotencyKey: ctx.action }),
});
requiresApproval: true holds every call to the tool, tainted or not. The template's policy_envelope can hold others.
What the person reads
The approval's title is one sentence and its fields are the call's input, in a person's words. <AgentChat> draws both. For your own tool the sentence is yours:
export const emailMe = defineTool({
title: "Email you",
approvalTitle: 'Email you "{subject}"?',
approvalFields: ["message"],
description: "Email the customer. Use it only when they asked to be emailed.",
input: z.object({ subject: z.string(), message: z.string() }),
trust: "tool_verified",
effect: "egress",
requiresApproval: true,
run: async ({ subject, message }, ctx) => mail.send({ customer: ctx.external_ref, subject, message }),
});
approvalTitleis the card's title. Each{name}is replaced by that field of the call's input: text or a number, on one line, at most 80 characters. A field the call left out is replaced by nothing. At most 200 characters.- Without
approvalTitlethe title istitleand a question mark ("Email you?"), and withouttitlethe tool's name in words ("Email me?"). approvalFieldssays which of the input's fields are the card's facts up front, and in what order: here the message, because the sentence already says the subject. Every other field stays on the card behind its details, so nothing the agent chose is hidden from the person deciding.[]leaves the sentence alone up front. WithoutapprovalFieldsevery field is up front, in the input's order.descriptionis for the model and is never shown to a person. Nothing on the card names your connector or the tool's id.
The sentence is part of the template version, so a change to it reaches a workspace with the next version you promote.
What happens to a held action
- The action is saved with
status: "requires_approval", andaction.requires_approvalfires. The run that asked ends: a run never waits for a person. - A person approves or rejects it within 24 hours. Then
approval.decidedfires, orapproval.expiredif nobody decided. - An approved action runs in a later run, with exactly the input that was approved. The approval is bound to that input by the action's
action_hash: a decision that names another hash is refused. - After a reject, a run follows too, in which the agent tells the person the action was dropped.
When that run can't start now, because the workspace reached its spending limit or the agent is paused, the decide answer says so in run_refused. It is the same refusal a message sent now would get: code (cap_reached, credits_exhausted, workspace_suspended, workspace_archived or agent_paused), message to show the person, partner_message for you, and on cap_reached the limit and when it resets. The decision itself is kept: a paused agent acts on it once resumed. Without run_refused a run follows, even if it waits its turn. <AgentChat> shows the refusal under the decided card instead of a working indicator.
An action's status is requires_approval, approved, executing, completed, failed, rejected or expired. GET /actions/{id} shows its tool, input, policy decision and, once done, its receipt.
Who may decide
Your users act in a workspace as members, each with a role:
| Role | May |
|---|---|
owner, admin | approve or reject every held action, answer the agent's questions, and read every conversation in the workspace |
member | approve or reject what their own conversation asked for, answer the agent's questions, and see only the threads they started |
- A user joins a workspace the first time your server acts for them (
OpenLegion-Subject, or a session), with the template'sdefault_subject_role,memberunless you set it. The templatenpx openlegion initwrites saysmember. - To give that user a name, send
OpenLegion-Subject-NamebesideOpenLegion-Subject: their display name, percent-encoded UTF-8 (encodeURIComponent), 1–120 characters. OpenLegion keeps it as that user's name in your organization: the agent is told it, and history and the audit trail show it. It changes only when you send a different one, on a call that changes something (aGETnever writes it), and leaving the header out keeps the name. A session's name is thedisplay_nameyou mint it with. Pass a name, never an email address. - To forget that user's name, send
OpenLegion-Subject-Name-Clear: truebesideOpenLegion-Subject(withoutOpenLegion-Subject-Name), on a call that changes something, or mint a session withdisplay_name: null. From then on, the agent isn't told a name. - A member approves or rejects an action that was asked for in a thread they started. Another person's approval answers them as one that doesn't exist (
404). - An approval from a run with no thread (a schedule's, a background run's, an inbound event's) belongs to nobody: only an owner or admin decides it.
- Give your customer's account owner the admin role (the call below), so that someone can decide those approvals and edit agents and schedules.
- Owners and admins can read every conversation in a workspace. Tell your users so if several of them share one.
- A decision with no person behind it is refused
subject_required, and one by a person who may not decide itinsufficient_role. - Another person's thread answers a member as if it didn't exist (
404 resource_missing), and so do its runs. A thread your key started without naming a person, or one a schedule or an inbound event started, belongs to nobody: only an owner, an admin and your key see it. - A member sees only the actions and approvals of runs in the threads they started; another person's answers as one that doesn't exist (
404). Owner and admin, and your key with no subject, see them all. - A person has the same power whichever way they come: a member your key names with
OpenLegion-Subjectgets the answer their session token (ols_…) gets. A member may connect an app and disconnect an account they connected. A member may also save a login or key an agent asked them for in a conversation they started (the secure form does this), creating it or adding the asked site to one they saved; never over an item someone else saved. Managing the vault and the workspace's model key, reading an agent's memory, changing which agents use a connection, and replacing or disconnecting an account someone else connected need an owner or admin; a member gets403 insufficient_role. Your key with no subject may do all of it.
Making a user an admin is one call from your server (your key needs the sessions scope). The role you last gave is the one they have:
await ol.sessions.create({ workspace, subject: yourAdmin.id, role: "admin" });
Keeping a tool's approvals for admins
export const cancelPlan = defineTool({
description: "Cancel the customer's plan at the end of the period.",
input: z.object({ reason: z.string() }),
trust: "tool_verified",
effect: "write",
requiresApproval: true,
approver: "admin",
run: async ({ reason }, ctx) => billing.cancelAtPeriodEnd(ctx.external_ref, { reason, idempotencyKey: ctx.action }),
});
approver: "admin"means only an owner or admin may approve or reject a held call of that tool. The default,"requester", lets the member whose conversation asked for it decide.- In a template spec it is
policy_envelope.tools.<tool id>.approver, besidestatus. It works for a platform tool too, and for a tool that is held for another reason, such as its cost. - It is read when a person decides, from the template version the workspace runs then. A new version that sets it covers the approvals already waiting.
- In
<AgentChat>, a member reading such an approval sees "Waiting for an admin to decide this." in place of Approve and Reject.GET /approvals/{id}says which withcan_decide.
Deciding
From your backend, when the event arrives (your key needs the approvals scope):
webhooks: {
"action.requires_approval": async (event) => {
const action = event.data.truncated
? await ol.workspace(event.workspace!).actions.retrieve(event.data.object.id!)
: event.data.object!;
if (await yourPolicySays(action)) {
await ol.workspace(event.workspace!, { subject: yourAdmin.id }).approvals.decide(event.data.approval, {
decision: "approve",
action_hash: action.action_hash,
});
}
},
},
- The approval to decide is
data.approval(apr_…), there even when the action is truncated. approval.requestedis a different thing: the agent asking a person a question, which a member may answer (decision: "answer").- Or show pending approvals in your own UI:
ws.approvals.list({ status: "pending" }). Each approval'sactionis the held action itself, an object (action.id,action.action_hash), not an id.<AgentChat>draws a held call as a card that a person may approve or reject in the chat.