Get Weather Data from OpenWeatherMap
Get current weather and tomorrow's forecast for any location in a LlamaIndex agent.
Why it matters
Integrate with the OpenWeatherMap API to retrieve current weather conditions and daily forecasts for any specified location.
Outcomes
What it gets done
Fetch current weather details for a given location.
Retrieve tomorrow's weather forecast for a specified location.
Connect to the OpenWeatherMap API using an API token.
Utilize the pyowm Python package for weather data retrieval.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/li-tool-tools-weather | bash Overview
Open Weather Map Tool
A LlamaIndex tool that fetches current weather and tomorrow's forecast for a location via OpenWeatherMap's OneCall API. Use for current or next-day weather questions about a named place, not longer-range or historical forecasts.
What it does
The Open Weather Map Tool connects a LlamaIndex agent to OpenWeatherMap's OneCall API using the pyowm Python package, giving the agent two weather-lookup functions: current conditions at a location, and the forecast for tomorrow at that location.
The OpenWeatherMapToolSpec is initialized with an OpenWeatherMap API token and exposes weather_at_location and forecast_tomorrow_at_location, both of which use pyowm under the hood to fetch and return the weather data for whatever place the agent is asked about.
When to use - and when NOT to
Use it when a LlamaIndex agent needs to answer questions about current or next-day weather conditions for a named place - temperature, wind, or general conditions today or tomorrow. Do not use it for forecasts beyond tomorrow or historical weather data - the tool only exposes current conditions and a one-day-ahead forecast, nothing further out.
Capabilities
weather_at_location returns current weather details for a given place. forecast_tomorrow_at_location returns the forecast for that place one day ahead. Both are powered by the pyowm client against OpenWeatherMap's OneCall API.
How to install
from llama_index.tools.weather import OpenWeatherMapToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
tool_spec = OpenWeatherMapToolSpec(key="...")
agent = FunctionAgent(
tools=tool_spec.to_tool_list(),
llm=OpenAI(model="gpt-4.1"),
)
Requires an OpenWeatherMap API token.
Who it's for
Developers building LlamaIndex agents that need to answer simple, current weather questions - today's conditions or tomorrow's forecast - for a location the user names.
Source README
Open Weather Map Tool
This tool connects to the OpenWeatherMap's OneCall API, using the pyowm Python package. You must initialize the tool with your OpenWeatherMap API token
The tool has access to the following functions:
- the current weather
- the weather tomorrow
Usage
Here's an example usage of the OpenWeatherMapToolSpec.
from llama_index.tools.weather import OpenWeatherMapToolSpec
from llama_index.core.agent.workflow import FunctionAgent
from llama_index.llms.openai import OpenAI
tool_spec = OpenWeatherMapToolSpec(key="...")
agent = FunctionAgent(
tools=tool_spec.to_tool_list(),
llm=OpenAI(model="gpt-4.1"),
)
print(await agent.run("What is the temperature like in Paris?"))
print(await agent.run("What is the wind like in Budapest tomorrow?"))
weather_at_location: Use pyowm to get current weather details at a location
forecast_tomorrow_at_location: Use pyowm to get the forecast for tomorrow at a location.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.