# Generative UI Generative UI lets the agent render React components directly in the chat. Instead of responding with text, the agent can produce charts, interactive widgets, visualizations, and custom UI. All generative UI in this project is registered in `apps/app/src/hooks/use-generative-ui-examples.tsx`. ## Hooks Overview | Hook | Purpose | |------|---------| | `useComponent` | Register a named React component the agent can render with parameters | | `useFrontendTool` | Register a tool the agent can call that runs in the browser | | `useRenderTool` | Custom renderer for a specific backend tool | | `useDefaultRenderTool` | Fallback renderer for any tool without a custom renderer | | `useHumanInTheLoop` | Interactive component that pauses the agent for user input | All hooks are imported from `@copilotkit/react-core/v2`. ## useComponent — Agent-Rendered Components Register a React component with a name, description, Zod schema, and render function. The agent decides when to use it based on the description. ### Chart Example ```tsx import { z } from "zod"; import { useComponent } from "@copilotkit/react-core/v2"; const PieChartProps = z.object({ title: z.string(), description: z.string(), data: z.array(z.object({ label: z.string(), value: z.number(), })), }); useComponent({ name: "pieChart", description: "Displays data as a pie chart.", parameters: PieChartProps, render: PieChart, // your React component }); ``` ### Widget Renderer (Sandboxed HTML) The `widgetRenderer` component renders arbitrary HTML/SVG in a sandboxed iframe. This is the most flexible generative UI — the agent writes HTML and it gets rendered with full interactivity. ```tsx useComponent({ name: "widgetRenderer", description: "Renders interactive HTML/SVG visualizations in a sandboxed iframe. " + "Use for algorithm visualizations, diagrams, interactive widgets, " + "simulations, math plots, and any visual explanation.", parameters: WidgetRendererProps, // { title, description, html } render: WidgetRenderer, }); ``` The iframe environment includes: **ES Module Libraries** (use `