Overview
Components are React components that the AI can dynamically render in response to user messages. Each component is registered with a name, description, and props schema that defines what data it can accept.TamboComponent Type
TheTamboComponent interface defines how components are registered:
Component Field
The actual React component to render. Pass the component itself, not an instance:Name Field
A unique identifier for the component. Should be:- Descriptive - Indicates what the component does
- CamelCase or PascalCase - Follows React naming conventions
- Unique - No two components should share the same name
Description Field
Explains to the AI when and how to use this component. Should include:- Purpose - What the component displays or does
- Use cases - When it should be selected
- Data requirements - What kind of data it expects
Props Schema
Defines the component’s props using Zod or another supported schema library. The schema:- Validates incoming props
- Documents available props for the AI
- Provides types for TypeScript inference
Loading Component
Optional component shown while props stream in from the AI:Registering Components
Components are registered by passing them toTamboProvider:
Component Lifecycle
1. Registration
WhenTamboProvider mounts, components are registered with the internal registry and converted to tool definitions for the AI.
2. Selection
When a user sends a message, the AI analyzes it and decides which component(s) to render based on:- Component descriptions
- Available props schemas
- Conversation context
3. Streaming
The AI streams props to the selected component:- Component renders with initial/empty props
- Props update as they stream in
- Component re-renders with new prop values
- Stream completes when all props are delivered
4. Rendering
The component renders in the message thread as an assistant message with type"component".
Component Props
Props your component receives come from two sources:1. Schema-defined Props
Props defined in your Zod schema, streamed from the AI:2. Handling Partial Props
During streaming, props may be incomplete. Handle gracefully:Best Practices
Write Clear Descriptions
Descriptions help the AI choose the right component:Use Descriptive Schema Fields
Add.describe() to schema fields to help the AI understand what data to provide:
Handle Loading States
Show something meaningful while props stream:Avoid Props Not in Schema
Only use props defined in your schema. The AI won’t provide props outside the schema:TypeScript Integration
Infer prop types from your schema:Next Steps
- Learn about Interactable Components for persistent, updatable components
- Explore Tools to understand how components relate to the tool system
- See Streaming for details on handling real-time prop updates
- Check Generative UI for the high-level concept