Weather
About 779 wordsAbout 3 min
Adds WeatherAPI.com current conditions, multi-day forecasts, location autocomplete, and astronomy (sunrise / sunset / moon phase) data to Spora agents. Supports both metric and imperial units. A free tier is available (100k calls/month).
Installation
php bin/spora plugin:install spora-ai/spora-plugin-weatherFor local development against a sibling checkout, pass --path=/abs/path/to/checkout.
After install, the plugin exposes a single agent-facing tool — weather_api — with four operations (see Per-tool parameters).
Configuration
Settings → Tools → Weather API. The plugin reads its settings through Spora\Services\ToolConfigService; all settings can be left at defaults except api_key, which is required.
| Setting | Required | Default | Notes |
|---|---|---|---|
api_key | yes | — | API key from https://www.weatherapi.com. Encrypted at rest by ToolConfigService; masked in the UI; never logged. |
base_url | no | https://api.weatherapi.com/v1 | Override only if you proxy the API through your own gateway. |
default_days | no | 3 | Default forecast length when the agent doesn’t pass days. Clamped to 1..3 because the free plan caps forecast at 3 days. |
units | no | metric | metric (°C, km/h) or imperial (°F, mph). Select in the admin UI. |
http_timeout | no | 10 | Seconds before an HTTP request fails. Falls back to SPORA_TOOL_HTTP_TIMEOUT env var. |
The q location parameter accepts city names, lat,lon, US/UK/CA postal codes, METAR (metar:EGLL), IATA (iata:DXB), an IP address, auto:ip, or a search API id:NNNNNN (see the WeatherAPI docs).
Per-tool parameters
The plugin exposes one tool (weather_api) with four operations. Pick the operation in the agent’s tool call; on success the tool returns a human-readable text summary inside ToolResult::ok. It never throws — a single API failure surfaces as ToolResult::fail and the agent loop keeps running.
| Operation | Endpoint | Description | Parameters | Returns |
|---|---|---|---|---|
current | /current.json | Current conditions for a location. | location (string, required) | Condition text + code, temp / feels-like, wind / gusts, humidity, cloud cover, UV, precipitation, pressure, day/night, local time. |
forecast | /forecast.json | Multi-day forecast (clamped to 1–3 days on the free plan). | location (string, required), days (int 1–3, required, falls back to default_days) | One block per day: date, condition, avg/high/low temp, max wind, chance of rain, UV index. |
search | /search.json | Autocomplete / resolve a location name. | query (string, ≥2 chars, required) | Up to ~10 matches: name, region, country, lat/lon, local time. |
astronomy | /astronomy.json | Sunrise, sunset, moonrise/moonset, moon phase and illumination. | location (string, required), date (yyyy-MM-dd, required, default today) | All six astro fields for the given location and date. |
All four operations are enabledByDefault and do not require human approval (requiresApprovalByDefault: false). Authentication is via ?key=<api_key> query parameter on every request; the key is stripped from log lines.
Vendor
- Sign up: https://www.weatherapi.com
- API documentation: https://www.weatherapi.com/docs/
Both metric and imperial units are supported natively by the upstream API — toggle between them with units.
Translations
The plugin ships a German catalogue at locales/de.json, declared through WeatherPlugin::translationsPaths(). The catalogue key is the English source string:
{ "Weather API": "Wetter-API", "Metric or Imperial units": "Metrische oder Imperial-Einheiten" }Only operator-facing copy is translated — the tool’s display name, every #[ToolSetting] description this plugin owns, and the plugin description. A description core already translates is core’s to keep: the host merges the plugin’s catalogue under core’s, and core wins a key collision, so the plugin does not repeat it. Strings the model reads (#[Tool].description, #[ToolParameter].description, #[ToolSetting].label and its option labels) stay English, in the operator’s view too: a German tool description degrades the model’s tool selection, and a translated label that also reaches the model puts German into its prompt.
Editing the English orphans the translation — the key changes and the old entry is dead — so re-translate in the same commit. The repository checks its catalogue against three rules: no translation is empty, none is identical to its key, and no key survives a copy edit. The gate is this repository’s own tests/Unit/LocaleCatalogTest.php.
Requires spora-core >= 0.31.0; on older cores the catalogue is ignored.
Development
composer install
./vendor/bin/pest # Pest tests
./vendor/bin/phpstan analyse --no-progress
./vendor/bin/php-cs-fixer fix --dry-run --diffCI: .github/workflows/ci.yml — Pest on PHP 8.4 + 8.5 + 8.6, PHPStan, and php-cs-fixer dry-run. The sonar job uploads coverage to SonarCloud (project key spora-ai_spora-plugin-weather) so the new_coverage metric is measurable per PR; requires the SONAR_TOKEN secret in the repo. MIT license.
Repo: spora-ai/spora-plugin-weather · MIT