logoAnt Design X

⌘ K
DesignDevelopmentComponentsX MarkdownX SDKX CardX SkillPlayground
  • Introduction
  • Overview
  • Common
    • Bubble
    • Conversations
    • Notification
      2.0.0
  • Confirm
    • ToolCall
      2.9.0
  • Confirmation
    • Think
      2.0.0
    • ThoughtChain
      2.0.0
  • Wake
    • Welcome
    • Prompts
  • Express
    • Attachments
    • Sender
    • Suggestion
  • Feedback
    • Actions
    • CodeHighlighter
      2.1.0
    • FileCard
      2.0.0
    • FolderFile Tree
      2.4.0
    • Mermaid
      2.1.0
    • Sources
      2.0.0
  • Others
    • XProvider

ToolCall

Display an Agent tool call's arguments, execution status, result, and error.
Importimport { ToolCall } from "@ant-design/x";
Sourcex/components/tool-call
Docs
Edit this page
Versionsupported since 2.9.0
loading

When To Use

  • Display a tool invocation in an Agent conversation or execution timeline.
  • Provide a consistent surface for streaming arguments, approval, live duration, results, errors, and retry intent.
  • The component renders state and emits approval, cancellation, and retry intent. The application owns real tool execution, authorization checks, and persistence.

Examples

API

Common props ref: Common props

ToolCallProps

PropertyDescriptionTypeDefault
itemTool call view modelToolCallItem-
statusIconsOverride icons by execution status; approval represents awaiting approval; null hides the iconToolCallStatusIcons-
expandedWhether details are expanded in controlled modeboolean-
defaultExpandedInitial expansion; derived from status when omittedbooleanSee below
onExpandedChangeCalled when expansion changes(expanded: boolean) => void-
retryingDisables retry and displays its loading statebooleanfalse
onRetryEmits retry intent(item: ToolCallItem) => void-
approvalApproval configuration with controlled and uncontrolled modesToolCallApprovalConfig-
approvalRenderCustom renderer for the complete approval region(approval, item, actions) => ReactNode-
durationDuration display configuration; false hides itboolean | ToolCallDurationConfigtrue
cancellingControlled cancellation loading stateboolean-
onCancelEmits cancellation intent while running(item: ToolCallItem) => void | Promise<void>-
cancelButtonPropsCancel button propsButtonProps-
argumentsRenderCustom arguments renderer(item: ToolCallItem) => ReactNode-
resultRenderCustom result renderer(value: unknown, item: ToolCallItem) => ReactNode-
errorRenderCustom error renderer(error: ToolCallError, item: ToolCallItem) => ReactNode-
actionsCustom actionsReactNode | (item: ToolCallItem) => ReactNode-
classNamesSemantic class namesRecord<SemanticDOM, string>-
stylesSemantic stylesRecord<SemanticDOM, CSSProperties>-
prefixClsStyle class prefixstring-
rootClassNameRoot class namestring-

ToolCallItem

typescript
type ToolCallStatus =
| 'pending'
| 'streaming'
| 'running'
| 'completed'
| 'failed'
| 'cancelled';
type ToolCallStatusIconType = ToolCallStatus | 'approval';
type ToolCallStatusIcons = Partial<
Record<ToolCallStatusIconType, React.ReactNode | ((item: ToolCallItem) => React.ReactNode)>
>;
interface ToolCallItem {
id: React.Key;
name: string;
icon?: React.ReactNode;
description?: React.ReactNode;
argumentsText?: string;
arguments?: unknown;
result?: unknown;
status: ToolCallStatus;
error?: ToolCallError;
attempt?: number;
startedAt?: number;
completedAt?: number;
}
interface ToolCallError {
code?: string;
message: string;
retryable?: boolean;
details?: unknown;
}

When item.icon is provided, a completed call prefers the tool's own icon, which can be an image or any ReactNode. Pending, streaming, running, failed, cancelled, and approval states continue to use status icons. statusIcons takes precedence over tool and built-in icons; override individual states or pass null to hide an icon.

ToolCallApprovalConfig

PropertyDescriptionTypeDefault
statusControlled approval statepending | approved | rejected-
defaultStatusInitial uncontrolled approval statepending | approved | rejectedpending
titleApproval titleReactNodeApproval required
descriptionRisk or impact descriptionReactNode-
riskRisk levellow | medium | high-
approveTextApprove action labelReactNodeApprove and run
rejectTextReject action labelReactNodeReject
approveButtonPropsApprove button propsButtonProps-
rejectButtonPropsReject button propsButtonProps-
loadingExternally controlled action loading stateboolean | approve | reject-
onStatusChangeCalled after a successful approval action(status, item) => void-
onApproveApprove callback; status is committed after its Promise resolves(item) => void | Promise<void>-
onRejectReject callback; status is committed after its Promise resolves(item) => void | Promise<void>-

