An Allow button in the chat will not stop a bad refund
assistant-ui ships a ready-made tool approval card for your client's users, but permissions, signatures and the audit trail remain your job.
In brief
- The default ToolFallback card already has Allow and Deny buttons, so a tool approval demo needs no UI code.
- Configuration varies by version: the official recipe uses needsApproval, while the AI SDK v7 page uses toolApproval at the call level.
- In the standard useChat model the client controls the chat history, so the server must recheck permissions and the approval request's signature.
The tool approval recipe in the assistant-ui documentation builds a customer support agent that looks up orders by itself but stops before issuing a refund. The chat shows the refund the agent wants to make, with two buttons: Allow and Deny. None of this takes a single extra line of UI code.
For an FDE, that means a client can see an early demo of an agent that must ask permission before it acts. But the easier the button is to build, the easier it is to mistake for a layer of protection. The hard part lies behind it: who may approve, what the server trusts and where the decision is stored.
Use it when the client wants to see what the agent is doing
assistant-ui is a TypeScript/React library under the MIT license. It provides the thread and composer as editable components, along with a runtime that handles streaming, tool calls, attachments and conversation history.
Consider it when the client already has a React frontend and operators need to follow each step the agent takes. A tool UI is a component that appears directly in the thread when the model calls a tool. Its status prop reports the tool’s current state, and each state should answer a different question for the user:
status |
What the user is asking | What to show |
|---|---|---|
running |
What is it doing? | Name of the operation and order ID |
requires-action |
What is waiting for approval? | Amount, recipient, consequences |
incomplete |
Why did it stop? | Canceled or failed, and the next step |
complete |
What was the result? | Result and reference number |
Your first task on site is to sit down with the person who will click the button and fill in the last column in their words. A card that shows only a function name and JSON trains them to click Allow out of habit.
Two tools, one stopping point
Two tools are enough to show where the stopping point belongs. Looking up an order only reads data, so it runs straight through. A refund changes data and is hard to reverse, so it has to wait.
The skeleton below follows the needsApproval recipe and keeps only the parts that determine behavior. Take the descriptions and input schemas from the documentation for the version you have installed:
// Abridged skeleton, not runnable code yet
// user: taken from the login session the server has authenticated
const makeTools = (user) => ({
lookupOrder: {
execute: async ({ orderId }) => findOrder(user, orderId),
},
refundOrder: {
needsApproval: true,
execute: async ({ orderId, amount }) => {
await assertCanRefund(user, orderId, amount); // a function you write yourself
return refund(orderId, amount);
},
},
});
With needsApproval: true, the refund tool runs only after the user allows it. The default ToolFallback card takes care of the display. You should add your own assertCanRefund to recheck the signed-in user’s permissions and the amount immediately before execution.
user is passed in from the login session on every request. Keep it out of tool parameters and chat messages; otherwise the model or the client can claim to be anyone.
Say an order is worth $80 and the agent proposes refunding $800. Someone clicking in a hurry will still wave the card through, but a comparison on the server will block it. In the demo, run this case in front of the client, then click Deny on another so they can see the order stay unchanged.
There is a version trap. The integration page for AI SDK v7, which requires ai@^7.0.101 and @ai-sdk/react@^4, uses a toolApproval option at the call level. The server pauses, emits an approval-requested part, then resumes when the client sends its response.
The skeleton above therefore cannot be copied straight into v7: the stopping point has to be declared in the model call. The check inside execute should stay in both approaches. Look at the client’s package.json before copying any sample.
Should the server trust that click?
The Vercel AI SDK documentation warns that in the standard useChat model, the server rebuilds the conversation from messages sent by the client. The chat history is therefore client-controlled data. Without further checks, a forged or altered approval can slip into it.
The AI SDK has an experimental_toolApprovalSecret option that signs approval requests, blocking forged or altered approvals before the tool runs. The v7 skeleton below puts the stopping point and the signing key side by side, in the same server-side model call:
// Abridged skeleton for v7; check the documentation before use
streamText({
model,
messages, // rebuilt from data sent by the client
tools: makeTools(user), // remove needsApproval from refundOrder
toolApproval: refundPolicy, // you declare: refundOrder must wait for approval
experimental_toolApprovalSecret: process.env.APPROVAL_SECRET,
});
refundPolicy is a placeholder name; take the correct syntax from the documentation for your installed version. The signing key should live only in a server environment variable. The experimental_ prefix is a reminder to check again at every upgrade.
The signature protects the integrity of the request; the business permissions of the person clicking still need a separate check.
The assistant-ui documentation draws the same boundary: the render function only draws the tool call, while sensitive logic belongs in the execute of the backend tool. That code runs on the server and is never sent to the browser. In code review, check whether the refund conditions are sitting in a React component.
Forge an approval before someone else does
Run this test in a test environment, with fake data. Use the v7 skeleton with experimental_toolApprovalSecret set, let the agent stop at the refund step, then click Allow and copy the request the browser sends from the Network tab. In that request’s message history, find the refund tool call and the approval attached to it.
Resend it with an API client in three variants, using a new order each time. The first inserts an approval request the server never issued, already marked as approved. The second keeps a genuine request but changes the amount from 80 to 800 after approval.
The last leaves the genuine request for a valid order intact, but sends it from the session of someone without approval rights. A signature cannot say whether the sender is authorized, so assertCanRefund has to block this case, based on that session’s user.
The expected result: the first two variants are blocked before execute, while the third enters execute but stops before the refund call. The order is unchanged in all three cases. Errors may surface differently from version to version, so put logs at the start of execute and immediately before refund rather than relying on the response code.
Then remove the signing key line and rerun the first two variants. If the logs look the same, your test has not touched the signing mechanism; the request may have failed for another reason.
What the library leaves to you
If you write your own approval card, call respondToApproval only while approval.approved is still undefined. await the call before locking the button: if the system refuses to record the answer, the user can still click again. Make the call fail deliberately once and see whether the button still works.
Storage is also yours. With approval options, assistant-ui does not store the decision and does not answer later approvals automatically. An “always allow” choice therefore needs a place to be stored, a scope, an expiry and a means of revocation in the client’s system.
Agree a minimum record with the client before go-live: who approved, when, which tool, the parameters at the time of approval and the execution result. Without the parameters, nobody will later know what figure the approver agreed to.
Start with a narrow workflow
The November 2025 Thoughtworks Technology Radar put assistant-ui in the Assess ring, after its team built a simple chat interface and was pleased with the result. A simple interface proves nothing about a multi-level approval process. Learn status first, then the default card, and write your own card only once all three variants above are blocked.
Put that test in your portfolio, along with the logs from the three variants. When an interviewer asks about human-in-the-loop, you can open the logs and point to the line where the refund was blocked.
At the demo, the client will look at the Allow button. Their security lead will ask what happens when someone sends the command without clicking it, and you should have the test ready to answer.
Was this article useful?
Thanks for the feedback!
9 sources
- assistant-ui documentation
- GitHub - assistant-ui/assistant-ui: Typescript/React Library for AI Chat 💬🚀
- assistant-ui LICENSE
- Tool UI · assistant-ui
- Ask before running a tool · assistant-ui
- AI SDK v7 · assistant-ui
- Tool Approvals (AI SDK)
- assistant-ui | Technology Radar | Thoughtworks · 2025-11-05
- assistant-ui Pricing