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

user_input:
  message:
    type: string
workflow:
  - name: create_system
    type: create_messages
    config:
      message_configs:
        - role: system
          content: >
            You are a helpful assistant that can help the user determine the
            weather outside.

            Use relevant tools in the correct order to answer the user's
            question.

            Also inform the user where exactly they are in the world.
    inputs: {}
  - name: user_messages
    type: create_messages
    config:
      message_configs:
        - role: user
          content: message
    inputs:
      message: message
  - name: all_messages
    type: insert_messages
    config:
      index: -1
    inputs:
      messages: create_system.output
      new_messages: user_messages.output
  - name: get_my_weather
    type: tool_generation
    config:
      model: openai/gpt-4o
      tools:
        - name: experimental.HTTPRequestTool
          init_kwargs:
            name: get_location
            method: GET
            url: https://ipapi.co/json/
            description: Get user's location based on IP address
            timeout: 5
        - name: experimental.HTTPRequestTool
          init_kwargs:
            name: get_weather
            method: GET
            url: https://api.open-meteo.com/v1/forecast?hourly=temperature_2m
            description: Get current weather data for a location
            query_schema: >-
              {"properties": {"latitude": {"description": "Latitude coordinate",
              "title": "Latitude", "type": "number"}, "longitude":
              {"description": "Longitude coordinate", "title": "Longitude",
              "type": "number"}}, "required": ["latitude", "longitude"],
              "title": "WeatherQuery", "type": "object"}
    inputs:
      messages: all_messages.output

Workflow Breakdown

StepNode NameTypePurpose
1create_systemcreate_messagesSets a system prompt for the LLM
2user_messagescreate_messagesTakes in the user input as a message
3all_messagesinsert_messagesCombines user prompt and system messages
4get_my_weathertool_generationMakes a tool call to the weather API to get the weather
  1. 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.
  2. 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”.
  3. 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.
  4. 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.