Display components
Register React components that your agent can render in the chat.
What is this?
A display component is a React component that your agent can call as a tool. When the agent calls the tool, CopilotKit renders your component directly in the chat with the tool's arguments as props. You do not write a handler, and the user does not need to do anything.
import { useComponent } from "@copilotkit/react-core/v2";
import { Chart, ChartProps } from "./chart";
useComponent({
name: "showChart",
description: "Populate data and show the user a chart",
parameters: ChartProps,
render: Chart
});
When should I use this?
Use a display component when you want to:
- Display rich UI (cards, charts, tables) inline in the chat
- Show structured data from agent responses
- Render previews, status indicators, or visual feedback
- Let the agent present information beyond plain text
How it works in code
Install the ADK + AG-UI bridge
pip install ag-ui-adkAdd AGUIToolset() to your agent
AGUIToolset() exposes CopilotKit's frontend tools to the model.
Add it to your LlmAgent's tools= list. Use an ADK-supported model
available to your project.
The callback below preserves the Gemini termination safeguard: it stops on
final text with a STOP finish reason, while leaving partial responses and
pending tool calls alone. It is defined here in full, not imported from
ag-ui-adk or a showcase-only module.
from ag_ui_adk import AGUIToolset
from google.adk.agents import LlmAgent
from google.adk.agents.callback_context import CallbackContext
from google.adk.models.llm_response import LlmResponse
def stop_on_terminal_text(
callback_context: CallbackContext, llm_response: LlmResponse
) -> None:
content = llm_response.content
if llm_response.partial or not content or content.role != "model":
return
finish_reason = llm_response.finish_reason
if getattr(finish_reason, "name", finish_reason) != "STOP":
return
parts = content.parts or []
if not any(part.text for part in parts) or any(part.function_call for part in parts):
return
# ADK's invocation context is private; tolerate SDK changes.
invocation = getattr(callback_context, "_invocation_context", None)
if invocation is not None:
try:
invocation.end_invocation = True
except AttributeError:
pass
agent = LlmAgent(
name="assistant",
model="gemini-3.1-flash-lite",
instruction="Help the user and call the available frontend tools when appropriate.",
tools=[AGUIToolset()],
after_model_callback=stop_on_terminal_text,
)The display component receives the tool's arguments as typed props and mounts inline in the chat. Below is the bar chart from the demo. The agent sends the data, and the component draws it.
useComponent({
name: "render_bar_chart",
description: "Display a bar chart with labeled numeric values.",
parameters: barChartPropsSchema,
render: BarChart,
});Ask the agent for a chart, for example Show me a bar chart of quarterly sales for Q1, Q2, Q3, Q4. The chart renders in the chat with the data
that the agent filled in.
Without parameters
For simple components that don't need typed parameters, leave out
parameters. The component then accepts any props:
useComponent({
name: "showGreeting",
render: ({ message }: { message: string }) => (
<div className="rounded border p-3 bg-blue-50">
<p>{message}</p>
</div>
),
});Scoping to an agent
In multi-agent setups, pass agentId to scope a component to one agent:
useComponent({
name: "renderProfile",
parameters: z.object({ userId: z.string() }),
render: ProfileCard,
agentId: "support-agent",
});How is this guide?