OpenWeatherTools enable an Agent to access weather data from the OpenWeatherMap API.

Prerequisites

The following example requires the requests library and an API key which can be obtained from OpenWeatherMap. Once you sign up the mentioned api key will be activated in a few hours so please be patient.

export OPENWEATHER_API_KEY=***

Example

The following agent will use OpenWeatherMap to get current weather information for Tokyo.

cookbook/tools/openweather_tools.py
from agno.agent import Agent
from agno.tools.openweather import OpenWeatherTools

# Create an agent with OpenWeatherTools
agent = Agent(
    tools=[
        OpenWeatherTools(
            units="imperial",  # Options: 'standard', 'metric', 'imperial'
        )
    ],
    markdown=True,
)

# Get current weather for a location
agent.print_response("What's the current weather in Tokyo?", markdown=True)

Toolkit Params

ParameterTypeDefaultDescription
api_keystrNoneOpenWeatherMap API key. If not provided, uses OPENWEATHER_API_KEY env var.
unitsstrmetricUnits of measurement. Options: ‘standard’, ‘metric’, ‘imperial’.
current_weatherboolTrueEnable current weather function.
forecastboolTrueEnable forecast function.
air_pollutionboolTrueEnable air pollution function.
geocodingboolTrueEnable geocoding function.

Toolkit Functions

FunctionDescription
get_current_weatherGets current weather data for a location. Takes a location name (e.g., “London”).
get_forecastGets weather forecast for a location. Takes a location name and optional number of days (default 5).
get_air_pollutionGets current air pollution data for a location. Takes a location name.
geocode_locationConverts a location name to geographic coordinates. Takes a location name and optional result limit.

Developer Resources