Overview
Generative UI in CopilotKit enables you to:- Render custom components based on agent tool calls
- Display real-time progress and status updates
- Create interactive approval interfaces for human-in-the-loop workflows
- Stream intermediate state from agents to the UI
- Build rich, contextual interfaces that update as agents work
What You’ll Learn
This guide teaches you how to:- Implement the
renderfunction inuseFrontendTool - Use
useRenderActivityMessagefor rendering agent activity - Create status-aware UI components
- Build custom generative UI for tool calls
- Handle different execution states (executing, inProgress, complete, error)
Example: Search Results Component
One of the simplest generative UI examples is rendering search results as they’re being fetched: File:components/generative-ui/SearchResults.tsx
Example: Car Selection UI
A more complex example from the State Machine example shows an interactive car selection component: File:components/generative-ui/show-car.tsx
- Displays car details in a visually appealing card
- Shows/hides action buttons based on completion status
- Provides user interaction callbacks (onSelect, onReject)
- Adapts to different status states
Streaming Agent State
For more advanced use cases, you can stream intermediate state from your agent to create live updates:Backend: Emit Intermediate State
In your LangGraph agent (Python example): File:agent/src/search.py
Frontend: Render Streaming State
File:lib/hooks/use-trips.tsx
components/SearchProgress.tsx
Render Function Parameters
Therender function receives an object with these properties:
Status Values
ToolCallStatus.InProgress- The tool call is in progress (arguments may be partial)ToolCallStatus.Executing- The tool is currently being executed (all arguments present)ToolCallStatus.Complete- The tool has completed successfully- (Error states are handled separately)
Best Practices
1. Handle All Status States
Always provide UI feedback for each status state:2. Use Framer Motion for Smooth Transitions
Animate component entries and state changes:3. Provide Clear Visual Feedback
Use icons, colors, and animations to indicate status:4. Make Interactive Components Responsive
Hide action buttons when completed to avoid duplicate actions:Advanced: Multiple Cars with Selection
Render multiple options and handle selection: File:components/generative-ui/show-car.tsx
Real-World Examples
Research Canvas
The Research Canvas example uses generative UI to display research progress and results in real-time as the agent conducts research. Source: GitHubState Machine Copilot
The State Machine example uses multiple generative UI components for different stages:- Contact information forms
- Car selection cards
- Financing options
- Payment cards
- Order confirmation
Travel Planner
The Travel Planner uses generative UI for:- Trip addition/editing approval interfaces
- Search progress indicators
- Map marker updates
Next Steps
Human-in-the-Loop
Learn how to use generative UI for approval workflows
Shared State
Build state-driven generative UI components
useFrontendTool
Complete reference for the useFrontendTool hook
useRenderActivityMessage
Reference for rendering agent activity
