Adding Tools
Add tools to extend Tambo's capabilities
Define your tool function and register it with tambo. Tools are asynchronous functions that take in a single argument and return a single value.
//define the tool function. This is your own custom function and can perform any logic you want.
const getWeather = async (city: string) => {
try {
const weather = await fetch(
`http://api.weatherapi.com/v1/current.json?key=${process.env.NEXT_PUBLIC_WEATHER_API_KEY}&q=${city}`,
);
return weather.json();
} catch (error) {
throw new Error(`Failed to fetch weather for ${city}`);
}
};
// Create a TamboTool definition including your tool function
export const tools: TamboTool[] = [
{
name: "get_weather",
description: "Fetch current weather information for a specified city",
tool: getWeather,
toolSchema: z
.function()
.args(z.string().describe("The city to fetch weather for"))
.returns(
z.object({
location: z.object({
name: z.string(),
}),
}),
),
},
];
// Register your tools with Tambo
<TamboProvider tools={tools}>
<App />
</TamboProvider>;
Now tambo can fetch weather information for a city when responding to a message!