Overview
Component registration tells Tambo which React components the AI can render and how to use them. By providing a Zod schema for props, the AI understands what data each component needs and can stream props in real-time.Component Types
Tambo supports two types of components:- Generative Components - Render once in response to a message (charts, summaries, visualizations)
- Interactable Components - Persist and update as users refine requests (task boards, shopping carts, forms)
Tambo supports both Zod v3 and v4. You can also use other Standard Schema-compliant validators like Valibot or ArkType.
import React from 'react';
interface WeatherCardProps {
location: string;
temperature: number;
condition: string;
humidity?: number;
}
export const WeatherCard: React.FC<WeatherCardProps> = ({
location,
temperature,
condition,
humidity,
}) => (
<div className="weather-card">
<h2>{location}</h2>
<div className="temp">{temperature}°F</div>
<div className="condition">{condition}</div>
{humidity && <div className="humidity">Humidity: {humidity}%</div>}
</div>
);
import { z } from 'zod';
export const weatherCardSchema = z.object({
location: z.string().describe('The city and state/country'),
temperature: z.number().describe('Temperature in Fahrenheit'),
condition: z.string().describe('Weather condition (sunny, cloudy, rainy, etc.)'),
humidity: z.number().optional().describe('Humidity percentage (0-100)'),
});
import { TamboComponent } from '@tambo-ai/react';
import { WeatherCard, weatherCardSchema } from '@/components/weather-card';
export const components: TamboComponent[] = [
{
name: 'WeatherCard',
description: 'Displays current weather information for a location. Use this when the user asks about weather conditions.',
component: WeatherCard,
propsSchema: weatherCardSchema,
},
];
import { TamboProvider } from '@tambo-ai/react';
import { components } from '@/lib/tambo-components';
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html>
<body>
<TamboProvider
apiKey={process.env.NEXT_PUBLIC_TAMBO_API_KEY!}
userKey="user-123"
components={components}
>
{children}
</TamboProvider>
</body>
</html>
);
}
Multiple Components
Register multiple components by adding them to the array:lib/tambo-components.ts
Loading States
Provide a loading component to show while props are streaming:Best Practices
Use descriptive component names
Use descriptive component names
Choose names that clearly indicate what the component does.
WeatherCard is better than Card1.Write detailed descriptions
Write detailed descriptions
Include when to use the component and what scenarios it’s appropriate for. The AI uses this to make decisions.
Add field descriptions to schemas
Add field descriptions to schemas
Use
.describe() on each schema field to help the AI understand what data to provide.Keep schemas aligned with props
Keep schemas aligned with props
Your Zod schema should match your TypeScript prop types. Use
z.infer<typeof schema> to derive types:Use enums for limited options
Use enums for limited options
When a prop has specific valid values, use
z.enum():Troubleshooting
Component not rendering
Component not rendering
- Verify the component is in the
componentsarray passed toTamboProvider - Check that the
namefield matches what you expect - Ensure the AI’s response includes your component (check the message content)
Props not streaming correctly
Props not streaming correctly
- Confirm your schema matches the expected prop types
- Check for TypeScript errors in the component
- Verify the schema validates the incoming data
AI choosing wrong component
AI choosing wrong component
- Make descriptions more specific and detailed
- Add examples of when to use each component
- Ensure component names are distinct and clear
Next Steps
Interactable Components
Create components that persist and update
Register Tools
Add functions the AI can call
Component State
Manage state inside AI-rendered components
Streaming Status
Monitor prop streaming progress