How Tools Turn GPT into an Agent: A Hands-On Guide

Sai Charan B MSai Charan B M
5 min read

Introduction: Why Tools Matter

Language models like GPT are powerful. They can write essays, summarize research, translate languages, and even crack jokes. But as amazing as they are, they have one big limitation: they don’t know anything beyond what they were trained on. Ask GPT for the current weather or today’s stock prices, and it’ll politely tell you it can’t help. Not because it’s lazy, but because it simply wasn’t built to browse the real world on its own.

That’s where tools come in.

Think of GPT as a brilliant thinker trapped in a library. It knows a lot, but it can’t make phone calls, fetch live data, or edit a real file—unless you hand it the right tools and tell it how to use them. With the right combination of functions (APIs) and smart instructions (system prompts), we can turn GPT into something more than just a chat companion—we can make it agentic. That means it can decide when to use a tool, act on real-world data, and deliver responses based not just on what it knows, but on what it can do.

In this post, we’ll start with a simple problem: asking GPT about the weather, and show how, with a little tooling, it goes from “I don’t know” to giving you real-time forecasts. Then, we’ll scale that idea up with a real-world example: CodeBuddy, a command-line tool powered by GPT that can write, modify, and analyze code like a helpful AI developer.

Let’s explore how a few lines of code and the right system prompt can turn GPT from an assistant into an agent.

The Limits of GPT Alone

GPT may feel intelligent, but it has a major blind spot: it can’t access real-time information or interact with the outside world on its own.

Ask it, “What’s the weather in Delhi right now?”, and you’ll likely get a polite response like:

“I’m sorry, I don’t have access to real-time data.”

That’s not a bug—it’s by design. GPT’s knowledge is frozen at the time it was trained. It doesn’t know what’s happening today, can’t fetch live data, and can’t perform real actions unless you explicitly give it that ability.

So while GPT is a great thinker, it’s not yet a doer. To change that, we need to give it tools.

The Power of Tools

To unlock GPT’s true potential, we can equip it with tools—custom functions it can call when needed.

Let’s say we define a simple function to fetch live weather data:

def get_weather(city: str) -> str:
    url = f"http://api.weatherapi.com/v1/current.json?key={{YOUR_API_KEY}}&q={city}"
    response = requests.get(url)
    if response.status_code == 200:
        return f"The weather in {city} is {response.text}."
    return "Something went wrong"

Now, we pair this tool with a system prompt that tells GPT how to think like an agent—planning, selecting the right function, and responding step by step:

SYSTEM_PROMPT = """
You are a helpful AI assistant.

You operate in the following steps:
1. Plan based on user query
2. If needed, use available tools
3. Wait for the tool’s response (observation)
4. Deliver the final answer

Rules:
- Always output one step at a time.
- Use this function if needed:
  - get_weather: Takes a city name and returns the current weather

Output format:
{
  "step": "string",
  "content": "string",
  "function": "string (optional)",
  "input": "string (optional)"
}

 Example:
    User Query: What is the weather of new york?
    Output: {{ "step": "plan", "content": "The user is interseted in weather data of new york" }}
    Output: {{ "step": "analyse", "content": "From the available tools I should call get_weather" }}
    Output: {{ "step": "action", "function": "get_weather", "input": "new york" }}
    Output: {{ "step": "observe", "output": "12 Degree Cel" }}
    Output: {{ "step": "output", "content": "The weather for new york seems to be 12 degrees." }}
"""

Now, when you ask:

“What’s the weather in Bengaluru?”

GPT responds intelligently:

  1. Plans what to do

  2. Picks the get_weather tool

  3. Calls it with "Bengaluru"

  4. Waits for the result

  5. Returns the final weather update

With just one function and a well-structured prompt, we’ve turned GPT from a static model into an agent that can interact with the real world.

Building CodeBuddy: GPT + Tools + Prompting

With all the learning around Agentic AI — tools and prompts. I’ve started building my own experiment: CodeBuddy.


🛠️ What Is CodeBuddy?

CodeBuddy is a CLI-based AI agent designed to create and modify software projects through natural language commands. It's powered by an LLM (like GPT-4) and a set of custom-built tools that allow it to:

  • Execute Linux shell commands

  • Create project files

  • Ask intelligent follow-up questions to gather requirements

  • Modify existing files based on feedback

In essence, it acts like an AI junior developer, capable of turning conversational instructions into working code.


⚙️ How It Works (Current Version)

In its current version, CodeBuddy:

  • Begins with a natural conversation to understand your project needs

  • Uses shell tools to scaffold files and directories

  • Generates code using GPT

  • Supports project modification — you can ask it to change colors, themes, file logic, etc.

📝 Example Use Case

I asked CodeBuddy to build a note-taking app.

  • It created the full project structure.

  • Upon request, it changed the theme to dark mode.

  • All of this was done through simple chat-like prompts.

(Screenshots attached below show this interaction in action.)


🧩 What’s Next?

This is just the beginning. The roadmap includes:

  • Adding more tools to give the agent deeper project context

  • Letting it analyze existing codebases

  • Enabling more advanced code refactoring and debugging, and more


🔗 Try It Yourself

If you're reading this from the future (👋 hello time traveler), you can find the latest version of the project on GitHub:

👉 github.com/saicharanbm/codeBuddy

0
Subscribe to my newsletter

Read articles from Sai Charan B M directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Sai Charan B M
Sai Charan B M