Adding a tool
When building AI agents, you often need to extend their capabilities with external data or functionality. Timbal lets you pass tools to an agent using the tools
parameter. Tools give agents a way to call specific functions, such as fetching data or performing calculations, to help answer a user's query.
Prerequisites
This example uses the openai
model. Make sure to add OPENAI_API_KEY
to your .env
file.
Creating a tool
This tool provides historical weather data for London, returning arrays of daily temperature, precipitation, wind speed, snowfall, and weather conditions from January 1st of the current year up to today. This structure makes it easy for agents to access and reason about recent weather trends.
Adding a tool to an agent
This agent uses the london_weather_tool_instance
to answer questions about historical weather in London. It has clear instructions that guide it to use the tool for every query and limit its responses to data available for the current calendar year.
Example usage
Use the agent directly by calling it with a prompt message.