← All tools

Knowledge & Research

OpenWeatherMap

Current conditions and 5-day forecasts.

openweathermap

Overview

Looks up today's weather and the five-day forecast for any city or coordinate. Useful whenever weather might influence a decision — travel planning, event scheduling, field operations.

How it works

Calls the OpenWeatherMap API to return either current conditions or a 5-day forecast at 3-hour intervals. Accepts a city name or (lat, lon) coordinates and returns temperature, humidity, wind, and a short description. Units can be metric, imperial, or Kelvin-based 'standard'.

Example

When a user asks:

What's the 5-day forecast for Zurich?

the agent calls the tool:

openweathermap(city="Zurich", forecast=true, units="metric")

and gets back: current conditions plus a 5-day / 3-hour forecast in metric units.

Configuration

Set these before calling the tool. Values marked required must be present or the tool call will fail.

OPENWEATHER_API_KEY required

OpenWeatherMap API key. Read from env or the 'api_key' parameter.

swarmai.tools.openweather.api-key optional

Spring property alternative to the env var.

Use it in a workflow

Wire this tool into a SwarmAI crew. Use the YAML DSL for declarative workflows, or the Java builder API when you want full programmatic control.

YAML DSL

# ops-planning.yaml
name: ops-planning-crew
process: SEQUENTIAL

agents:
  - id: planner
    role: Operations Planner
    goal: Factor weather into scheduling decisions
    tools:
      - openweathermap

tasks:
  - id: ops-planning-task
    agent: planner
    description: Get the 5-day forecast for Zurich and flag any day with more than 70% chance of precipitation.

Java

import ai.intelliswarm.swarmai.agent.Agent;
import ai.intelliswarm.swarmai.task.Task;
import ai.intelliswarm.swarmai.swarm.Swarm;
import ai.intelliswarm.swarmai.swarm.SwarmOutput;
import ai.intelliswarm.swarmai.process.ProcessType;
import ai.intelliswarm.swarmai.tool.data.OpenWeatherMapTool;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;

@Autowired ChatClient chatClient;
@Autowired OpenWeatherMapTool openWeatherMapTool;

Agent planner = Agent.builder()
    .role("Operations Planner")
    .goal("Factor weather into scheduling decisions")
    .chatClient(chatClient)
    .tool(openWeatherMapTool)
    .build();

Task plannerTask = Task.builder()
    .description("Get the 5-day forecast for Zurich and flag any day with more than 70% chance of precipitation.")
    .agent(planner)
    .build();

SwarmOutput result = Swarm.builder()
    .agent(planner)
    .task(plannerTask)
    .process(ProcessType.SEQUENTIAL)
    .build()
    .kickoff();

What it's good for

Real scenarios where agents put this tool to work.

Travel and logistics planning agents
Event-ops agents for outdoor scheduling
5-day forecasts for field-work crews
City conditions in smart-assistant demos

Source

Implementation lives at swarmai-tools/src/main/java/ai/intelliswarm/swarmai/tool/data/OpenWeatherMapTool.java in the swarm-ai repository.

Open openweathermap on GitHub →