Tool call
FreeOne 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.
npx shadcn@latest add https://pixilui.com/r/tool-call.jsonPreview
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>
);
}When to use
Use it when
- 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.
Use something else when
- 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.
Installation
npx shadcn@latest add https://pixilui.com/r/tool-call.jsonAdds tool-call.tsx with button.tsx, kbd.tsx, tooltip.tsx, code-block.tsx and badge.tsx, and installs clsx and tailwind-merge. The URL works in any app with a components.json, with no registry to add first.
"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>
);
});
It uses Button, Kbd, Tooltip, Code block and Badge: add them the same way. Then npm i clsx tailwind-merge, and add the foundation once per app, as in Installation.
Usage
import { ToolCall } from "@/components/pixilui/tool-call";
<ToolCall
tool={tool}
args={args}
onOpenChange={onOpenChange}
/>Fills its container; long values wrap under their own column, and the row's words keep one line.
API reference
toolRequiredstring–The tool's name: "Stripe".argsRequiredCodeJsonValue–The arguments it was called with.markReactNode–The tool's real logo, on its own color (a 20 tile).fnstring–The function it called, as a code tag: "refunds.create".timestring–How long it took: "412 ms".secretsRecord<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.resultCodeJsonValue–What it returned. Leave it out while there is none.statusstring | 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.foldnumber–Show this many lines of the result, then a fade and "Show all N lines".defaultOpenbooleantrueOpen (default) or folded, uncontrolled.openboolean–Open or folded, controlled.onOpenChange(open: boolean) => void–The head was pressed.numbersbooleanfalseLine numbers in the blocks (off by default: the JSON starts on the label's line).wordsPartial<ToolCallWords>–Every word it says.chevronReactNode–The head's chevron (the locked disclosure).Also takes every native <section> attribute except title, onToggle, and a ref.
Keyboard
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.
Related
Questions
A tool call: one row per call with the tool's real logo, the function as a code tag and its time, folding the arguments and the result as highlighted JSON a person can copy. A key in the arguments renders masked, and Copy copies the mask. Several calls in one turn are the reasoning trail's steps.
Yes. Map each tool call your framework reports to the row's
tool,fn,argsandresult(withstatusandtoneonce it returns); the row does not depend on a framework. The guides below show that mapping for the Vercel AI SDK, LangGraph and the OpenAI Agents SDK.
Guides
Show each tool call as one quiet row (the tool, the function, its time) and keep the input and output JSON one click away with keys masked, not in the message.
Any stack · Tool call UI with LangGraphRender LangGraph tool calls from stream.toolCalls: fold each call's input and output as JSON with keys masked, and tag finished and error.
LangGraph · Tool call UI with the OpenAI Agents SDKTurn tool_called and tool_output events from an OpenAI Agents SDK stream into tool calls: match by callId, time them, fold the JSON.
OpenAI Agents SDK · Tool call UI with the Vercel AI SDKRender AI SDK 7 tool parts as tool calls: name the function, fold input and output as JSON with keys masked, tag the result ok or failed.
Vercel AI SDK ·Compare
Tool calls and approvals inside an assistant-ui chat
Checked assistant-ui vs PixilUIA full chat runtime with adapters for many model backends
Checked Arc vs PixilUIOne library for a whole app's UI, with or without Tailwind
Checked prompt-kit vs PixilUIFree chat building blocks on shadcn/ui
Checked