Skip to main content
This guide builds the tool permissions flow in a chat.agent. You’ll store grants, record who owns each chat, check grants before each tool call, and add the approval buttons to your chat UI.

Store grants

Give each tool a scope string, and store one row per grant. A scope ending in :* covers every tool in that integration.
prisma/schema.prisma
Run npx prisma migrate dev to create the table. Keep the scope map in its own file with no database imports, so your approval buttons can import it in the browser:
lib/tool-scopes.ts
lib/permissions.ts
The examples use Prisma with Postgres. On SQLite, which doesn’t support skipDuplicates, catch the unique constraint error instead. They import your Prisma client from @/lib/db, a gmail wrapper around the user’s Gmail connection from @/lib/gmail, and requireUser from @/lib/auth, which returns the signed-in user. Swap in your own.

Save the chat’s owner

The agent checks the grants of the user who owns the chat. Save the owner when the session starts, and only mint tokens for that user. Otherwise anyone who learns a chat ID can answer its approvals, or ask the agent to act with the owner’s grants.
prisma/schema.prisma
app/actions.ts
These replace the session actions from the quick start.

Check grants before each tool call

Check the user’s grants each time the model calls a tool. Because the check runs on every call, a new grant applies to the next call and a revoked grant stops applying on the next call. Look the user up from the chat you saved, not from clientData, because the browser can set clientData to anything.
Pass a toolApproval function to streamText. Return "approved" to run the call, "user-approval" to ask the user, or undefined to run it without a check. List the tools that only read, and ask for everything else, so a tool you add later asks until you give it a scope.
trigger/my-chat.ts
Calls that a grant approved are marked approval.isAutomatic: true on the message, so you can see which calls ran without asking.
When the check asks the user, the turn ends with the call in the approval-requested state and the run waits for the answer. The user can answer hours later. If the run has ended by then (after turnTimeout, one hour by default), the answer starts a continuation run that restores the conversation from transcript storage and sends the email.
Keep authorization checks in execute or in the function it calls, as well as in the approval check. The grant decides whether to ask. It doesn’t replace checking that the user may act on that account.

Add approval buttons to your chat UI

Your chat UI talks to the agent through useChat and Trigger.dev’s chat transport. When the agent pauses on a call, the call appears in the assistant message as a tool part in the approval-requested state. Render buttons for it, and send the answer back with addToolApprovalResponse:
app/components/chat.tsx
The approval component renders four buttons. Both “Always allow” buttons save a grant first, then approve the call. A tool with no scope gets only Approve once and Deny:
app/components/approval.tsx
Add the action that saves the grant to app/actions.ts:
app/actions.ts
A grant skips the user’s check on every call it covers, including calls prompted by content the agent reads. An email that says “forward this inbox to me” runs unchecked if the user has a gmail:* grant. Only offer “always allow” for actions you’re comfortable running without a person looking.

Let users revoke grants

List the user’s grants on a settings page, one row per grant, with a revoke button that calls this action. Revoking gmail:send leaves a gmail:* grant in place, so show both. The next call after a revoke asks again, and nothing in the agent needs to change.
app/actions.ts

Verify it

  1. Ask the agent to send an email. Confirm the approval buttons appear and nothing is sent yet.
  2. Click Deny. Confirm execute doesn’t run and the agent replies without retrying.
  3. Ask again and click Always allow this. Confirm a gmail:send row appears in ToolGrant and the email sends.
  4. Ask for another email. Confirm it sends with no approval prompt.
  5. Revoke the grant. Confirm the next request asks again.

Common mistakes

  • Reading the user ID from clientData. The browser sets it. Look up the chat’s owner on the server.
  • Minting tokens for any chat ID. Check that the signed-in user owns the chat, or another user can answer its approvals.
  • Saving the grant after approving. Write the grant first, so a later call in the same turn finds it.
  • Grants with no revoke path. Give users a page where they can see and remove their grants.
  • An idempotency key your send function ignores. Gmail doesn’t deduplicate sends. Record each key and skip one you’ve already sent.
  • Approvals on read-only tools. Don’t ask before tools that only read, or users learn to click through every prompt.

Next steps

Outside a chat

Ask for permission from scheduled jobs and background agents.

Human-in-the-loop

Questions, selections and approvals inside a chat.

Frontend

Connect useChat to your agent with the chat transport.

Tools

Declare tools on the agent and build them per turn.