Tool Rendering
Render your agent's tool calls with custom UI components.
This example demonstrates the implementation section applied in the CopilotKit feature viewer.
What is this?
Tools are a way for the LLM to call predefined, typically, deterministic functions. CopilotKit allows you to render these tools in the UI as a custom component, which we call Generative UI.
When should I use this?
Rendering tools in the UI is useful when you want to provide the user with feedback about what your agent is doing, specifically when your agent is calling tools. CopilotKit allows you to fully customize how these tools are rendered in the chat.
Render tool calls in your frontend
Use the useRenderTool hook to render tool calls in the UI. The name must match the name of the tool defined in your agent.
Important
In order to render a tool call in the UI, the name must match the name of the tool. Learn more.
import { useRenderTool } from "@copilotkit/react-core/v2";
import { z } from "zod";
// ...
const weatherParams = z.object({
location: z.string().describe("The location to get weather for"),
});
const YourMainContent = () => {
// ...
useRenderTool({
name: "get_weather",
parameters: weatherParams,
render: ({ status, parameters }) => {
return (
<p className="text-gray-500 mt-2">
{status !== "complete" && "Calling weather API..."}
{status === "complete" && `Called the weather API for ${parameters.location}.`}
</p>
);
},
});
// ...
}
Default Tool Rendering
useDefaultRenderTool provides a catch-all renderer for any tool that doesn't have a specific useRenderToolCall defined. This is useful for:
- Displaying all tool calls during development
- Rendering MCP (Model Context Protocol) tools
- Providing a generic fallback UI for unexpected tools
import { useDefaultRenderTool } from "@copilotkit/react-core/v2";
// ...
const YourMainContent = () => {
// ...
useDefaultRenderTool({
render: ({ name, args, status, result }) => {
return (
<div style={{ color: "black" }}>
<span>
{status === "complete" ? "✓" : "⏳"}
{name}
</span>
{status === "complete" && result && (
<pre>{JSON.stringify(result, null, 2)}</pre>
)}
</div>
);
},
});
// ...
};
Unlike useRenderToolCall, which targets a specific tool by name,
useDefaultRenderTool catches all tools that don't have a dedicated
renderer.
In v2, use useDefaultRenderTool
for wildcard fallback rendering, and
useRenderTool for named or wildcard
renderer registration.
