Agentic AI represents a significant leap forward from simple chatbots. Instead of just responding to a single question, an AI “agent” can proactively pursue a goal. It can decompose a complex request into a logical series of steps, choose the right tools for each step—like querying a database or running a calculation—and then execute that plan to deliver a complete solution. This ability to reason, plan, and act makes agents powerful tools for automating complex digital tasks.

MySQL HeatWave is a fully managed MySQL database service that combines transactions, analytics, machine learning, and GenAI services, without ETL duplication. Also included is MySQL HeatWave Lakehouse, which allows users to query data in object storage, MySQL databases, or a combination of both. Users can deploy MySQL HeatWave–powered apps on a choice of public clouds: Oracle Cloud Infrastructure (OCI), Amazon Web Services (AWS), and Microsoft Azure.

This article showcases the power of combining the LangChain framework with an LLM hosted on MySQL HeatWave GenAI. Our goal is to create an agent that can answer the question, “What is the current weather in Fahrenheit?”. To do this, the agent must first fetch the weather (which is in Celsius) and then convert it to Fahrenheit, a classic multi-step task. This agent will demonstrate how a Large Language Model (LLM) can use tools and a logical sequence of steps to solve a problem.

The Agent’s “Brain”: Zero-Shot REACT in LangChain

At the core of our weather bot is a ZERO_SHOT_REACT_DESCRIPTION agent from LangChain. This type of agent uses the LLM’s reasoning ability to determine the best sequence of actions to take. It operates on a simple but powerful loop: Thought -> Action -> Observation.

  1. Thought: The agent thinks about what it needs to do to solve the problem.
  2. Action: Based on its thought, it chooses a tool to use.
  3. Observation: It observes the result from the tool and uses that information to decide on its next thought and action.

This entire reasoning process is powered by a LLM running in MySQL HeatWave, which we connect to LangChain using a custom MyLLM wrapper.

The Agent’s “Tools”: Getting Data and Crunching Numbers

To interact with the real world, our agent needs tools. For this task, we’ve equipped it with two custom-built tools: a weather fetcher and a calculator.

1. The Weather Tool

This tool’s job is to get the current weather. It first determines the machine’s approximate location using an IP-based location service (ipapi.co). It then passes the latitude and longitude to the Open-Meteo API to retrieve live weather conditions. Crucially, this tool gets the temperature in Celsius.

Here’s the Python function that defines the core logic:

import requests
    
    def get_current_location_and_weather(input_str: str = ""):
        # 1) Get approximate location via IP
        loc_resp = requests.get("https://ipapi.co/json/", timeout=5)
        loc_resp.raise_for_status()
        loc = loc_resp.json()
        lat = loc.get("latitude")
        lon = loc.get("longitude")
        if lat is None or lon is None:
            raise ValueError("Could not determine latitude/longitude from IP.")
    
        # 2) Get current weather from Open-Meteo
        params = {
            "latitude": lat,"longitude": lon,
            "current": "temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,weather_code",
            "timezone": "auto",
     }
        wx_resp = requests.get(
            "https://api.open-meteo.com/v1/forecast", params=params, timeout=5
     )
        wx_resp.raise_for_status()
        wx = wx_resp.json().get("current", {})
    
        return {
            "location": {
                "city": loc.get("city"),"region": loc.get("region"),
                "country": loc.get("country_name"), "country_code": loc.get("country_code"),
                "latitude": lat, "longitude": lon, "ip": loc.get("ip"),
                "source": "ipapi.co (IP-based, approximate)",
     },
    
            "weather": {
                "time": wx.get("time"), "temperature_c": wx.get("temperature_2m"),
                "feels_like_c": wx.get("apparent_temperature"), "humidity_percent": wx.get("relative_humidity_2m"),
                "wind_speed_mps": wx.get("wind_speed_10m"),  "weather_code": wx.get("weather_code"),
                "source": "open-meteo.com",
     },
     }

We then wrap this function in a LangChain Tool object so the agent can use it.

from langchain.agents import Tool
    
    # Create the weather tool
    weather_tool_object = Tool(
        name="Weather",
        func=get_current_location_and_weather,
        description=(
            "Gets the weather in Celsius for the current location. Has no inputs. When choosing this tool, always provide: Action Input: (an empty string)."
     ),
    )

2. The Calculator Tool

This is a straightforward tool that can evaluate a mathematical expression using Python’s eval function. The agent will reason that it needs this tool to convert the Celsius temperature it received from the Weather tool into Fahrenheit.

