# Tool call

One tool call in the agent's answer: its row names the call (the tool's real logo, the function as a code tag, the time) and folds its Arguments and Result. A secret in the arguments renders masked, and Copy copies the mask.

Tier: free. Type: component. Category: ai. Tags: agent, trace, run, keyboard, motion.

## Install

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

One-time setup: add the registry to `components.json`:

```json
{
  "registries": {
    "@pixilui": "https://pixilui.com/r/{name}.json"
  }
}
```

Files: `components/pixilui/tool-call.tsx`.

## Preview

Live preview: https://pixilui.com/components/tool-call

Knobs:

- `result`: `200, refunded`, `402, declined`
- `row`: `open`, `folded`

Signature: Copy on the arguments: the check draws, the masked Stripe key lights once, and the clipboard holds sk_live_••••••••4242.

Styles: `lively` (default), `quiet`, set with `data-style` on <html>. The item reads the style through the foundation; it needs no prop. Standalone files: lively https://pixilui.com/r/standalone/tool-call.tsx, quiet https://pixilui.com/r/standalone/tool-call.quiet.tsx.

## Code

`components/pixilui/tool-call.tsx`

```tsx
"use client";

/*
  Tool call (B11, locked 3 Dec 2026, design/explorations/components/locked/code, view 1): one call's row (the tool's real logo,
  "Called Stripe", the function as a filled code tag, the time) that folds its two blocks, Arguments and Result. The head names
  the call the way the locked reasoning trail's head does (14/20 in the muted ink, words then the chevron); it is a button
  that folds the blocks away (the system's fold). A secret in the arguments renders masked and Copy copies the mask.

  A port of the locked code.js's call(); the blocks are code-block's CodeBlockJson. The look is foundation.css section 8
  (.pixilui-code-call, --pixilui-code-call-*). Several calls in one turn are the reasoning trail's job, not this row's.
*/

import { forwardRef, useId, useState, type ComponentPropsWithoutRef, type ReactNode } from "react";
import { IconDisclosure } from "./icons/disclosure";
import { cn } from "./lib/utils";
import { BadgeTag } from "./badge";
import { CodeBlockJson, codeWords, type CodeJsonValue, type CodeWords } from "./code-block";

export type ToolCallWords = CodeWords & {
  /** The head's words: "Called Stripe". */
  called: (tool: string) => string;
  /** The first block's label. */
  args: string;
  /** The second block's label. */
  result: string;
};

export const toolCallWords: ToolCallWords = { ...codeWords, called: (tool) => `Called ${tool}`, args: "Arguments", result: "Result" };

export type ToolCallProps = Omit<ComponentPropsWithoutRef<"section">, "children" | "title" | "onToggle"> & {
  /** The tool's name: "Stripe". */
  tool: string;
  /** The tool's real logo, on its own color (a 20 tile). */
  mark?: ReactNode;
  /** The function it called, as a code tag: "refunds.create". */
  fn?: string;
  /** How long it took: "412 ms". */
  time?: string;
  /** The arguments it was called with. */
  args: CodeJsonValue;
  /** Keys whose values are secrets, each with what it is ({ api_key: "Stripe secret key" }); values that look like keys are caught too. */
  secrets?: Record<string, string>;
  /** What it returned. Leave it out while there is none. */
  result?: CodeJsonValue;
  /** The result's status code, shown as the locked tag in the Result header (200). */
  status?: string | number;
  /** The status tag's tone: ok (default) or bad. */
  tone?: "ok" | "bad";
  /** Show this many lines of the result, then a fade and "Show all N lines". */
  fold?: number;
  /** Open (default) or folded, uncontrolled. */
  defaultOpen?: boolean;
  /** Open or folded, controlled. */
  open?: boolean;
  /** The head was pressed. */
  onOpenChange?: (open: boolean) => void;
  /** Line numbers in the blocks (off by default: the JSON starts on the label's line). */
  numbers?: boolean;
  /** Every word it says. */
  words?: Partial<ToolCallWords>;
  /** The head's chevron (the locked disclosure). */
  chevron?: ReactNode;
};

/** One tool call: its row names the call and folds the Arguments and Result blocks. A secret renders masked; Copy copies the mask. */
export const ToolCall = forwardRef<HTMLElement, ToolCallProps>(function ToolCall(
  { tool, mark, fn, time, args, secrets = {}, result, status, tone = "ok", fold, defaultOpen = true, open: openProp, onOpenChange, numbers = false, words: w, chevron, className, ...rest },
  ref,
) {
  const words = { ...toolCallWords, ...w };
  const id = useId();
  const [own, setOwn] = useState(defaultOpen);
  const open = openProp ?? own;
  return (
    <section ref={ref} className={cn("pixilui-code-call", className)} aria-label={`${words.called(tool)}${fn ? ` ${fn}` : ""}`} {...rest}>
      <button
        className="pixilui-code-call-head"
        type="button"
        aria-expanded={open}
        aria-controls={id}
        onClick={() => {
          setOwn(!open);
          onOpenChange?.(!open);
        }}
      >
        {mark ? (
          <span className="pixilui-code-call-mark" aria-hidden="true">
            {mark}
          </span>
        ) : null}
        <span className="pixilui-code-call-words">
          <span>{words.called(tool)}</span>
          {fn ? <code>{fn}</code> : null}
          {time ? <span className="pixilui-code-call-time">{time}</span> : null}
        </span>
        <span className="pixilui-code-call-chev" aria-hidden="true">
          {chevron ?? <IconDisclosure />}
        </span>
      </button>
      <div className="pixilui-code-call-body pixilui-fold" id={id} data-state={open ? "open" : "closed"} inert={!open}>
        <div>
          <div className="pixilui-code-call-blocks">
            <CodeBlockJson title={words.args} value={args} secrets={secrets} numbers={numbers} words={words} />
            {result !== undefined ? (
              <CodeBlockJson
                title={words.result}
                value={result}
                fold={fold}
                numbers={numbers}
                words={words}
                meta={
                  status !== undefined && status !== null ? (
                    <BadgeTag tone={tone} size="sm">
                      {String(status)}
                    </BadgeTag>
                  ) : undefined
                }
              />
            ) : null}
          </div>
        </div>
      </div>
    </section>
  );
});
```

