🛠️ Tool Use: Teaching AI to Use Its Superpowers
The Story of Alex the AI Assistant
Imagine you have a super-smart friend named Alex. Alex knows a lot of things, but there’s a problem: Alex can only talk. Alex can’t open doors, check the weather, or send emails.
Now, what if we gave Alex special tools? A key to open doors. A phone to check weather. A computer to send emails.
That’s exactly what Tool Use is in Agentic AI!
We give AI agents tools so they can do things in the real world, not just talk about them.
🎯 What You’ll Learn
We’ll explore 7 magical steps that help AI use tools:
- Tool Definition – What is a tool?
- Tool Schemas – The instruction manual
- Custom Tool Creation – Building your own tools
- Tool Selection – Picking the right tool
- Tool Execution – Using the tool
- Tool Result Processing – Understanding what happened
- Tool Error Handling – Fixing mistakes
Let’s begin our adventure! 🚀
1️⃣ Tool Definition: What is a Tool?
The Toy Box Analogy 🧸
Think of tools like toys in a toy box.
Each toy does something different:
- A toy car can roll
- A puzzle can be solved
- A ball can bounce
For AI, tools are like these toys. Each tool does one specific job.
Real Examples of AI Tools
| Tool Name | What It Does |
|---|---|
get_weather |
Tells you if it’s sunny or rainy |
send_email |
Sends a message to someone |
search_web |
Finds information online |
calculate |
Does math problems |
Simple Definition
A Tool Definition tells the AI:
- Name: What is the tool called?
- Job: What does it do?
- Inputs: What does it need to work?
Tool: get_weather
Job: Tell the weather
Needs: city name
Think of it like this: If you want to use a hammer, you need to know it’s called “hammer” and that it’s for hitting nails!
2️⃣ Tool Schemas: The Instruction Manual 📖
The LEGO Instructions Analogy
Have you ever built a LEGO set? You follow the instruction book, right?
A Tool Schema is like that instruction book. It tells the AI:
- What pieces (inputs) are needed
- What shape they should be
- What you get when you’re done (output)
What’s Inside a Schema?
graph TD A[Tool Schema] --> B[Name] A --> C[Description] A --> D[Parameters] A --> E[Return Type] D --> F[Required Inputs] D --> G[Optional Inputs]
Example: Weather Tool Schema
{
"name": "get_weather",
"description": "Gets weather for a city",
"parameters": {
"city": {
"type": "string",
"required": true
},
"units": {
"type": "string",
"required": false,
"default": "celsius"
}
},
"returns": "Weather information"
}
Breaking it down:
- name: The tool is called
get_weather - city: You MUST tell it which city (required)
- units: You CAN choose celsius or fahrenheit (optional)
Why Schemas Matter
Without a schema, it’s like giving someone LEGO pieces without instructions. Chaos!
With a schema, the AI knows exactly what to do.
3️⃣ Custom Tool Creation: Building Your Own Tools 🔧
The Chef Analogy 👨🍳
A chef doesn’t just use store-bought sauces. A great chef creates their own special recipes!
Similarly, you can create custom tools for your AI. Tools that do exactly what YOU need.
Steps to Create a Custom Tool
graph TD A[1. Decide What It Does] --> B[2. Give It a Name] B --> C[3. Define What It Needs] C --> D[4. Write the Code] D --> E[5. Test It Works]
Example: Creating a Pizza Order Tool
Step 1: Decide the job → Order pizza
Step 2: Name it → order_pizza
Step 3: What it needs:
- Size (small, medium, large)
- Toppings (list)
- Delivery address
Step 4: Write it:
def order_pizza(size, toppings, address):
# Connect to pizza shop
# Send the order
# Return confirmation
return "Pizza ordered!"
Step 5: Test it:
order_pizza("large", ["cheese", "mushrooms"], "123 Main St")
→ "Pizza ordered!"
Key Points for Custom Tools
✅ Keep tools simple – one job per tool
✅ Use clear names – send_email not do_stuff
✅ Define all inputs clearly
✅ Always return something useful
4️⃣ Tool Selection: Picking the Right Tool 🎯
The Toolbox Analogy 🧰
Imagine you need to hang a picture. You open your toolbox and see:
- Hammer ✅ (good for nails!)
- Screwdriver ❌ (wrong tool)
- Wrench ❌ (wrong tool)
You pick the hammer because it matches the job.
How AI Selects Tools
The AI looks at:
- The user’s request – What do they want?
- Available tools – What can I use?
- Best match – Which tool fits?
graph TD A[User: What's the weather?] --> B{Check Available Tools} B --> C[get_weather ✅] B --> D[send_email ❌] B --> E[search_web ❌] C --> F[Selected!]
Example Scenario
User says: “Send a birthday message to Mom”
AI thinks:
get_weather? No, not about weathercalculate? No, not about mathsend_email? YES! This is about sending a message ✅
Smart Selection Tips
The AI uses the tool’s description to decide:
| Tool | Description | Match for “Send birthday message”? |
|---|---|---|
| get_weather | Gets weather info | ❌ No |
| send_email | Sends email messages | ✅ Yes! |
| calculate | Does math | ❌ No |
5️⃣ Tool Execution: Using the Tool ⚡
The Button Press Analogy 🔘
Selecting a tool is like picking a TV remote. But now you need to press the button to actually change the channel!
Tool Execution is when the AI actually runs the tool.
The Execution Flow
graph TD A[Tool Selected] --> B[Gather Inputs] B --> C[Call the Tool] C --> D[Wait for Result] D --> E[Receive Output]
Example: Executing the Weather Tool
User: “What’s the weather in Paris?”
Step 1: Gather inputs
city = "Paris"
units = "celsius" (default)
Step 2: Call the tool
get_weather(city="Paris", units="celsius")
Step 3: Wait for result (The tool connects to a weather service)
Step 4: Receive output
"Paris: 22°C, Sunny ☀️"
Execution in Action
INPUT: "What's the weather in Tokyo?"
↓
TOOL: get_weather(city="Tokyo")
↓
OUTPUT: "Tokyo: 18°C, Cloudy ☁️"
6️⃣ Tool Result Processing: Understanding the Answer 📊
The Translator Analogy 🗣️
When a tool returns a result, it might look like computer code. But users want a friendly answer!
Result Processing is like translating robot-speak into human-speak.
Raw Result vs. Friendly Response
Raw result from tool:
{
"city": "London",
"temp": 15,
"condition": "rainy",
"humidity": 80
}
Processed for user:
“It’s 15°C in London with rainy conditions. Don’t forget your umbrella! ☔”
The Processing Steps
graph TD A[Raw Tool Output] --> B[Extract Key Info] B --> C[Format Nicely] C --> D[Add Helpful Details] D --> E[Return to User]
What Good Processing Does
| Raw Data | Processed Response |
|---|---|
temp: 35 |
“It’s hot! 35°C” |
stock_price: 150.25 |
“The stock is $150.25” |
email_sent: true |
“Your email was sent successfully!” |
Combining Multiple Results
Sometimes AI uses multiple tools and combines results:
Tool 1: get_weather("Paris") → 22°C, Sunny
Tool 2: get_weather("London") → 15°C, Rainy
Combined: "Paris is warmer at 22°C and sunny,
while London is cooler at 15°C with rain."
7️⃣ Tool Error Handling: When Things Go Wrong 🔧
The Flat Tire Analogy 🚗
What happens when a car gets a flat tire? You don’t abandon the car! You fix it or find another way.
Error Handling teaches AI what to do when tools don’t work.
Common Tool Errors
| Error Type | What Happened | Example |
|---|---|---|
| Missing Input | Forgot something | No city name given |
| Invalid Input | Wrong format | “xyz” for a number |
| Tool Unavailable | Service is down | Weather site broken |
| Timeout | Took too long | Slow internet |
How AI Handles Errors
graph TD A[Error Occurs] --> B{What Kind?} B --> C[Missing Input] B --> D[Invalid Input] B --> E[Tool Down] C --> F[Ask User for Info] D --> G[Ask for Correct Format] E --> H[Try Backup Tool or Apologize]
Example: Graceful Error Handling
Scenario: User asks for weather but doesn’t say which city.
Bad response:
“ERROR: MISSING PARAMETER CITY_NAME”
Good response:
“I’d love to check the weather for you! Which city should I look up? 🌍”
Error Handling Best Practices
✅ Never crash – always respond to the user ✅ Be helpful – explain what went wrong simply ✅ Offer solutions – suggest what to do next ✅ Try alternatives – use a backup if available
Example Error Recovery
User: "What's the weather?"
AI: Tool error - no city!
AI Response: "Which city would you like
weather for? You can say something like
'weather in New York' 🌆"
🎉 Putting It All Together
Let’s see the complete journey:
graph TD A[1. Define Tool] --> B[2. Create Schema] B --> C[3. Build Custom Tools] C --> D[4. User Makes Request] D --> E[5. AI Selects Tool] E --> F[6. AI Executes Tool] F --> G{Success?} G -->|Yes| H[7. Process Result] G -->|No| I[8. Handle Error] H --> J[Reply to User] I --> J
Complete Example: The Weather Journey
- Definition:
get_weathertool exists - Schema: Needs city (required), units (optional)
- Custom: We built it to connect to a weather API
- Request: “Is it raining in Seattle?”
- Selection: AI picks
get_weather✅ - Execution:
get_weather(city="Seattle") - Result:
{condition: "rainy", temp: 12} - Processing: “Yes, it’s raining in Seattle! 🌧️ It’s 12°C.”
🌟 Key Takeaways
| Concept | One-Line Summary |
|---|---|
| Tool Definition | Give the tool a name and job |
| Tool Schema | Create the instruction manual |
| Custom Creation | Build exactly what you need |
| Tool Selection | Pick the right tool for the job |
| Tool Execution | Actually run the tool |
| Result Processing | Make the answer user-friendly |
| Error Handling | Handle problems gracefully |
💡 Remember This
Tools give AI agents superpowers. Without tools, AI can only talk. With tools, AI can do things!
Just like how you use different tools for different jobs at home:
- 🔨 Hammer for nails
- 🔧 Wrench for bolts
- 📱 Phone for calls
AI uses different tools for different tasks:
- 🌤️ Weather tool for forecasts
- 📧 Email tool for messages
- 🔢 Calculator for math
You’ve learned how AI becomes a true agent – one that can think AND act! 🚀