What is Static AG-UI?
Static AG-UI is a generative UI approach where you hand-craft React components and register them with CopilotKit. Your agent then decides when to invoke these components and what data to pass to them. This approach guarantees:- Visual polish and consistency - You control every pixel
- Type safety - Full TypeScript support with Zod schemas
- Predictability - Components behave exactly as designed
- Brand alignment - Components match your design system
Two Approaches: Display vs Tool Rendering
CopilotKit provides two hooks for static generative UI, each serving a different purpose:useComponent: Display Components
UseuseComponent when you want the agent to directly render a visual component as a tool. The component appears in the chat without requiring backend tool execution.
- You want the agent to display rich UI (cards, charts, tables) directly
- No backend processing is needed
- The component is purely presentational
useRenderTool: Tool Call Rendering
UseuseRenderTool when you want to customize how backend tool calls appear in the chat. This shows users what tools your agent is executing and their progress.
- Your agent calls backend tools (database queries, API calls, computations)
- You want to show progress indicators or tool arguments
- You want to render custom results when tools complete
Complete Example: Weather Display
Let’s build a complete example showing both approaches:Frontend: Register Components
app/page.tsx
Component: Weather Card
components/WeatherCard.tsx
Agent: Python Backend (AG2 Example)
agent.py
Agent vs Tool Rendering: When to Use Which
| Scenario | Use | Why |
|---|---|---|
| Display data visualization | useComponent | No backend processing needed |
| Show a chart or card | useComponent | Purely presentational |
| Render preview or summary | useComponent | Direct display of information |
| Show tool execution progress | useRenderTool | User needs transparency |
| Display API call status | useRenderTool | Backend processing happening |
| Render database query results | useRenderTool | Tool returning data |
Advanced: Tool Rendering States
useRenderTool provides three states to handle different execution phases:
Agent Scoping
Both hooks support scoping to specific agents:Comparison with Other Approaches
| Feature | Static AG-UI | Declarative A2UI | Open-ended MCP |
|---|---|---|---|
| Component control | Developer | Spec-defined | Agent/MCP Server |
| Type safety | Full (Zod + TS) | Schema-level | None |
| Visual consistency | Guaranteed | Good | Variable |
| Setup complexity | Medium | Medium | Low |
| Cross-platform | React-based | Multi-renderer | Web-only |
| Maintainability | High | Medium | Low |
Best Practices
1. Keep Components Simple and Focused
2. Use Descriptive Names and Descriptions
3. Leverage Zod Descriptions for Better Agent Understanding
4. Handle All Tool States Gracefully
Next Steps
useComponent API
Full API reference for useComponent hook
useRenderTool API
Full API reference for useRenderTool hook
Declarative A2UI
Learn about JSON-based UI specifications
MCP Apps
Explore open-ended HTML/JavaScript rendering
