Agent Examples
Weather App With Tools
Build a weather app with a tool call.
Overview
This application shows an example of using a tool call in an agent. It allows the user to ask a question about the weather and responds with information based on where the user is. By leveraging a tool generation node, the agent can make a call to an external API. The intent is to determine the weather and the user’s geographical location using a couple of tools integrated with it. Here’s a breakdown of how the workflow progresses:
YAML Workflow
Workflow Breakdown
Step | Node Name | Type | Purpose |
---|---|---|---|
1 | create_system | create_messages | Sets a system prompt for the LLM |
2 | user_messages | create_messages | Takes in the user input as a message |
3 | all_messages | insert_messages | Combines user prompt and system messages |
4 | get_my_weather | tool_generation | Makes a tool call to the weather API to get the weather |
- Create a System Message: A message is created with the role of “system.” This message frames the context for the tool generation, telling the virtual assistant what its role is in this workflow. It specifies tasks such as determining the weather and informing the user of their location.
- User Message Handling:
- Receive User Input: Capture a message from the user, which typically contains the user’s query or request.
- Create User Message: This step converts the captured input into a message object with the role of “user”.
- Combine Messages: The system message and user message are combined into a list, which will be used to provide context for operations performed in subsequent steps.
- Tool Generation & Execution:
- Get Location: Use an HTTP request tool to get the user’s location based on their IP address by querying https://ipapi.co/json/.
- Get Weather: Use another HTTP request tool to get the current weather information for the user’s location. The query_schema is given, which indicates the latitude and longitude are needed as inputs to this weather query.