def math_tool(input_str: str) -> str:
        # Defines a simple math tool
        try:
            return str(eval(input_str))
        except Exception:
            return "Sorry, I couldn't compute that."
    
    # Runs the loop for a MySQL based math agent
    math_tool_object = Tool(
        name="Calculator",
        func=math_tool,
        description="Useful for doing math calculations. Input should be a valid Python math expression.",
    )

Putting It All Together: The Agent in Action

First, we need to establish a connection to our MySQL HeatWave instance. We’ll use the mysql-connector-python library to do this. You’ll need to configure your database credentials, including the host IP, user, password, and schema name.

import mysql.connector
    
    # Connect to the database
    mydb = mysql.connector.connect(
        host="127.0.0.1", port=3306,
        user="root", password="",
        database="rag_test", allow_local_infile=True,
        use_pure=True, autocommit=True,
    )
    

With the LLM brain and the tools ready, we assemble them using LangChain’s initialize_agent function. We provide the agent with our list of tools and connect it to the HeatWave LLM.

from langchain.agents import initialize_agent, AgentType
    from mysql.ai.genai import MyLLM
    
    # Bind defaults so they're always passed to the model's _call
    my_llm = MyLLM(mydb).bind(model_id="meta.llama-3.3-70b-instruct")
    
    agent = initialize_agent(
        tools=[math_tool_object, weather_tool_object],
        llm=my_llm,
        agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
        handle_parsing_errors=True,
        max_iterations=2, # prevents loops
        early_stopping_method="generate", # produce best-effort Final Answer if stuck
        verbose=True,
    )

Now for the exciting part! We ask our question: "What is the current weather in Fahrenheit?"

agent.invoke({"input": "What is the current weather in Fahrenheit?"})
    
    > Entering new AgentExecutor chain...
    To find the current weather in Fahrenheit, I first need to get the current weather in Celsius and then convert it to Fahrenheit. 
    
    Action: Weather
    Action Input: 
    Observation: {'location': {'city': 'Redwood City', 'region': 'California', 'country': 'United States', 'country_code': 'US', 'latitude': 37.5331, 'longitude': -122.2486, 'ip': '148.87.23.10', 'source': 'ipapi.co (IP-based, approximate)'}, 'weather': {'time': '2025-10-03T13:15', 'temperature_c': 19.6, 'feels_like_c': 19.2, 'humidity_percent': 60, 'wind_speed_mps': 6.6, 'weather_code': 1, 'source': 'open-meteo.com'}}
    Thought:To convert the temperature from Celsius to Fahrenheit, I can use the formula: Fahrenheit = (Celsius * 9/5) + 32. I will use the Calculator tool to perform this calculation.
    
    Action: Calculator
    Action Input: (19.6 * 9/5) + 32
    Observation: 67.28
    Thought:Thought: I now know the final answer
    Final Answer: The current weather is 67.28°F.
    
    > Finished chain.
    {'input': 'What is the current weather in Fahrenheit?',
     'output': 'The current weather is 67.28°F.'}

The agent “thinks” its way to the answer.

  • Thought: The agent first thinks, “To find the current weather in Fahrenheit, I first need to get the current weather in Celsius and then convert it to Fahrenheit.”
  • Action: It decides to use the Weather tool.
  • Observation: The Weather tool returns a detailed dictionary, including the temperature: temperature_c: 19.6.
  • Thought: The agent now knows the temperature is 19.6°C. It reasons, “To convert the temperature from Celsius to Fahrenheit, I can use the formula: Fahrenheit = (Celsius * 9/5) + 32. I will use the Calculator tool to perform this calculation.”.
  • Action: It calls the Calculator tool with the input (19.6*9/5)+32.
  • Observation: The Calculator tool returns the result: 67.28.
  • Thought: The agent concludes, “I now know the final answer”.
  • Final Answer: The current weather is 67.28°F.

This simple example powerfully illustrates how HeatWave GenAI can be seamlessly integrated into an agentic workflow created with LangChain. By combining an LLM’s reasoning with specialized tools, we can build applications that solve complex, multi-step problems that go far beyond a single prompt. This approach opens the door to creating sophisticated agents that can query live databases, interact with APIs, and perform calculations to provide accurate, real-time answers.

Get Started Today

We invite you to try HeatWave AutoML and GenAI. If you’re new to Oracle Cloud Infrastructure, try Oracle Cloud Free Trial, a free 30-day trial with US$300 in credits.