AI Agents: Turning LLMs From Thinkers into Doers (Build Along!)

Suman SarkarSuman Sarkar
8 min read

Hey there, fellow tech enthusiasts! Ever caught yourself daydreaming about having a digital buddy like Jarvis from Iron Man? You know, someone who’s always got your back, whether it’s checking the weather, managing your schedule, or even giving you a heads-up about that meeting you almost forgot. Well, guess what? AI agents are here to make that dream a reality—and they’re way cooler than you might think. Think of them as your personal mini Jarvis, ready to help you tackle everyday tasks with a sprinkle of Tony Stark-level flair.

In this article, we’re going to explore what AI agents are, why they’re so awesome, and how you can build your very own weather agent (yep, just like having Jarvis check the forecast for you). Don’t worry if you’re not a tech genius—we’ll keep it fun, simple, and totally relatable. By the end, you’ll not only understand agents better but also feel like you’re ready to step into Tony’s workshop and build your own digital sidekick. Let’s suit up and get started!

What Are AI Agents? (Hint: Think Jarvis!)

Imagine this: You’re getting ready for a big day, and you casually ask, “Hey, what’s the weather like in Mumbai?” Instead of scrambling to check your phone, your AI agent jumps into action. It thinks, “Hmm, I need to fetch the weather for Mumbai,” grabs the info, and replies, “It’s sunny with a high of 43°C—don’t forget your sunscreen!” That’s the magic of AI agents: they’re proactive, smart, and always ready to help.

Now, you might be wondering, “Wait, isn’t that just a fancy chatbot?” Not quite! While chatbots are great at answering questions, AI agents are like chatbots with superpowers. They can:

  • Understand what you need.

  • Plan how to get it done.

  • Take action (like calling a weather service).

  • Observe the result and adjust accordingly.

It’s like having a mini detective—or, in this case, a mini Jarvis—working for you. Just like how Jarvis doesn’t just answer Tony’s questions but anticipates his needs, manages his suit, and even cracks a joke or two, AI agents are designed to be proactive and context-aware. They’re not just reacting; they’re thinking ahead.

Building Your Own Weather Agent (A Mini Jarvis for Weather!)

Alright, now for the fun part: let’s build a simple weather agent. This little guy will take a city name, fetch the current weather, and tell you what it’s like outside. It’s like giving your agent a tiny piece of Tony’s tech—specifically, Jarvis’s weather radar.

What You’ll Need:

  • A tool to fetch weather data (we’ll use a super simple weather API called wttr.in).

  • An AI agent powered by a language model (like OpenAI or Gemini) that can plan, act, and observe based on your query.

Don’t worry about the technical stuff just yet—we’ll walk through it step by step, and you don’t need to be a coding wizard to follow along.

How Does the Weather Agent Work? (It’s Like Jarvis in Action!)

Our weather agent follows a straightforward but powerful workflow, kind of like how Jarvis operates:

  1. Plan: Understand your query and decide what to do. (E.g., “The user wants the weather in Mumbai. I should use the weather tool.”)

  2. Action: Call the right tool (in this case, get_weather) with the correct input (the city name).

  3. Observe: Look at the result from the tool.

  4. Output: Share the final answer with you, maybe with a friendly reminder to stay hydrated if it’s hot!

It’s like watching Jarvis in action: he doesn’t just fetch data; he processes it, makes sense of it, and delivers it in a way that’s helpful and timely.

The Tools We’re Using:

  • get_weather: This is like Jarvis’s weather scanner. It takes a city name and returns the current weather using the wttr.in API.

For now, we’ll focus on get_weather, but imagine the possibilities! You could have your agent check your calendar, send reminders, or even order pizza (okay, maybe not yet, but hey, the future is bright).

  1. Setting Up the Environment

    Let’s setup the project quickly, open your terminal and enter

uv init 
uv add openai or google-genai or anthropic
uv add python-dotenv
uv add requests

In this one we will use openai python sdk.

from openai import OpenAI
from dotenv import load_dotenv
import os
import json
import requests

# Load environment variables from .env file
load_dotenv()

GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
GEMINI_API_URL = os.getenv("GEMINI_API_URL")

# Initialize OpenAI API client
client = OpenAI(
    api_key=GEMINI_API_KEY,
    base_url=GEMINI_API_URL,
)

Explanation: This section prepares the groundwork for our weather agent. We import essential libraries: OpenAI to interact with the AI model, dotenv and os to securely load API keys from a .env file, json to handle data formatting, and requests to fetch weather data from an online API. After importing, we load the API key and URL from the environment and set up the OpenAI client to communicate with the AI model.

2. Defining the Tools

def get_weather(city: str):
    print(f"Tool called: get_weather with input: {city}")
    url = f"https://wttr.in/{city}?format=%C+%t"
    response = requests.get(url)
    if response.status_code == 200:
        return f"The weather in {city} is: {response.text}"
    else:
        return "Error fetching weather data"