## Usage

When to use:

- One call the agent made, with the evidence a person can open: what it sent and what came back.
- A call whose arguments hold a key: it never reaches the page or the clipboard.

When not to use:

- Several calls in one turn: they are the reasoning trail's steps.
- A command the agent ran in a terminal: use Command.
- A change to a file: use Diff.

```tsx
import { ToolCall } from "@/components/pixilui/tool-call";
import { StripeMark, toolCallArgs, toolCallDeclined, toolCallResult } from "@/components/pixilui/tool-call.examples";

// The first option of each knob is the demo's default; the docs preview starts there.
export const knobs = {
  result: ["200, refunded", "402, declined"],
  row: ["open", "folded"],
} as const;

const ANSWER = { fontSize: "var(--pixilui-text-answer)", lineHeight: "var(--pixilui-text-answer-leading)", letterSpacing: "var(--pixilui-text-answer-tracking)" };

/** One call in the agent's answer: the row names it and folds its Arguments and Result; the key stays masked, and Copy copies the mask. */
export default function ToolCallDemo({ result = "200, refunded", row = "open" }: KnobValues<typeof knobs>) {
  const ok = result === "200, refunded";
  return (
    <div className="grid w-full max-w-xl gap-3 rounded-panel bg-surface p-5 elevation-raised">
      <p className="m-0 text-foreground" style={ANSWER}>
        {ok ? "Refunding Lena Ortiz $214.00 for the duplicate charge on Nov 14." : "Stripe declined the refund: the charge was already refunded on Nov 15."}
      </p>
      <ToolCall
        key={`${result}${row}`}
        tool="Stripe"
        mark={<StripeMark />}
        fn="refunds.create"
        time={ok ? "412 ms" : "268 ms"}
        args={toolCallArgs}
        secrets={{ api_key: "Stripe secret key" }}
        result={ok ? toolCallResult : toolCallDeclined}
        status={ok ? 200 : 402}
        tone={ok ? "ok" : "bad"}
        fold={8}
        defaultOpen={row === "open"}
      />
    </div>
  );
}
```

