Overview
Tools are functions that the AI can execute to perform actions. In Tambo, tools run client-side in the browser, giving them access to:- DOM manipulation
- React state
- Browser APIs (localStorage, geolocation, etc.)
- Authenticated API calls
- User-specific data
TamboTool Type
TheTamboTool interface defines how to register a tool:
Tool Fields
name
Unique identifier for the tool. Should be descriptive and follow camelCase:description
Explains to the AI what the tool does and when to use it:tool
The function to execute. Can be sync or async:inputSchema.
inputSchema
Defines the tool’s parameters using Zod:outputSchema
Defines the expected return type:- Type safety
- AI understanding of return values
- Validation of tool responses
transformToContent (Optional)
Transforms the tool result into content parts for the AI:transformToContent when your tool returns rich content like images or audio.
Registering Tools
Pass tools toTamboProvider:
Tool Execution Flow
- User message - “What’s the weather in San Francisco?”
- AI decides - Calls
getWeathertool with{ location: "San Francisco" } - Validation - Input validated against
inputSchema - Execution - Tool function runs client-side
- Result - Return value sent back to AI
- Response - AI incorporates result into its response
Common Use Cases
Fetching Data
Modifying State
Browser APIs
DOM Manipulation
Tool vs Component
When should you use a tool vs a component?Use a Tool When:
- Performing an action (update cart, send email, save data)
- Fetching data that will be displayed in text or existing UI
- No new UI needed - the result is used in the conversation
- Browser APIs - accessing geolocation, clipboard, etc.
Use a Component When:
- Displaying data in a custom visualization
- Rendering UI - charts, cards, forms, etc.
- Interactive elements that persist across messages
- Rich presentation beyond plain text
Use Both Together:
Tools can fetch data that components then display:- Calls
fetchSalesDatatool - Receives data
- Renders
SalesChartcomponent with the data
Error Handling
Throw errors from tools to signal failure to the AI:Best Practices
Clear Descriptions
Validate Inputs
Use schema constraints:Type Safety
Infer types from schemas:Handle Async Properly
Always use async/await, never.then():
Next Steps
- Learn about Components to display tool results
- Explore MCP for server-side tool integration
- See Streaming for real-time tool execution
- Check Authentication for securing tool calls