Without status, the component updates its internal approval state after the action succeeds. With status, update it from onStatusChange. A rejected callback Promise leaves the approval pending so the user can retry. Real authorization must still be enforced on the server.

approvalRender receives the approval config, current item, and { status, loading, approve, reject }. Use it for edit-before-run, approval reasons, always-allow, or multi-party workflows.

ToolCallDurationConfig

PropertyDescriptionTypeDefault
valueControlled elapsed time in millisecondsnumber-
refreshIntervalRunning refresh interval, at least 250msnumber1000
formatterCustom duration renderer(milliseconds, item) => ReactNode-

By default, elapsed time updates from startedAt while running and freezes when completedAt is present. Providing value fully controls the displayed duration.

pending, streaming, running, and failed expand by default. completed and cancelled collapse by default. Supplying expanded makes the component fully controlled.

The default retry action is only visible when status is failed, error.retryable is true, and onRetry is supplied. Running calls show cancellation when onCancel is supplied. The component does not execute tools directly; update item in response to emitted events.

Completed calls display a safely serialized result summary and copy action by default. Expand the call to inspect the complete displayable result.

Complete JSON in argumentsText is formatted while incomplete streaming JSON is preserved. Object results use safe serialization; circular, binary, and oversized values receive concise type summaries. Default rendering never injects HTML or exposes raw stack traces.

Semantic DOM

Design Token

Component TokenHow to use?
Token NameDescriptionTypeDefault Value
actionGapnumber4
approvalColorstring#faad14
contentMaxHeightnumber320
detailBgstring#ffffff
errorColorstring#ff4d4f
headerBgstringrgba(0,0,0,0.02)
runningColorstring#1677ff
statusSizenumber24
successColorstring#52c41a
Global TokenHow to use?
Basic

Display a complete tool call in a conversation. The demo simulates argument streaming, execution, and completion, then restores the tool's own icon.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Approval and execution

Controlled approval and execution timing.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
All statuses

The component covers pending, argument streaming, running, completed, failed, and cancelled states, including tool icons and status icon overrides. Retry is shown only for retryable failures with an onRetry handler.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Controlled expansion

Use expanded and onExpandedChange to fully control the details area and synchronize it with an inspection mode or global preference.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Custom rendering

Use argument, result, and error renderers plus the actions slot to turn a tool call into a domain-specific observability surface.

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
Travel assistantConnected · tools ready
AI

I’ll check the local forecast before planning the itinerary.

Completed
getWeatherForecast
Hangzhou · next 3 days·Completed·1.3s·Result: { "current": "27°C", "condition": "Partly cloudy", "forecast": [ "28 / 22°C",...

The next three days are warm with light cloud cover.

Release controlProduction deployment
PROD
Awaiting approval
deployProduction
checkout-api · v2.18.0 · cn-hangzhou·Awaiting approval
Arguments
{
  "service": "checkout-api",
  "version": "v2.18.0",
  "strategy": "canary",
  "traffic": "10% → 50% → 100%",
  "rollbackOnError": true
}
Production access requiredHigh risk
This action changes live traffic. Health checks and automatic rollback are enabled.
Waiting for an authorized operator
Pending
reserveInventory
Waiting for an execution slot·Pending
Receiving arguments
searchCatalog
Receiving structured arguments·Receiving arguments
Running
calculateShipping
Calling logistics providers·Running·0ms
Completed
queryOrder
Order #20260803001·Completed·Result: { "status": "paid", "total": 369 }
Failed
createShipment
Provider request failed·Failed
Cancelled
sendNotification
Cancelled by the user·Cancelled
Details
Completed
runSalesAnalysis
Quarterly revenue by product line·Completed
Arguments
{
  "period": {
    "from": "2026-04-01",
    "to": "2026-06-30"
  },
  "dimensions": [
    "productLine",
    "region"
  ]
}
Result
{
  "rows": 128,
  "currency": "CNY",
  "generatedAt": "2026-08-04T10:20:00Z"
}
Completed
deployPreview#2
x-components · preview/4281·Completed
Arguments
branch: feature/tool-call
region: cn-hangzhou
checks: true
Result
Preview is healthyAverage latency 82 ms
Failed
queryOrder
Order query·Failed
Arguments
{
  "orderId": "20260803001"
}
Error
Service unavailable
  • root
    Root
  • header
    Header
  • status
    Status
  • name
    Tool name
  • description
    Description
  • actions
    Actions
  • details
    Details
  • approval
    Approval
  • arguments
    Arguments
  • result
    Result
  • error
    Error