Render AI tool calls as custom React components that show loading, result, and interactive states for each tool invocation in assistant-ui.
Render a tool call as your own React component, with loading, result, error, and interactive states.
What a tool UI does
A tool UI is a component that renders in the thread when the model calls a tool. It receives the call's live state as props, so it can:
- show progress while the arguments stream in and the tool runs
- display the result, or the error
- ask the user for input or a decision, and send the answer back to the run
This page covers rendering and interaction. Declaring tools, choosing where they run, and registering a toolkit are covered elsewhere:
| You want to | Go to |
|---|---|
Declare a tool and attach its render (tool kinds, "use generative", Tools() registration) | Defining Tools |
| Attach UI to a tool another system executes | Externally defined tools |
| Give the model the tool's schema on your server | Backend tools |
| Hold a tool call until the user allows it, picks an option, or answers a question | Tool approvals |
| Let the model compose UI from a vocabulary instead of one component per tool | Generative UI |
A render function only draws the tool call; it does not run the tool. Backend execute code stays on your server; see Tool kinds.
Samples on this page call helpers that are yours to implement, such as fetchWeatherAPI, ResultList, Chart, SizePicker, and taskStore.
Rendering a tool call
render
render is a React component. It re-renders as the arguments stream, the result arrives, and the status changes, and it can use hooks. Type it with ToolCallMessagePartComponent, then put it on the toolkit entry for the tool. This is the get_weather tool from the quick start, with its inline render replaced by a named WeatherToolUI:
"use generative";
import { defineToolkit } from "@assistant-ui/react";
import { z } from "zod";
import { WeatherToolUI } from "@/components/weather-tool-ui";
export default defineToolkit({
get_weather: {
description: "Get current weather for a location.",
parameters: z.object({
location: z.string().describe("City name or zip code"),
unit: z.enum(["celsius", "fahrenheit"]).default("celsius"),
}),
execute: async ({ location, unit }) => {
"use client";
return fetchWeatherAPI(location, unit);
},
display: "standalone",
render: WeatherToolUI,
},
});fetchWeatherAPI and WeatherToolUI are yours to implement; the live sample at the top of this page is a WeatherToolUI you can start from. Mount the toolkit with AuiConfig({ tools: Tools({ toolkit }) }) as described in Registering a toolkit with Tools(), and see the quick start for the full setup. Every tool you author on the client or the server takes the same render field.
To render a tool that another system defines and executes, such as a separate backend or a LangGraph node, give the entry execute: externalTool() and a render and nothing else:
web_search: { execute: externalTool(), render: SearchToolUI },An externalTool() entry carries no schema and no executor, so use it only for a tool defined elsewhere. See Externally defined tools.
The component receives these props:
| Prop | Meaning |
|---|---|
args, argsText | The arguments as an object and as raw JSON text. Both are partial while the model is still writing them. |
status | Where the call is in its lifecycle; see Tool status. |
result, isError, isPreliminary | The tool's result. While isPreliminary is set, result is an interim value and the call is not settled. isError marks an error result. |
artifact | UI-only data attached to the result. |
toolName, toolCallId | Which tool, and which call. |
addResult | Completes the call with a result you supply; see User input collection. |
interrupt, resume | A payload the tool is waiting on, and the function that answers it; see Pausing a frontend tool. |
approval, respondToApproval | A pending approval request, and the function that answers it; see Tool approvals. |
unstable_interactions, unstable_recordInteraction | What the user did in this UI, stored with the call; see Recording interactions. |
messages | Nested thread messages produced by the call, such as a sub-agent conversation; see Multi-Agent. |
The full type is ToolCallMessagePartProps; useToolArgsStatus is documented in the Tool Status reference.
renderText
For a one-line status instead of a component, give the entry renderText. Each of running and complete is a string, a React node, or a function of { args } and { args, result }:
renderText: {
running: ({ args }) => `Searching for ${args.query}…`,
complete: ({ result }) => `Found ${result?.length ?? 0} results`,
},running applies while the call is running or requires-action. complete applies in every other state, including a cancelled or failed call, so use render when you need to tell those apart. If an entry has both, render wins.
Which renderer runs
For each tool-call part, the thread picks the first match:
- The renderer registered for that tool name through
Tools({ toolkit }). If two registered toolkits render the same name, the one registered first wins. - A renderer passed to the deprecated
components.tools.by_nameprop. - The generic MCP app renderer, for a call whose
mcp.app.resourceUriis aui://app. - The fallback; see Tool fallback.
Tool Resolution covers the same order from the primitive's side, including part.toolUI in the children API.
Inline or standalone
display decides whether the call folds into the collapsed tool group or stands on its own in the thread. A tool UI is "inline" by default, so consecutive calls collapse behind a tool group. Set display: "standalone" for UI that asks the user for something or that the user should not have to open. Human tools are standalone unless they set display: "inline", and MCP app calls are standalone too.
Status and streaming
Tool status
status is derived from the message and the result, so a renderer branches on it directly:
status.type | Meaning |
|---|---|
running | The arguments are streaming or the tool is executing. Also while an interim isPreliminary result is showing. |
requires-action | The call is waiting for the user: a human tool's result, a paused human(), or an open approval. status.reason is "tool-calls" or "interrupt". |
complete | A final result arrived, including an error result. A call with no result takes the status of its message, so it is also complete when the message completed without ever returning one. |
incomplete | The run ended before a result arrived. status.reason is "cancelled", "tool-calls", "error", "length", "content-filter", or "other", and status.error can carry detail. LocalRuntime sets "tool-calls" when its maxSteps limit stops a run that still has tool calls to follow. |
A call fails in one of two ways. A tool whose execute throws completes with isError set and the error as its result. A run that fails before the tool returns leaves the call incomplete. Handle both in the same renderer; see Tool failure for a ready-made card.
const SearchToolUI: ToolCallMessagePartComponent<
{ query: string },
{ results: SearchResult[] }
> = ({ args, status, result, isError }) => {
if (status.type === "incomplete") {
return <p>{status.reason === "cancelled" ? "Cancelled" : "Failed"}</p>;
}
if (status.type !== "complete" || !result) {
return <p>Searching for {args.query}…</p>;
}
if (isError) return <p>Search failed</p>;
return <ResultList results={result.results} />;
};Field-level streaming state
args fills in as the model writes it. Use useToolArgsStatus to tell a field that is still being written from one that is final. The hook returns a propStatus map where each top-level key resolves from "streaming" to "complete" as the partial JSON arrives, and argsStatus tracks the whole object. Call it inside a tool-call renderer:
import {
useToolArgsStatus,
type ToolCallMessagePartComponent,
} from "@assistant-ui/react";
type FormArgs = { email: string; phone: string };
export const SubmitFormToolUI: ToolCallMessagePartComponent<FormArgs> = ({
args,
}) => {
const { argsStatus, propStatus } = useToolArgsStatus<FormArgs>();
return (
<form aria-busy={argsStatus === "streaming"}>
<input
type="email"
value={args.email ?? ""}
data-streaming={propStatus.email === "streaming"}
disabled
/>
<input
type="tel"
value={args.phone ?? ""}
data-streaming={propStatus.phone === "streaming"}
disabled
/>
</form>
);
};argsStatus stays "streaming" while the object is partial, even when every field received so far is complete, and becomes "complete" once the object is. That can happen while status is still "running" because the tool is executing. A field missing from propStatus is not in the current args: while argsStatus is "streaming" it may still arrive, and once argsStatus is "complete" it was never sent.
The hook uses parser metadata when the runtime provides it. The AI SDK marks settled tool arguments complete even while execution continues, so received fields become "complete" at that point too. Without parser metadata, a running part stays conservatively "streaming", because some runtimes build argsText from an incomplete snapshot, and any non-running lifecycle settles argument streaming. "complete" does not guarantee valid arguments or a successful result.
Interim results
A tool can send interim results before its final one, such as an AI SDK execute that yields. While isPreliminary is set, status stays "running" and result holds the latest interim value:
const AnalysisToolUI: ToolCallMessagePartComponent<
{ dataset: string },
{ progress: number; insights: string[] }
> = ({ result, status }) => (
<div>
{status.type === "running" && <progress value={result?.progress ?? 0} max={100} />}
<ul>
{(result?.insights ?? []).map((insight) => (
<li key={insight}>{insight}</li>
))}
</ul>
</div>
);Deferred rendering
Partial args can render a misleading or jarring intermediate state: a chart flashing through half-populated data, an expensive widget mounting repeatedly, or an iframe reloading. To render only once the call is settled, return null until then. The streaming args still arrive in args; the renderer ignores them.
export const ChartToolUI: ToolCallMessagePartComponent<ChartArgs> = ({
args,
status,
}) => {
if (status.type !== "complete") return null;
return <Chart title={args.title} data={args.series} />;
};The chart mounts once, with its final args. status becomes "complete" when the result arrives, not when the arguments finish, so a tool with a slow execute shows its UI after the tool returns. To mount as soon as the arguments are final, gate on argsStatus instead. argsStatus is also "complete" when a run stops mid-call, so exclude "incomplete":
const { argsStatus, status } = useToolArgsStatus<ChartArgs>();
if (argsStatus !== "complete" || status === "incomplete") return null;This applies when the model drives the component through a tool call. When your backend pushes the component instead, Data-part generative UI renders once with final data and needs no deferral.
To place the component outside the message parts, such as a card under the avatar block, gate it at the message level with AuiIf as in Render After Stream Completes, and read the tool-call part from s.message.parts:
function PostMessageCard() {
const parts = useAuiState((s) => s.message.parts);
const chartCall = parts.find(
(p) => p.type === "tool-call" && p.toolName === "renderChart",
);
if (chartCall?.type !== "tool-call") return null;
return <Chart {...chartCall.args} />;
}To show partial data as it streams instead, use Field-level streaming state and Interim results.
Renderers that need props or state
A toolkit renderer is a component with a stable identity, so it cannot read props or state from the component that mounts the toolkit, and passing a new function on every render would remount the UI. When the renderer has to read them, build the toolkit in a hook and wrap the renderer in useInlineRender. It returns a component whose identity never changes and that always calls the latest function you passed. A toolkit built at render time cannot be a "use generative" file, so it uses the plain type: "backend" entry shape:
"use client";
import { defineToolkit, useInlineRender } from "@assistant-ui/react";
import { useMemo } from "react";
export function useInventoryToolkit(productId: string, productName: string) {
const renderInventory = useInlineRender<unknown, { quantity: number }>(
({ result }) => (
<div>
<h4>{productName} inventory</h4>
<p>
Stock for {productId}: {result?.quantity ?? "…"} units
</p>
</div>
),
);
return useMemo(
() =>
defineToolkit({
checkInventory: { type: "backend", render: renderInventory },
}),
[renderInventory],
);
}Mount it below the component that owns the state. ProductDetails is your own component:
import { AuiConfig, AuiProvider, Tools, useAui } from "@assistant-ui/react";
import { useInventoryToolkit } from "./inventory-toolkit";
function ProductPage({
productId,
productName,
}: {
productId: string;
productName: string;
}) {
const toolkit = useInventoryToolkit(productId, productName);
const aui = useAui();
const config = AuiConfig({ tools: Tools({ toolkit }) });
return (
<AuiProvider extends={aui} config={config}>
<ProductDetails />
</AuiProvider>
);
}Human-in-the-loop
Three mechanisms let a tool UI send something back to the run. They differ in where the pause lives:
| Mechanism | The pause | The renderer answers with | Declared by |
|---|---|---|---|
| Human tool | The tool has no executor; the UI supplies the whole result | addResult(result) | execute: humanTool(); see Human tools |
| Interrupt | A frontend execute awaits human(payload) | resume(value), which human() returns to execute | A frontend tool calling human() |
| Approval gate | The runtime holds a tool call until the user decides | respondToApproval(...) | The runtime or server, such as AI SDK toolApproval; not the toolkit. See Tool approvals |
Use addResult when the user supplies the answer, resume when code is waiting to continue, and respondToApproval when the user allows or blocks an action the server performs.
On the AI SDK runtime, the assistant continues after addResult or resume only when the client posts the result back, and sendAutomaticallyWhen decides that. Its default is never, so set sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls on useChatRuntime; see Multi-step tool calls. Approvals use a different predicate, described under Server-side approval gates.
A thread that cannot take an answer should show the request without its controls. s.thread.capabilities.answerToolCall is false in a readonly thread, such as a sub-agent transcript or a conversation rendered through ReadonlyThreadProvider, where addResult, resume, and respondToApproval do nothing. It is also false on an external store that has no onAddToolResult, onResumeToolCall, or onRespondToToolApproval, and no tool execution of its own. ToolFallback already checks it:
const canAnswer = useAuiState((s) => s.thread.capabilities.answerToolCall);User input collection
A human tool has no executor. Its renderer collects the input and passes it to addResult, which completes the call, and the assistant continues with the data you passed once the runtime sends the result back (see the sendAutomaticallyWhen note above). Call it once. This renderer comes from the with-generative-ui example. Register it with execute: humanTool(); see Human tools for the entry:
"use client";
import { useState } from "react";
import type { ToolCallMessagePartComponent } from "@assistant-ui/react";
export const DatePickerToolUI: ToolCallMessagePartComponent<
{ prompt: string; minDate?: string; maxDate?: string },
{ date: string }
> = function DatePickerToolUI({ args, result, addResult }) {
const [value, setValue] = useState("");
if (result) {
return (
<p>
Selected{" "}
{new Date(result.date).toLocaleDateString(undefined, { timeZone: "UTC" })}
</p>
);
}
return (
<div>
<p>{args.prompt}</p>
<input
type="date"
value={value}
min={args.minDate}
max={args.maxDate}
onChange={(e) => setValue(e.target.value)}
/>
<button
type="button"
disabled={!value}
onClick={() => addResult({ date: new Date(value).toISOString() })}
>
Confirm
</button>
</div>
);
};Branching on result turns the control into a record once the user answers, so scrolling back never shows a live control for a decision already made. To report a declined request as an error result, pass addResult a ToolResponse from assistant-stream with isError: true.
Option list, Question flow, and Reviewable diff are ready-made human-tool renderers. For LocalRuntime, a human tool also has to be listed in unstable_humanToolNames; see Human-in-the-loop tools.
Pausing a frontend tool
A frontend tool can pause during execute and wait for the user. execute calls human() with a payload; the renderer receives it as interrupt.payload, and the value passed to resume() becomes the return value of human(). While the call waits, status is requires-action.
execute: async (_args, { human }) => {
"use client";
const confirmed =
(await human({ message: "Clear all completed tasks?" })) === true;
return { cleared: confirmed ? taskStore.clearCompleted() : 0 };
},export const ClearCompletedToolUI: ToolCallMessagePartComponent<
Record<string, never>,
{ cleared: number }
> = ({ result, interrupt, resume }) => {
if (result) return <p>Cleared {result.cleared} completed tasks.</p>;
if (interrupt) {
const { message } = interrupt.payload as { message: string };
return (
<div>
<p>{message}</p>
<button onClick={() => resume(true)}>Clear</button>
<button onClick={() => resume(false)}>Keep</button>
</div>
);
}
return <p>Working…</p>;
};The with-webmcp example registers this entry with display: "standalone", so the prompt is not hidden inside a collapsed group. The execute context also carries abortSignal and toolCallId; see Cancellation. Unlike a human tool, execute still returns the result.
Approvals
In an approval gate, the runtime or server holds a tool call until the user allows or denies it. The request arrives on the tool part as approval, and the renderer answers it with respondToApproval. A request can also offer decision options, such as "allow for this session", or ask a question the user answers by picking or typing. Tool approvals covers the states of a request, decision options, questions, and which runtimes emit each field.
Recording interactions
A tool UI can record what the user did in it, so a stored conversation keeps the answer next to the question. Call unstable_recordInteraction with the action the user took. The runtime stamps the time and appends it to the call's unstable_interactions, which cloud history stores with the message.
export const SizePickerToolUI: ToolCallMessagePartComponent<
{ sizes: string[] },
{ size: string }
> = ({ args, addResult, unstable_recordInteraction }) => (
<SizePicker
sizes={args.sizes}
onPick={(size) => {
void unstable_recordInteraction?.({
type: "human-response",
payload: { size },
}).catch(() => {});
addResult({ size });
}}
/>
);Some interactions are recorded for you. The answer passed to resume() is recorded as a human-response once the runtime accepts it. Every action that present or prompt_user output of @assistant-ui/generative-ui dispatches to its action registry is recorded as an action, and the state a user changes in a render_spec call from generative-frame/spec/assistant-ui is recorded as a setState action so it comes back after a reload.
unstable_recordInteraction and unstable_interactions are experimental and may change in any release. Recording is best effort. A payload must be plain JSON of at most 16,384 characters, and an action payload must be a JSON object. A tool call keeps its latest 32 entries within 65,536 characters; earlier ones are counted in omitted. The promise rejects when a runtime cannot record or a payload is invalid, so catch it as the example does. A failed recording never affects the user's action. The local runtime and the AI SDK, AG-UI, and A2A runtimes record interactions. Runtimes built on useExternalStoreRuntime under a cloud thread list, such as LangGraph, LangChain, and ADK, keep them on the cloud copy of the conversation, which is on unless the AssistantCloud client sets telemetry: { messages: false } or telemetry: false; their own messages do not carry them. A readonly thread ignores them. Interactions are never sent to the model or the agent on their own; a toolkit can still add what a UI shares on purpose to the model context, as generative-frame's does.
Tool fallback
A tool call with no registered renderer renders through the fallback. In the kit's Thread that is ToolFallback: a collapsed one-line summary that opens into the arguments, the result, and, when the call is waiting on a decision, the controls to answer it. It handles every approval shape in Tool approvals, including options, questions, and the receipt of a settled request. A registered renderer always takes precedence over it.
To replace it for every unregistered tool, pass components.ToolFallback to Thread. With the MessagePrimitive.Parts children API, part.toolUI is the registered renderer, or null when none matches:
<MessagePrimitive.Parts>
{({ part }) => {
if (part.type === "tool-call")
return part.toolUI ?? <ToolFallback {...part} />;
return null;
}}
</MessagePrimitive.Parts>See Tool fallback for install and restyling, Tool group for collapsing consecutive calls, and Tool call for a one-line renderer to start from.
Data-part generative UI
Besides tool calls, a backend can attach UI to a message as a named data part: { type: "data", name, data }. You register a renderer for a name with makeAssistantDataUI and mount the returned component once inside AssistantRuntimeProvider.
Choose by who decides what renders:
- Tool UI (this page): the model decides by calling a tool, and its args become the component's data. Args stream, so you use
status,useToolArgsStatus, and Deferred rendering. - Data UI: your backend or orchestrator decides and pushes a data part. A data part arrives as one terminal event with no partials, so the renderer runs once with the final data.
The LangGraph adapter produces data parts from push_ui_message and typedUi().push(). LangGraph Generative UI covers emitting, registering renderers with makeAssistantDataUI, and the data-part shape. In the children API, part.dataRendererUI is the registered data renderer; see Tool Resolution.
Designing for the conversation
A tool UI shares the transcript with the assistant's prose and the user's replies, so it is designed against the conversation rather than as a standalone screen.
Give each tool UI one job
A tool UI either informs (a table, a chart, a link card), asks for a decision (an approval, an option list), adjusts something reversible (a filter, a parameter), or reports work in flight (a plan, a progress bar). When one surface does two of these, let one lead: a table with row actions is information first, and its actions stay secondary.
Fit the chat column
Messages are narrow and interleaved with text. State the purpose in the first 300px of height, design for 400 to 600px of width in a single column, give every control at least a 44px touch target, and show five to seven options at most, leaving the rest to a follow-up. The elements are sized to this column already (max-w-sm or max-w-md); keep a custom tool UI to the same widths.
Keep what the user acts on addressable
The model can only refer back to what it can name. Give the options, rows, and items a tool UI renders stable ids from your data, not array positions or ids minted at render time, and send those ids back through addResult. Then "the second option" and "row 4" in the next turn resolve to the same records the user saw.
Leave a receipt
Once a user decides, the interactive surface should become a record of the decision, so scrolling back never shows a live control for a choice already made. Render the receipt from the tool call itself: result for a human tool, approval for an approval gate, and unstable_interactions for recorded actions. The kit follows this everywhere: ToolFallback replaces settled approval controls with a receipt, OptionList takes the committed answer as choice, and an answered generative prompt_user locks its controls.
Write the decision in the past tense and the request in the imperative, so the receipt reads as what happened to what was asked: "Denied · Delete all project files", "Answered · Staging". Skip receipts for reversible controls such as sorting or filtering; nothing was decided there.
Split the work with the message
The assistant's text introduces the tool UI and the tool UI carries the structure, so neither repeats the other: when the message asks "Which environment?", the option list shows only the environments. Avoid text inputs inside a tool UI when the answer could be typed into the composer, avoid tabs or navigation inside one surface (split it into separate tool calls instead), and never let an action change state silently; show its outcome.
Related guides
- Defining Tools: declare tools, choose where they run, and register a toolkit
- Backend tools: expose the toolkit's schemas to the model on your server
- Tool approvals: approval gates, decision options, and questions
- Generative UI: let the model compose UI from a vocabulary
- Multi-Agent: render sub-agent conversations inside tool call UIs
- Tool fallback: the default UI for tools without a registered renderer
- Message primitive: how tool-call parts resolve to renderers
- Tool Status reference and Rendering reference: type definitions