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

NameTypeDefaultDescription
namestringTool 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"
summaryReactNodeShort human summary next to the name; truncates with an ellipsis
iconReactNodewrench iconIcon in the tile on the left – a 16px stroke SVG fits best
argsunknownArguments – objects are pretty-printed and highlighted, JSON strings are parsed; the section is hidden when undefined
resultunknownWhat the tool returned – like args; other strings are shown as plain text. While running without a result, "Waiting for result…" is shown
errorstringError message, shown in the body when status is "error"
startedAtnumberStart time in ms since epoch – the live timer counts from here instead of from when the card turned running
durationnumberFinal duration in ms – otherwise the time measured while the card was running
defaultOpenbooleanfalseStart expanded (uncontrolled)
openbooleanExpanded state (controlled)
onOpenChange(open: boolean) => voidCalled when the header is toggled
openOnErrorbooleantrueOpens the card when the call fails and closes it on the next run, unless someone toggled it by hand (uncontrolled only)
onRetry() => voidShows a Retry button next to the error message
maxCodeHeightnumber220Height in px after which arguments and result are capped with a fade and a "Show all" toggle
classNamestringExtra class on the root
ToolCallGroup · childrenToolCallCard elementsThe cards – the group reads their icon, status and duration props for its header, so pass them as direct children
ToolCallGroup · labelstring"Used N tools"Header label once nothing is running
ToolCallGroup · runningLabelstring"Using tools…"Shimmering header label while any card is running
ToolCallGroup · durationnumberTotal in ms – otherwise the sum of the cards' duration props, or the time measured while any card was running
ToolCallGroup · defaultOpen / open / onOpenChangeboolean / boolean / (open) => voidfalseExpanded state, uncontrolled or controlled
ToolCallGroup · classNamestringExtra 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