OpenWeather

Fetch current weather, forecasts, air pollution data, and geocoding with OpenWeatherTools and the OpenWeatherMap API.

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

Prerequisites

The following example requires the requests and openai libraries and an API key which can be obtained from OpenWeatherMap. The API key activates a few hours after sign-up.

uv pip install -U agno requests openai
export OPENWEATHER_API_KEY=***

Example

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

cookbook/91_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'.
enable_current_weatherboolTrueEnable current weather function.
enable_forecastboolTrueEnable forecast function.
enable_air_pollutionboolTrueEnable air pollution function.
enable_geocodingboolTrueEnable geocoding function.
allboolFalseEnable all functions.
timeoutint30Per-request HTTP timeout in seconds.

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