## Examples

None.

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `tool` (required) | `string` |  | The tool's name: "Stripe". |
| `mark` | `ReactNode` |  | The tool's real logo, on its own color (a 20 tile). |
| `fn` | `string` |  | The function it called, as a code tag: "refunds.create". |
| `time` | `string` |  | How long it took: "412 ms". |
| `args` (required) | `CodeJsonValue` |  | The arguments it was called with. |
| `secrets` | `Record<string, string>` | `{}` | Keys whose values are secrets, each with what it is ({ api_key: "Stripe secret key" }); values that look like keys are caught too. |
| `result` | `CodeJsonValue` |  | What it returned. Leave it out while there is none. |
| `status` | `string \| number` |  | The result's status code, shown as the locked tag in the Result header (200). |
| `tone` | `"ok" \| "bad"` | `"ok"` | The status tag's tone: ok (default) or bad. |
| `fold` | `number` |  | Show this many lines of the result, then a fade and "Show all N lines". |
| `defaultOpen` | `boolean` | `true` | Open (default) or folded, uncontrolled. |
| `open` | `boolean` |  | Open or folded, controlled. |
| `onOpenChange` | `(open: boolean) => void` |  | The head was pressed. |
| `numbers` | `boolean` | `false` | Line numbers in the blocks (off by default: the JSON starts on the label's line). |
| `words` | `Partial<ToolCallWords>` |  | Every word it says. |
| `chevron` | `ReactNode` |  | The head's chevron (the locked disclosure). |

Also accepts every native `<section>` attribute except `title`, `onToggle`, and a ref to it.

## Keyboard

- `Tab`: Reaches the row, then each block's Copy, its masked keys and Show all.
- `Enter` + `Space`: Folds or opens the blocks from the row; copies; shows all lines.

## Accessibility

- The row is a button with aria-expanded and aria-controls; a folded body is inert.
- The section is named for the call (Called Stripe refunds.create); a masked key is role img named with its last four.
- On touch the 20 row reaches 44 tall without growing.

## Motion

- The row folds the blocks with the system's fold (the height glides, the blocks fade into a 2px blur), and the chevron turns.
- A long result glides open under Show all; Copy turns into its check and the masked key lights once.
- Reduced motion: at once.

## Responsive

- Fills its container; long values wrap under their own column, and the row's words keep one line.

## Performance

- Plain spans and CSS transitions; one ResizeObserver per well.

## Notes for AI

- <ToolCall tool="Stripe" mark={<StripeMark />} fn="refunds.create" time="412 ms" args={args} secrets={{ api_key: "Stripe secret key" }} result={result} status={200} fold={8} />.
- Pass the tool's real logo as mark (a 20 tile on its own color); leave result out while the call has none; tone bad for a 4xx or 5xx status.
- Several calls in one turn belong to the reasoning trail, not a group of rows (the old grouped summary is gone).
- Every word is in words (Called, Arguments, Result, Copy); the blocks are code-block's CodeJson.

## Related

- [Code block](https://pixilui.com/components/code-block/markdown): Code the agent shows you in its answer, in a grey well: the file with its folders quiet, Copy, the syntax in six picked inks and a write-in replay. A well of JSON masks any key as it renders, and Copy copies the mask.
- [Command](https://pixilui.com/components/command/markdown): A command the agent ran: the row reads Ran pnpm test · 4.2 s and folds a well with the command, Copy and what it printed. Running, its output prints in, the clock ticks and Stop ends it; a failure reads red with its exit code.
- [Reasoning trail](https://pixilui.com/components/reasoning-trail/markdown): The agent's thinking chain in a chat: steps on one hairline with their thoughts and sources, streamed with a soft edge, folding into one line when the answer starts, any retry or failure kept.
- [Diff](https://pixilui.com/components/diff/markdown): An agent's edit to one file, waiting in its answer: the row reads Edited policy.ts +5 −2 with Undo and Keep, over the path and the line diff. Keep and Undo turn the diff into the file in place, and each change can be kept or undone on its own.
