Tool Calls and Approvals
Show each tool call an AI SDK agent makes, and ask a person to approve the risky ones before they run.
To show an AI agent's tool calls and ask for approval in React, render each tool part as a Tool, and mark the tools that need a person with needsApproval: true on the server. fromUIMessages turns every AI SDK tool part into a step with a call, which the Tool shows with its input, output and status. When a call waits for approval, the Tool shows a Confirmation with Approve and Deny; pass the decision back with toApprovalResponse and useChat's addToolApprovalResponse, and the chat continues on its own.
The samples use React. The same components ship for Vue, Svelte and Solid, with the same parts and props spelled the way each framework expects, so the page translates component for component: add <name>-vue, <name>-svelte or <name>-solid in place of each item below, as Choose a Framework shows. fromUIMessages and toApprovalResponse don't depend on a framework, so they map the messages of the AI SDK's @ai-sdk/vue and @ai-sdk/svelte chats too.
Installation
Set up the @kind-ui registry as Get Started shows, then add the components, the AI SDK and Zod for the tool schemas:
npx shadcn@latest add @kind-ui/conversation @kind-ui/message @kind-ui/markdown @kind-ui/composer @kind-ui/tool
npm install ai @ai-sdk/react zodThe Server Route
get_weather runs on its own. delete_branch has needsApproval: true, so the model's call stops and waits for a person's decision before execute runs.
import { convertToModelMessages, stepCountIs, streamText, tool, type UIMessage } from "ai";
import { z } from "zod";
const tools = {
get_weather: tool({
description: "Get the weather in a city",
inputSchema: z.object({ city: z.string() }),
execute: async ({ city }) => ({ city, temperature: 18, sky: "cloudy" }),
}),
delete_branch: tool({
description: "Delete a git branch",
inputSchema: z.object({ branch: z.string() }),
needsApproval: true,
execute: async ({ branch }) => ({ deleted: branch }),
}),
};
export async function POST(request: Request) {
const { messages }: { messages: UIMessage[] } = await request.json();
const result = streamText({
model: "openai/gpt-5",
messages: await convertToModelMessages(messages, { tools }),
tools,
stopWhen: stepCountIs(5),
});
return result.toUIMessageStreamResponse();
}The Chat Page
"use client";
import { useChat } from "@ai-sdk/react";
import type { Part } from "@kind-ui/agent-ui";
import { fromUIMessages, toApprovalResponse } from "@kind-ui/agent-ui/adapters/ai-sdk";
import { lastAssistantMessageIsCompleteWithApprovalResponses } from "ai";
import { Composer, ComposerInput, ComposerStop, ComposerSubmit } from "@/components/ui/composer";
import {
Conversation,
ConversationContent,
ConversationJump,
ConversationRow,
ConversationViewport,
} from "@/components/ui/conversation";
import { Markdown } from "@/components/ui/markdown";
import { Message, MessageContent } from "@/components/ui/message";
import { Tool } from "@/components/ui/tool";
export default function Chat() {
const { messages, status, error, sendMessage, stop, addToolApprovalResponse } = useChat({
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses,
});
const rendered = fromUIMessages(messages, { status, error });
const renderPart = (part: Part) => {
if (part.type === "text") {
return <Markdown key={part.id} source={part.text} streaming={part.state === "streaming"} />;
}
if (part.type === "step" && part.step.kind === "tool") {
const { call, error } = part.step;
const approval = call.approval;
return (
<Tool
key={part.id}
call={call}
error={error}
approvalReason
onApprove={() => approval && addToolApprovalResponse(toApprovalResponse(approval, { approved: true }))}
onDeny={({ reason }) =>
approval && addToolApprovalResponse(toApprovalResponse(approval, { approved: false, reason }))
}
/>
);
}
return null;
};
return (
<main className="mx-auto flex h-dvh max-w-2xl flex-col gap-4 p-4">
<Conversation aria-label="Chat" messageCount={rendered.length} className="min-h-0 flex-1">
<ConversationViewport>
<ConversationContent>
{rendered.map((message, index) => (
<ConversationRow key={message.id} value={message.id} index={index}>
<Message
aria-label={message.role === "user" ? "Your message" : "Assistant message"}
messageRole={message.role}
status={message.status}
>
<MessageContent>{message.parts.map(renderPart)}</MessageContent>
</Message>
</ConversationRow>
))}
</ConversationContent>
</ConversationViewport>
<ConversationJump />
</Conversation>
<Composer aria-label="Message" onSubmit={(draft) => sendMessage({ text: draft.text })} onStop={stop}>
<ComposerInput aria-label="Prompt" placeholder="Ask anything" />
<ComposerSubmit />
<ComposerStop />
</Composer>
</main>
);
}How It Works
- Tool calls: each tool part becomes a part of type
stepwhosestep.kindis"tool". Pass itscallanderrorto the Tool and key it by the part's id, so updates to one call never reset another. The Tool shows the input as it streams, then the output, and closes into its header when the call completes. - Status: the Tool reads its status from the call:
running,awaiting-inputwhile it waits for approval,complete,error, orcancelledwhen it was denied. - Approval:
onApproveandonDenyshow Approve and Deny.approvalReasonmakes a person's first Deny open a box for the reason, whichonDenygets and sends with the denial.toApprovalResponse(approval, decision)builds the argumentaddToolApprovalResponsetakes. - Continuing:
sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponsessends the chat back to the server once every waiting call has a decision, so an approved call runs and the model answers. - Outcome: once the decision is recorded, the buttons give way to the outcome, like "Approved", so the conversation keeps what was decided.
Screen readers hear the tool's name and its outcome, like "delete_branch complete", and the decision, like "Approved". An agent connected with createAgent finds the confirmation by its name, like "Run delete_branch?", and can approve or deny it, but every decision waits for a person to confirm unless your allow lets it through.
Next Steps
- Show the model's reasoning and plan beside its tool calls: Reasoning and Agent Steps.
- Ask before an action that isn't a tool call with a standalone Confirmation, or ask the person a question with Question.
- Let people choose how much the agent may do on its own with Approval Mode.