Registering Components as UI Tools
Learn how to register components as UI Tools with Tambo.
One of the core features of Tambo is its ability to intelligently respond to user messages with UI components filled with relevant data instead of just text. With this ability, Tambo allows your users to conversationally control your app with AI assistance rather than simply have questions answered.
Tambo does not, however, generate components from scratch on-the-fly. Instead, you "tell" Tambo which components are available and what props they expect using a registerComponent
call.
The @tambo-ai/react
package provides hooks to help with this.
Core Concepts
Component Registration
There are two main approaches to registering components with Tambo:
1. Using the TamboProvider
You can pass a list of components directly to the TamboProvider
component. All components will be visible to Tambo hooks and components rendered inside the provider.
2. Dynamic Registration
For runtime registration, use the registerComponent
function from the useTamboRegistry()
hook:
Note that dynamic registration makes tools available to all components within the <TamboProvider>
component.
Props Definition Options
You have two options for defining the props your components expect:
Using Zod (Recommended)
Note that when using zod's .optional()
on a field, tambo may not attempt to generate any value for the prop.
You can also use z.describe()
to provide extra guidance to the AI:
Using a JSON-like Object (Alternative)
Now when a user sends a message asking about something related to your components, Tambo can respond with the appropriate component filled with relevant data!