# LLM Kit Tool Call

AI agents can make decisions that trigger tool invocations for querying databases, calling APIs, or browsing the web. Use the ToolCall component to show users what action the agent takes and what result it receives.

The [ToolCall component](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcall) makes the side effects from tool invocations visible: it displays the tool name, input parameters, and output result in a collapsible block, and supports approval and error states so users can stay in control.

The following example demonstrates the ToolCall component animating through a complete execution sequence.

[Demo Source](https://demos.telerik.com/kendo-react-ui/conversational-ui/llm-kit/tool-call/source.txt)

## Configuring the Tool Header

Use [`label`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#label) to set the name of the tool or function. Additional context such as a target, resource, or execution duration can be included by using the [`secondaryLabel`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#secondarylabel) prop.

Set [`svgIcon`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#svgicon) to identify the tool being invoked. The component does not require a separate status icon; its [`state`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#state) determines the status presentation.

```tsx
<ToolCall
    label="query_database"
    secondaryLabel="analytics · db · 1.0s"
    state={toolState}
    svgIcon={dataSqlIcon}
/>
```

## Controlling the State

Use [`state`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#state) to show the current lifecycle stage of a tool invocation. The component supports four states:

* `active`—The tool invocation is in progress. The component displays the tool header and any provided parameters with its in-progress presentation, but does not display a status badge. See [Displaying Parameters and Results](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/llm-kit/tool-call#displaying-parameters-and-results).
* `completed`—The tool invocation finished successfully. The component displays a completed badge and the result, when provided. See [Displaying Parameters and Results](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/llm-kit/tool-call#displaying-parameters-and-results).
* `awaitingApproval`—The tool invocation needs user confirmation. The component displays an awaiting approval badge and the default approval content, when provided, with **Approve** and **Reject** actions. See [Showing Approval Actions](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/llm-kit/tool-call#showing-approval-actions).
* `error`—The tool invocation failed. The component displays an error badge and the error content, when provided. See [Handling Errors](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/llm-kit/tool-call#handling-errors).

```tsx
<ToolCall label="query_database" state={toolState} />
```

```tsx
const [toolState, setToolState] = React.useState<ToolCallState>('active');

const completeToolCall = () => setToolState('completed');
```

## Displaying Parameters and Results

Use [`parameters`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#parameters) to show data sent to the tool, such as a query or filter. Set [`result`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#result) to show the response returned by a completed tool call. The component formats the passed object value as JSON by default for both `parameters` and `result`.

```tsx
<ToolCall
    label="query_database"
    state="completed"
    parameters={parameters}
    result={result}
/>
```

Use [`paramsTemplate`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#paramstemplate) or [`resultTemplate`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#resulttemplate) to replace either JSON block with a custom React component.

```tsx Templates
const parameters = { query: 'SELECT * FROM customers' };
const result = { count: 10 };

const ParametersTemplate = ({ parameters }: ToolCallParamsTemplateProps) => (
    <p>Query: {(parameters as { query: string }).query}</p>
);

const ResultTemplate = ({ result }: ToolCallResultTemplateProps) => (
    <p>Records returned: {(result as { count: number }).count}</p>
);

<ToolCall
    label="query_database"
    state="completed"
    parameters={parameters}
    result={result}
    paramsTemplate={ParametersTemplate}
    resultTemplate={ResultTemplate}
/>;
```

## Showing Approval Actions

For actions that require user confirmation, set [`state`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#state) to `'awaitingApproval'`. The component then displays a default approval block inside the expanded panel.

Set [`approvalText`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#approvaltext) to display a message in the default block with **Approve** and **Reject** buttons. Handle the user's decision by using [`onAction`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#onaction) to start an approved operation, cancel a rejected operation, and update the ToolCall state with the outcome.

The following example demonstrates the full approval lifecycle from pending through to an approved or denied outcome.

[Demo Source](https://demos.telerik.com/kendo-react-ui/conversational-ui/llm-kit/tool-call-approval/source.txt)

For a custom approval layout, use [`approvalTemplate`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#approvaltemplate) to replace the default approval message block and actions.

```tsx
const ApprovalMessage = () => <p>Review this query before it runs.</p>;

<ToolCall
    state="awaitingApproval"
    parameters={parameters}
    approvalTemplate={ApprovalMessage}
/>;
```

## Handling Errors

When a tool invocation fails, set [`state`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#state) to `'error'`. The component then displays an error status badge, and when you provide [`errorText`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#errortext), a message inside a default error block in the expanded panel. Use [`errorTemplate`](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcallprops#errortemplate) to replace the default error content with a custom React component.

```tsx
<ToolCall
    label="query_database"
    state="error"
    errorText="Connection timeout: Unable to reach database server"
    expandable
    parameters={parameters}
/>
```

The following example demonstrates the ToolCall component transitioning from active execution to the error state.

[Demo Source](https://demos.telerik.com/kendo-react-ui/conversational-ui/llm-kit/tool-call-error/source.txt)

## Suggested Links

* [LLM Kit Overview](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/llm-kit)
* [Checkpoint](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/llm-kit/checkpoint)
* [API Reference of the ToolCall component](https://www.telerik.com/kendo-react-ui-develop/components/conversationalui/api/toolcall)
