# Use case – Fetching live data from an external service

In this guide, we'll walk through another concrete function example: giving your Agent the ability to retrieve real-time weather data.

### Implementing a function for weather data

Let's go step by step through creating a function that retrieves weather data from an external service.

#### Function configuration

1. **Create a new function**:
   * Open your Agent's management panel;
   * Navigate to the "Functions" section;
   * Select the "Advanced functions" tab;
   * Press "New function";
2. **Fill in the function fields**:
   * **Name**: enter "weather\_info";
   * **Description**: "This function retrieves real-time weather data for a specific city. It provides information on temperature, general conditions, and chance of rain. Use it when a user asks about current weather for a location."
   * **Webhook**: enter your weather service link (e.g., "<https://api.openweathermap.org/data/2.5/weather>");
   * **HTTP method**: select GET;
   * **Query string template**: location={city}\&units=metric\&lang=en\&appid=your\_OpenWeatherMap\_key
   * **Create a new parameter and set**:
     * **Name**: "city" (matching the word in curly braces);
     * **Description**: "Name of the city for which to retrieve weather data";
     * **Type**: select "string";
     * Set the parameter as **required**.

{% hint style="danger" %} <mark style="color:red;">Remember that API keys should be sent inside the HTTP header, not in the query string. In this case, however, our service requires us to send the key in the "Query string template" field.</mark>
{% endhint %}

The query string lets you define dynamic parameters (i.e., variables) like {city}, which will be replaced with the actual value when the function is called:

3. Test the function:
   1. Use the "Test" section to verify it works;
   2. Enter a sample city (e.g., "London");
   3. Check that the response contains the correct weather data.

#### Integrating into the Agent's instructions

Now that the function is ready, let's add it to the Agent's instructions:

1. Go to your Agent's  **Settings**;
2. Navigate to  AI > Instructions;
3. Add these instructions:

```
When a user asks about the weather for a specific city:
1. Use the weather_info function with the city name as a parameter;
2. Interpret the received data and provide a clear, concise response;
3. Include temperature, general conditions, and chance of rain.
```

### Example usage

Here's how a conversation using this function might go:

> **User**: What's the weather like in London today?
>
> \[The Agent uses the weather\_info function with the parameter city="London"]
>
> **Agent**: Sure! Let me check the latest weather information for London.
>
> Based on the data I just received, I can tell you that today in London the temperature is 14°C with partly cloudy skies. There's a 20% chance of rain in the afternoon. Humidity is at 70% and wind speed is 15 km/h from the southwest.
>
> Would you like the forecast for the next few days, or do you have any other questions about the weather in London?

With this implementation, **your Agent becomes a reliable source of real-time information**. This weather data function is just the beginning: you can apply the same approach to integrate other types of external data, further expanding your Agent's capabilities! 🌟


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aisuru.com/en/advanced-features/integrations/functions/advanced-functions/best-practices/live-data-from-web.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
