# Tool call

> One tool invocation from arguments to result: preparing, running, done, failed or denied.

The card an agent shows when it calls a tool. Arguments fill in as the model writes them and the panel eases taller with each one. The status is one pill that never swaps out: "Preparing" carries a sweep of light, a spinner opens in as it morphs to "Running", then the spinner blurs into a check that draws itself while the run time rolls up from zero and the result rises in. Failures open themselves with the reason and a retry. Arguments read as fields, not raw JSON, and you can render any result your own way.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/tool-call.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/tool-call
- Registry item (source): https://hairlineui.com/r/tool-call.json

## Usage

```tsx
import { ToolCall } from "@/components/tool-call";

<ToolCall
  name="search_flights"
  title="Search flights"
  status="done"
  duration={1240}
  input={{ from: "BLR", to: "LIS", date: "2026-11-02" }}
  output={{ cheapest: "€412", airline: "TAP" }}
/>
```

## With the AI SDK

```tsx
import { useChat } from "@ai-sdk/react";
import type { UIMessage } from "ai";
import { ToolCall, type ToolCallStatus } from "@/components/tool-call";

type ToolPart = Extract<UIMessage["parts"][number], { toolCallId: string }>;

function toolStatus(part: ToolPart): ToolCallStatus {
  switch (part.state) {
    case "input-streaming": return "preparing";
    case "input-available": return "running";
    case "output-available": return "done";
    case "output-error": return "error";
    case "approval-responded": return part.approval.approved ? "running" : "denied";
    default: return "denied"; // output-denied (show approval-requested with ApprovalCard)
  }
}

function ToolCalls({ message }: { message: UIMessage }) {
  return message.parts.map((part) =>
    "toolCallId" in part && part.state !== "approval-requested" ? (
      <ToolCall
        key={part.toolCallId}
        name={part.type === "dynamic-tool" ? part.toolName : part.type.replace(/^tool-/, "")}
        status={toolStatus(part)}
        input={part.input}
        output={part.state === "output-available" ? part.output : undefined}
        errorText={part.state === "output-error" ? part.errorText : undefined}
      />
    ) : null
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `name / title` | `string` | – | The tool’s name as the model calls it, and an optional human label. |
| `status` | `"preparing" \| "running" \| "done" \| "error" \| "denied"` | – | Where the call is. |
| `input` | `unknown` | – | Arguments, possibly partial while preparing. Objects render as fields. |
| `output / renderOutput` | `unknown / (output) => ReactNode` | – | The result, shown as fields or JSON, or rendered your way. |
| `errorText / onRetry` | `string / () => void` | – | Why it failed, and a Retry button. |
| `duration` | `number` | – | Run time in ms, shown when done. |
| `icon` | `ReactNode` | `wrench` | An icon for the tool. |
| `open / defaultOpen / onOpenChange` | `boolean / boolean / (open) => void` | `false` | Control the details panel. |

## States

- **preparing**: A 1.4s sweep of light crosses "Preparing" while the arguments arrive field by field; the panel eases to each new height over 420ms.
- **running**: The icon slot opens (380ms) with a spinner and the label morphs to "Running". The spinner only spins in this state.
- **done**: The spinner blurs out as an emerald check draws itself (420ms), the label lifts away and the run time rolls up from zero ("1.2s"); the output rises in as the panel eases to fit.
- **error**: An alert icon and "Failed" in red; the card opens itself once to show the reason and a Retry.
- **denied**: A ban icon and "Denied": the user declined, so it didn’t run.

## What it handles

When an agent calls a tool, people want to know what it asked for and what came back, without reading raw JSON. This shows one call from its arguments to its result.

- **Arguments fill in as written**: They show as fields rather than raw JSON, and the panel eases taller with each one.
- **One status pill**: The pill goes from “Preparing” to “Running” to a check, without ever being swapped for another element.
- **Run time and result**: The run time rolls up from zero and the output rises in, as fields or JSON, or rendered your way.
- **Failures explain themselves**: A failed call opens itself once, shows the reason and offers Retry.
- **Denied is a state of its own**: A ban icon and “Denied” say the person declined, so nothing ran.
- **Long values don’t break the layout**: Long text wraps and nested objects show as compact JSON. Folded details are inert.

## Replaces

a tool call card, a JSON viewer, a status badge, a run timer, an error with Retry

## Where it fits

- **AI agent chats**: Show each tool the agent calls, with its arguments and its result.
- **Assistants that call APIs**: Make an API request visible, so people see what was sent.
- **Agent debugging**: Inspect what a tool received and returned.
- **Approval flows**: Mark a call as denied when the person said no.

## Notes

- The header is a button with aria-expanded; the status badge is announced politely as it changes, and the run time is real text behind the rolling digits.
- Collapsed details are inert, so a folded card can’t trap focus.
- Long values wrap and nested objects show as compact JSON, so wide arguments never break the layout.
- Installs Number roll and Text morph. With reduced motion the sweep, spinner, rolls and slides stop; states change in place.

License: MIT (https://hairlineui.com/license#components)
