# Display components

> Register React components that your agent can render in the chat.

<!-- interactive demo: gen-ui-tool-based -->

## What is this? [#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.

<Tabs items={['page.tsx', 'chart.tsx']}>
  <Tab value="page.tsx">
  ```tsx
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
});

````
</Tab>
<Tab value="chart.tsx">
```tsx
import { z } from "zod";
import { ResponsiveContainer, BarChart, XAxis, YAxis, Tooltip, Bar } from "recharts";

export const ChartProps = z.object({
  title: z.string(),
  data: z.array(z.object({ label: z.string(), value: z.number() })),
});

export function Chart({ title, data }: z.infer<typeof ChartProps>) {
  return (
    <div>
      <h3>{title}</h3>
      <ResponsiveContainer width="100%" height={300}>
        <BarChart data={data}>
          <XAxis dataKey="label" /><YAxis /><Tooltip />
          <Bar dataKey="value" fill="#6366f1" />
        </BarChart>
      </ResponsiveContainer>
    </div>
  );
}
````

  </Tab>
</Tabs>

## When should I use this? [#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 [#how-it-works-in-code]

<Steps>
  <Step>
    ### Install the ADK + AG-UI bridge

    ```bash
    pip install ag-ui-adk
    ```

  </Step>
  <Step>
    ### Add `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.

    ```python
    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,
    )
    ```

  </Step>
</Steps>

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.

```typescript title="src/app/demos/gen-ui-tool-based/page.tsx"
  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 [#without-parameters]

For simple components that don't need typed parameters, leave out
`parameters`. The component then accepts any props:

```tsx
useComponent({
  name: "showGreeting",
  render: ({ message }: { message: string }) => (
    <div className="rounded border p-3 bg-blue-50">
      <p>{message}</p>
    </div>
  ),
});
```

## Scoping to an agent [#scoping-to-an-agent]

In multi-agent setups, pass `agentId` to scope a component to one agent:

```tsx
useComponent({
  name: "renderProfile",
  parameters: z.object({ userId: z.string() }),
  render: ProfileCard,
  agentId: "support-agent",
});
```

<IntegrationGrid path="render-only" />
