AI & Agents

How to Build Your First AI Agent With Tool Use

A beginner's guide to giving AI the power to actually do things — search the web, look up data, and take action.

Scroll to start

What Is an AI Agent With Tools?

An AI agent is a program that uses an AI (like Claude or GPT) to think through problems and make decisions on its own. Tool use is when you let that AI call extra helpers — like a search engine, a calculator, a weather app, or your email — to actually get things done.

Without tools, an AI can only talk. It can explain how to book a flight, but it cannot book the flight for you. With tools, it can search for flights, compare prices, and even click the buy button. Think of tool use like giving a smart friend a phone and a wallet: suddenly they can do things for you, not just talk about them.

The most common type of tool use is called function calling. The AI does not actually run the function itself — it tells your program which function to call and what to put in. Your program runs the function, gives the result back to the AI, and the AI uses that result in its next thought.

Chat Is Just the Beginning

A chatbot answers questions. An agent with tools gets work done. That is a big deal. With tool use, AI can check today's weather before planning your run, look up a real product on a website, send a meeting invite, run a database query, or post to your social media — all by itself.

This is the difference between a calculator that explains math and a calculator that buys you a new calculator. The first is interesting. The second is useful. Tool use is what turns interesting conversations into actual automation that saves you time and effort.

Almost every cool AI product you have heard of — coding assistants, research agents, customer support bots, the new "AI that browses the web for you" — runs on tool use under the hood. Once you understand it, you can see it everywhere.

💡 Key Insight

The AI itself does not run the tool. It just decides which tool to use and tells your code the tool's name and inputs. Your code runs the tool and gives the answer back. This split — the AI thinks, your code does — is what makes tool use safe and flexible.

The Agent Loop in 4 Steps

Building a tool-using agent is really just setting up a small loop. The AI thinks, decides if it needs a tool, asks your code to run that tool, looks at the result, and decides what to do next. It keeps looping until the task is finished.

Here is the loop your agent will follow, over and over, until the job is done:

The Tool-Use Agent Loop
👀
Read Goal
Look at the user's request
🧠
Think
Decide if a tool is needed
🛠️
Call Tool
Your code runs the tool
Check
Read result, decide next step
repeat until done

You can give the agent as many tools as you want. Each tool has a name, a short description, and a list of inputs it needs. The AI reads those descriptions and picks the right one for the job — almost like a person looking at a toolbox and grabbing the wrench.

A Weather Agent in 30 Lines of Python

Let's build a tiny agent that can answer the question "What's the weather in Toronto?" The agent has one tool: a function that pretends to look up the weather. The AI decides when to call it, and your code does the actual work.

agent.py
# Step 1: define a tool the AI can use
def get_weather(city):
    # In real life, you'd call a weather API    return f"It's 18°C and sunny in {city}."

# Step 2: tell the AI what tools are available
tools = [{
    "name": "get_weather",
    "description": "Get the current weather for a city",
    "parameters": {"city": "string"}
}]

# Step 3: send the user's question to the AI
user_message = "What's the weather in Toronto?"

# The AI thinks and replies: "I should call get_weather('Toronto')"
ai_says = ["get_weather", "Toronto"]

# Step 4: run the tool with the AI's choice
tool_name, tool_input = ai_says
result = get_weather(tool_input)

# Step 5: give the result back to the AI for a final answer
print(f"The weather in Toronto is: {result}")

That is the whole idea. The AI picks the tool, your code runs the tool, and the AI uses the result. Real agents like Claude's tool use or OpenAI's function calling follow this exact same pattern, just with more tools and smarter looping.

Knowledge Check

Test what you learned with this quick quiz.

Quick Quiz — 3 Questions

Question 1
What does "tool use" mean for an AI agent?
Question 2
In a tool-use agent, who actually runs the tool?
Question 3
Why does an AI agent loop "think, call tool, check, repeat" until done?
🏆

You crushed it!

Perfect score on this module.