affectUI › Components › Agents
Tool Call Card
An agent's tool call in one line – live timer, status and summary, folds open to highlighted arguments and result with copy, retry on errors and a group that sums them up.
Free and open source (MIT). Install: npx shadcn@latest add https://www.affectui.com/r/tool-call-card.json · Import from @/components/ui/tool-call-card
When to use
- Tool and function calls in an agent chat or run log – what was called, with what, and what came back
- Agents that call several tools per turn – wrap them in ToolCallGroup so the answer isn't buried under cards
- Developer-facing views where people need to copy the exact arguments or result to debug
When not to use
- Plain reasoning with no tool calls – use Thinking State or Thinking Loader
- End users who never care about JSON – show a one-line status instead and keep the details in a log
- Huge payloads (megabytes of JSON) – trim or paginate them first; the card renders the whole string
Usage
import { ToolCallCard, ToolCallGroup } from "@/components/ui/tool-call-card";
export function ToolCalls({ calls }: { calls: ToolCall[] }) {
return (
<ToolCallGroup>
{calls.map((call) => (
<ToolCallCard
key={call.id}
name={call.name}
summary={call.summary}
status={call.status}
args={call.args}
result={call.result}
error={call.error}
startedAt={call.startedAt}
duration={call.durationMs}
onRetry={() => retryToolCall(call.id)}
/>
))}
</ToolCallGroup>
);
}Props
| Name | Type | Default | Description |
|---|---|---|---|
name | string | Tool name as the agent calls it, shown in mono – e.g. "search_web" | |
status | "running" | "success" | "error" | Spinner with a live timer, check with the duration, or a red "Failed" | |
summary | ReactNode | Short human summary next to the name; truncates with an ellipsis | |
icon | ReactNode | wrench icon | Icon in the tile on the left – a 16px stroke SVG fits best |
args | unknown | Arguments – objects are pretty-printed and highlighted, JSON strings are parsed; the section is hidden when undefined | |
result | unknown | What the tool returned – like args; other strings are shown as plain text. While running without a result, "Waiting for result…" is shown | |
error | string | Error message, shown in the body when status is "error" | |
startedAt | number | Start time in ms since epoch – the live timer counts from here instead of from when the card turned running | |
duration | number | Final duration in ms – otherwise the time measured while the card was running | |
defaultOpen | boolean | false | Start expanded (uncontrolled) |
open | boolean | Expanded state (controlled) | |
onOpenChange | (open: boolean) => void | Called when the header is toggled | |
openOnError | boolean | true | Opens the card when the call fails and closes it on the next run, unless someone toggled it by hand (uncontrolled only) |
onRetry | () => void | Shows a Retry button next to the error message | |
maxCodeHeight | number | 220 | Height in px after which arguments and result are capped with a fade and a "Show all" toggle |
className | string | Extra class on the root | |
ToolCallGroup · children | ToolCallCard elements | The cards – the group reads their icon, status and duration props for its header, so pass them as direct children | |
ToolCallGroup · label | string | "Used N tools" | Header label once nothing is running |
ToolCallGroup · runningLabel | string | "Using tools…" | Shimmering header label while any card is running |
ToolCallGroup · duration | number | Total in ms – otherwise the sum of the cards' duration props, or the time measured while any card was running | |
ToolCallGroup · defaultOpen / open / onOpenChange | boolean / boolean / (open) => void | false | Expanded state, uncontrolled or controlled |
ToolCallGroup · className | string | Extra class on the root |
Keyboard
- Tab: Moves through the headers, copy buttons, Show all and Retry; content of closed cards is skipped
- Enter / Space: On a header: expands or collapses the card or the group
Accessibility
- Headers are real buttons with aria-expanded and aria-controls pointing at the body
- Closed bodies are inert, so they can't be focused or read until opened
- A polite live region per card announces "search_web running", "finished" or "failed: …"; the group announces "Using tools…" and "Used 3 tools"
- Copy buttons are labelled "Copy arguments" / "Copy result" and switch to "Copied"; icons are aria-hidden
- Errors use text and an icon, not only red
Responsive
- Fills its container; name and summary truncate with an ellipsis, the status never wraps – works down to ~320px
- Code wraps long lines instead of scrolling sideways
- Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
Requirements
- React 19
Related
- Thinking Loader – A small working pill for AI replies – an eight-ray spinner and a shimmering label that rolls through phases and settles on a check
- Thinking State – AI working panel with a live timer, searched sources and thinking steps that appear one by one
- AI Answer – Streamed answer with source cards, citation chips that preview their source, copy, regenerate, feedback and follow-ups
Guides
- React components for AI chat interfaces – What an AI chat UI needs – composer, streaming answers, thinking states, tool calls, citations, message actions – and React components for each.
- How to show tool calls in an AI agent UI – How to display an agent's tool calls – one readable line per call, arguments and results on demand, errors with retry – and when to switch to a trace or a graph.
- How to show what an AI agent is doing – UI patterns that make an AI agent's work visible – the current step, its plan, tool calls, a live tree or timeline, and a trace of where time and money went.
- MCP UI in React: tool calls, results and approvals – Build the interface around MCP tools: visible calls, useful results, approvals and errors. Understand where the protocol ends and your React UI begins.
- Generative UI in React: turn tool results into useful views – Use model-selected tools and validated data to show React views. Build useful generative UI without executing arbitrary model-generated code.
- Agent UI in React: tasks, progress and human control – Design an agent UI around delegated work: a clear task, visible progress, reviewable actions and a result people can verify.