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
Create a new function:
Open your Agent's management panel;
Navigate to the "Functions" section;
Select the "Advanced functions" tab;
Press "New function";
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.
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.
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:
Test the function:
Use the "Test" section to verify it works;
Enter a sample city (e.g., "London");
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:
Go to your Agent's Settings;
Navigate to AI > Instructions;
Add these instructions:
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! 🌟
Last updated