Build AI Agents


Can a LLM predict weather of your area ?
As we know, LLM works on pre-trained data and does not have real-time data. It cannot provide answers based on live data. Therefore, we need an agent to help get live information.
message = [
{"role": "user", "content": "What is the weather like todayin Bengaluru?"},
]
result = client.chat.completions.create(
model="gpt-4o",
messages=message,
temperature=0.5,
max_tokens=100,
top_p=1.0
)
print(result.choices[0].message.content
Output:
I'm unable to provide real-time weather updates. For the most current weather
information in Bengaluru, please check a reliable weather website or app.
How to solve above problem?
Step 1: You have to create a tool and create a get_weather method.
Step 2: You have to create a system prompt.
avaiable_tools = { "get_weather": { "fn": get_weather, "description": "Takes a city name as an input and returns the current weather for the city" }, } def get_weather(city:str): """ Function to get the weather for a given city. """ # This function would typically call a weather API # For demonstration, we will return a dummy response return f"The weather in {city} is sunny with a high of 25°C."
system_prompt = """ You are helpful AI assistant who is specialized in resolving user query. You work on start, plan, action, observe mode. For the given user query and available tools, plan the step by step execution, based on the planning, Select the relvant tool and available tool. and based on the tool selection you perform an action to call the tool. Wait for the observation and based on the observation from the tool call resolve query. Rules: - Follow the Output JSON Format. - Always perform one step at a time and wait for next input. - Carefully analyze the user query. Output JSON Format: {{ "step": "string", "content": "string", "function": "The name of function if the step is action", "input" : "The input parameter for the function", }} Available Tools: - get_weather: Takes a city name as an input and returns the current weather for the city - run_command: Takes a command as input to execute on system and returns ouput Example: user query : What is the weather like today in Bengaluru? Output: {{"step": "plan", "content": "The user is interested in weather data of Bengaluru." }} Output: {{"step": "plan", "content": "From the available tools I should have call get_weather" }} Output: {{"step": "action", "function": "get_weather", "input": "Bengaluru"}} Output: {{"step": "observe", "content": "sunny with a high of 25°C."}} Output: {{"step": "output", "content": "The weather for bengaluru seems to be sunny with 25°C" }} ""
🧠: The user wants to know the weather of Bengaluru and prefers a humorous response. 🧠: From the available tools, I should call get_weather to obtain the current weather data for Bengaluru. 🔨 Tool Called: get_weather bengaluru 🤖: The weather in Bengaluru is as sunny as a smile, at a toasty 25°C! It's the perfect day to put on your shades and work on that sun tan, or maybe just your screen tan if you're feeling lazy!
🌟 Summary:
You type a question → The assistant thinks about it → It picks the right tool → It runs the tool → It reads the result → It gives you an answer.
🔄 Step-by-step flow:
1️⃣ You type a question →
Example:
> What’s the weather in Paris?
You type this into the terminal → the program saves it in a list of messages.
2️⃣ Assistant plans (🧠) →
The assistant first analyzes your question.
It figures out:
What are you asking?
What tool should it use to get the answer?
Example:
🧠: The user is interested in weather data of Paris.
🧠: From the available tools I should call get_weather.
This “thinking” comes from the AI assistant (using GPT-4o).
3️⃣ Assistant takes action →
It calls the right tool.
In this example, it uses the get_weather
tool.
Example:
get_weather("Paris")
4️⃣ Program runs the tool →
- It sends a web request:
https://wttr.in/Paris?format=%C+%t
- The weather service replies, e.g.:
Partly cloudy +18°C
5️⃣ Assistant observes (👀) →
It looks at the result and notes it.
Example:
🧠: The weather in Paris is Partly cloudy +18°C.
6️⃣ Assistant outputs final answer (🤖) →
It gives you a friendly reply:
🤖: The weather for Paris seems to be Partly cloudy +18°C.
7️⃣ Loop repeats →
The assistant waits for your next question. You can keep chatting, or exit when you’re done.
⚙ Behind-the-scenes:
It remembers past messages so it knows the conversation context.
It uses JSON (a structured data format) to handle all steps cleanly.
The program only moves forward when each step is finished — this keeps the conversation structured and logical.
✅ Flow chart :
Assistant Plans → Assistant Picks Tool → Tool Runs → Assistant Reads Result → Assistant Replies → You...
You can visit the repo to get the code.
Subscribe to my newsletter
Read articles from Himandri Mallick directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
