---
title: 'Building a Weather AI Agent with ADK-Rust: A Step-by-Step Tutorial'
date: '2026-04-12T21:23:18+07:00'
description: 'Learn how to create a simple yet powerful AI Agent in Rust using the ADK-Rust framework and wttr.in to fetch real-time weather reports.'
author: 'AI Assistant'
image: '/images/post/building-weather-ai-agent-adk-rust.jpg'
alt: 'A conceptual image representing a high-tech AI agent and weather data.'
tags: ['rust', 'ai-agent', 'adk-rust', 'weather', 'tutorial']
---

In this tutorial, we will build a Weather AI Agent that can fetch real-time weather reports from the internet using a custom tool. We'll leverage the [ADK-Rust](https://github.com/google/adk-rust) framework and connect to the [wttr.in](https://wttr.in) service.

## Prerequisites

Before we start, ensure you have the following:

1.  **Rust Ecosystem**: A working Rust environment.
2.  **Google Gemini API Key**: To power the language model.
3.  **Dependencies**: We'll use `adk-rust` as our core framework and `reqwest` for HTTP requests.

## Step 1: Project Setup and Dependencies

Start by adding the following dependencies to your `Cargo.toml` file:

```toml
[dependencies]
adk-rust = "0.4"
adk-tool = "0.4"
tokio = { version = "1", features = ["full"] }
dotenvy = "0.15"
anyhow = "1"
reqwest = { version = "0.11", features = ["json"] }
serde_json = "1"
serde = { version = "1", features = ["derive"] }
schemars = "0.8"
async-trait = "0.1"
```

## Step 2: Defining Tool Arguments

We need to create a struct to capture the parameters that the AI Agent will pass to our tool. We'll derive `Deserialize` and `JsonSchema` so the agent understands the data structure.

```rust
#[derive(Deserialize, JsonSchema)]
struct WeatherArgs {
    /// The city to search for (e.g., bangkok, tokyo, london)
    city: String,
}
```

## Step 3: Creating the Weather Tool

Use the `#[tool]` macro to convert a standard async function into a tool that the Agent can invoke.

```rust
#[tool]
async fn get_weather(args: WeatherArgs) -> Result<Value> {
    let url = format!("https://wttr.in/{}?format=j1", args.city);
    let resp = reqwest::get(&url).await
        .map_err(|e| AdkError::Tool(e.to_string()))?
        .json::<serde_json::Value>().await
        .map_err(|e| AdkError::Tool(e.to_string()))?;
    Ok(resp)
}
```

## Step 4: Assembling the Agent

Finally, we'll use `LlmAgentBuilder` to create the agent and register our `get_weather` tool.

```rust
#[tokio::main]
async fn main() -> anyhow::Result<()> {
    dotenvy::dotenv().ok();
    let api_key = std::env::var("GOOGLE_API_KEY")?;

    // Select the Gemini model
    let model = adk_rust::model::GeminiModel::new(&api_key, "gemini-2.5-flash")?;

    // Build the Agent
    let agent = LlmAgentBuilder::new("agent-wttrin")
        .description("Weather Reporting AI")
        .instruction("You are a helpful assistant that provides accurate and friendly weather reports.")
        .model(Arc::new(model))
        .tool(Arc::new(GetWeather)) // Register the tool (note the PascalCase name automatically generated)
        .build()?;

    // Run via Launcher to interact through the terminal
    Launcher::new(Arc::new(agent)).run().await?;
    Ok(())
}
```

## How to Use Your Agent

1.  **Configure Environment**: Create a `.env` file and add your API Key:
    ```env
    GOOGLE_API_KEY=your_api_key_here
    ```

2.  **Run the Program**:
    ```bash
    cargo run
    ```

3.  **Interact with the Agent**:
    > "What's the weather like in Bangkok?"

The Agent will automatically call the `get_weather` tool, passing `city="bangkok"`, fetch the real-time data from wttr.in, and then summarize it for you in a friendly response!

## Conclusion

By using ADK-Rust, we've successfully integrated a live data source into an AI Agent with minimal boilerplate. This pattern can be extended to any API, allowing you to build specialized agents for virtually any task. Happy coding!
