Tulip Logo IconTulip
Concepts

Approvals

Let a person approve a tool call, in the chat or later, from a notification.

A tool that is asked first waits for an approval before it runs. Whether it asks follows the tool's confirmation and the workspace's setting for the agent (see Agents).

There are two places to approve, depending on whether someone is watching:

  • In the chat. The user is there: the call shows as an approval card in the response, with "once" or "for this chat". See Chat.
  • Outside the chat. Nobody is watching a background run, so the run pauses, the approvers get a notification, and the run continues once they decided, even the next day.

How a run waits

When a run outside the chat calls a tool that asks first:

  1. The run stops with status waiting and keeps its conversation, so it can continue where it stopped.
  2. Every call that waits gets an approval: the tool, its input, who may decide, whether it needs a passkey, and when it expires.
  3. approvals.notify(approval) tells the approvers, for example with a notification that links to an approval page.
  4. An approver decides with agents.approvals.decide.
  5. Once every approval of the run is decided, the run continues through enqueueRun, or right away without it. Approved calls run; the agent is told about denied ones.

agents.stream cannot wait: it throws for an agent with a tool that asks first. Start such agents with agents.run or agents.start.

Who decides

  • A run for a user: that user.
  • A run of an agent as itself: the users its identity.approvers(run) returns. Without approvers the run fails instead of waiting forever.

Only approvers can read and decide an approval, and each approval is decided once.

Decide

// The approvals a user may decide, a page at a time
const [approvals, total] = await Promise.all([
  agents.approvals.list(user.id, { status: ["pending"], limit: 20, offset: 0 }),
  agents.approvals.count(user.id, { status: ["pending"] }),
]);

// One approval, or null when the user is not an approver
const approval = await agents.approvals.get(user.id, approvalId);

// Approve or deny; continues the run when it was the last one
await agents.approvals.decide({ user, id: approvalId, approved: true, reason, proof });

An approval has agent, tool, input, confirmation, approverIds, status (pending, approved, denied, expired), reason, decidedBy, decidedAt, expiresAt and createdAt. get, list and approvals.notify add agentTitle and toolTitle: the titles people see.

Passkeys

A tool with confirmation: "passkey" is only approved with a proof verifyProof accepts. The proof is bound to the AI SDK's approval id, in the chat and outside it:

verifyProof: async ({ method, user, approvalId, toolName, proof }) => {
  // Check a WebAuthn assertion for a challenge issued for this user and approval id.
},

Issue the challenge only for an approval the user may decide: in the chat when the chat waits on it (chat.waitsFor), outside the chat when agents.approvals.get returns it as pending.

Expiry

An approval expires after approvals.expiresIn (a day by default). Call agents.approvals.expire() from a scheduled job: it expires the approvals nobody decided in time and fails their runs. An expired approval cannot be decided.

Guidance

  • Link the notification to one approval page, and keep an overview of open and decided approvals.
  • Show what will happen: the agent, the tool's title and its input.
  • Keep tools that change data idempotent where you can: a person may decide a day later, when the data has changed.

On this page