available_tools = {
    "get_weather": {
        "function": get_weather,
        "description": "Takes a city name as an input and returns the current weather of the city.",
    }
}

Explanation: Here, we define the tools our agent can use. The get_weather function fetches weather data for a given city using the wttr.in API, returning a simple string like "Sunny +25°C" or an error message if it fails. The available_tools dictionary lists these tools, linking their names to their functions and descriptions, so the agent knows what’s available.

3. Setting Up the AI Agent

system_prompt = """
You are a Helpful AI assistant specialized in resolving user queries.
You follow a start, plan, action, observe cycle.
For the given user query and available tools, plan the step-by-step execution.
Based on the plan, select the relevant tool from the available tools.
Perform an action to call the tool, wait for the observation, and resolve the user query based on the observation.

Rules:
- Follow the Output JSON format.
- Perform one step at a time and wait for the next input.
- Carefully analyze the user query.

Output JSON format:
{
    "step": "string",
    "content": "string",
    "function": "the name of the function if the step is action",
    "input": "the input parameter for the function"
}

Available tools:
- get_weather: Takes a city name as input and returns the current weather of the city.
- run_command: Takes a command as input to execute on the system and returns the output.

Example:
User query: "What is the current weather in Mumbai?"
Output: { "step": "plan", "content": "The user is interested in weather data for Mumbai." }
Output: { "step": "plan", "content": "From the available tools, I should call get_weather." }
Output: { "step": "action", "function": "get_weather", "input": "Mumbai" }
Output: { "step": "observe", "output": "43 Degree Celsius" }
Output: { "step": "output", "content": "The weather in Mumbai seems to be 43 degrees." }
"""

messages = [
    {"role": "system", "content": system_prompt},
]

Explanation: This section configures the AI agent. The system_prompt is a detailed instruction set telling the agent how to behave: it must plan its steps, use tools, observe results, and output answers in a specific JSON format. It also lists the available tools and provides an example. The messages list starts with this prompt, serving as the conversation’s foundation, which we’ll build on with user inputs.

4. The Main Interaction Loop

while True:
    user_query = input("user > : ")
    messages.append({"role": "user", "content": user_query})

    while True:
        response = client.chat.completions.create(
            model="gemini-2.5-flash-preview-04-17",
            response_format={"type": "json_object"},
            messages=messages,
        )

        response_content = json.loads(response.choices[0].message.content)

        output = response_content
        messages.append({"role": "assistant", "content": json.dumps(output)})

        if output["step"] == "plan":
            print(f"🧍🏻‍♂️: {output.get('content')}")
            continue

        if output["step"] == "action":
            tool_name = output.get("function")
            tool_input = output.get("input")

            if tool_name in available_tools:
                result = available_tools[tool_name]["function"](tool_input)
                observation = json.dumps({"step": "observe", "output": result})
                messages.append({"role": "assistant", "content": observation})
            else:
                error_msg = json.dumps({"step": "observe", "output": f"Error: Tool '{tool_name}' not found."})
                messages.append({"role": "assistant", "content": error_msg})

        if output["step"] == "output":
            print(f"🤖: {output.get('content')}")
            break

# now in you terminal enter "uv run <file_name.py>"

Explanation: This is where the agent comes to life. The outer while True loop keeps the conversation going, prompting the user for input (e.g., "What’s the weather in Mumbai?") and adding it to messages. The inner loop processes the query step by step:

  • It sends messages to the AI model and gets a JSON response.

  • If the step is "plan," it prints the agent’s thoughts (e.g., "I’ll use get_weather").

  • If "action," it calls the specified tool (like get_weather), adds the result as an "observe" message, and continues.

  • If "output," it prints the final answer (e.g., "It’s sunny in Mumbai!") and exits the inner loop, ready for the next query.

Why You’ll Love Having Your Own Digital Jarvis

So, why bother with AI agents? Here are a few reasons:

  • Save Time: Let your agent handle tasks while you focus on the important stuff (like planning your next adventure).

  • Reduce Errors: Agents follow instructions precisely, so they’re less likely to mess up.

  • Handle the Boring Stuff: Checking the weather every day? Yawn. Let your agent do it.

  • Learn and Have Fun: Building agents is a great way to explore AI and feel like you’re in Tony Stark’s lab.

Plus, it’s just plain cool to have a digital sidekick. Who wouldn’t want their own Jarvis?

Conclusion: The Future Is Agentic (And You’re Part of It!)

AI agents are more than just a trend—they’re shaping how we interact with technology, making it smarter, more helpful, and a lot more fun. Just like Jarvis is always there for Tony, your AI agent can be there for you, handling the small stuff so you can focus on what matters.

So, whether you’re checking the weather, automating your routine, or just exploring the world of AI, remember: you’ve got the power to build your own digital sidekick. Now, go ahead and make Tony proud!

Happy coding, and may your weather always be sunny (or at least predictable)!

Until next time! 🙌

0
Subscribe to my newsletter

Read articles from Suman Sarkar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Suman Sarkar
Suman Sarkar