> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenWeather

**OpenWeatherTools** 使 Agent 能够从 OpenWeatherMap API 访问天气数据。

## 先决条件

以下示例需要 `requests` 库和一个 API 密钥，该密钥可从 [OpenWeatherMap](https://openweathermap.org/api) 获取。注册后，您提到的 API 密钥将在几小时后激活，请耐心等待。

```shell theme={null}
export OPENWEATHER_API_KEY=***
```

## 示例

下面的 Agent 将使用 OpenWeatherMap 获取东京当前的天气信息。

```python cookbook/tools/openweather_tools.py theme={null}
from agno.agent import Agent
from agno.tools.openweather import OpenWeatherTools

# 创建一个包含 OpenWeatherTools 的 Agent
agent = Agent(
    tools=[
        OpenWeatherTools(
            units="imperial",  # 可选值：'standard', 'metric', 'imperial'
        )
    ],
    markdown=True,
)

# 获取某个地点的当前天气
agent.print_response("What's the current weather in Tokyo?", markdown=True)
```

## Toolkit 参数

| 参数                | 类型     | 默认值      | 描述                                                          |
| ----------------- | ------ | -------- | ----------------------------------------------------------- |
| `api_key`         | `str`  | `None`   | OpenWeatherMap API 密钥。如果未提供，则使用 OPENWEATHER\_API\_KEY 环境变量。 |
| `units`           | `str`  | `metric` | 测量单位。可选值：'standard', 'metric', 'imperial'。                  |
| `current_weather` | `bool` | `True`   | 启用当前天气功能。                                                   |
| `forecast`        | `bool` | `True`   | 启用天气预报功能。                                                   |
| `air_pollution`   | `bool` | `True`   | 启用空气污染数据功能。                                                 |
| `geocoding`       | `bool` | `True`   | 启用地理编码功能。                                                   |

## Toolkit 函数

| 函数                    | 描述                                 |
| --------------------- | ---------------------------------- |
| `get_current_weather` | 获取某个地点的当前天气数据。接受地点名称（例如，“London”）。 |
| `get_forecast`        | 获取某个地点的天气预报。接受地点名称和可选的天数（默认为 5 天）。 |
| `get_air_pollution`   | 获取某个地点的当前空气污染数据。接受地点名称。            |
| `geocode_location`    | 将地点名称转换为地理坐标。接受地点名称和可选的结果限制。       |

## 开发者资源

* 查看 [Tools](https://github.com/agno-agi/agno/blob/main/libs/agno/agno/tools/openweather.py)
* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/tools/openweather_tools.py)
