Tool Calling: The Boring API Feature That Makes AI Agents Actually Work
You've seen the demos. An AI agent books your flight, updates your CRM, sends emails, and reschedules your calendar. Impressive, right? But here's what those demos don't tell you: none of that magic happens without tool calling, the most unglamorous feature in the LLM API stack.
Tool calling (also called function calling) is the bridge between language models and the real world. Without it, your AI can write beautiful prose about sending an email but can't actually click send. It's the plumbing. The infrastructure. The thing nobody talks about at conferences but everyone needs to understand.
Let's give credit where it's due and walk through how this actually works.
Table of Contents
- What Tool Calling Actually Does
- The Tool Call Loop: A Simple Walkthrough
- Common Schema Design Mistakes
- Why This Matters More Than You Think
- What's Next for Tool Calling
What Tool Calling Actually Does
Here's the problem: language models generate text. That's it. They predict the next token based on previous tokens. When you ask GPT-4 to check the weather, it doesn't connect to a weather API. It just writes plausible-sounding text about checking weather.
Tool calling solves this by letting the model say, "I need to call this specific function with these specific parameters." Your code then executes that function and feeds the result back to the model.
Analogy: Think of the LLM as a really smart intern who can read, write, and make decisions, but has no arms. Tool calling is you agreeing to be their arms. They tell you exactly what to do ("click this button, type these words"), you do it, and you report back what happened.
The model doesn't execute anything. It just returns structured JSON saying what it wants to execute. Your application code handles the actual execution.
The Tool Call Loop: A Simple Walkthrough
Let's walk through a real example. You're building an agent that can check email and reply. Here's what actually happens:
Step 1: Define Your Tools
You tell the API what functions are available:
{
"name": "get_emails",
"description": "Retrieves unread emails from inbox",
"parameters": {
"type": "object",
"properties": {
"limit": {
"type": "number",
"description": "Maximum number of emails to retrieve"
}
}
}
}
This schema tells the model: "You can call this function. Here's what it does and what parameters it accepts."
Step 2: Send the Initial Request
User says: "Check my email and tell me if anything urgent came in."
You send this to the API along with your tool definitions. The model doesn't see your actual inbox. It just sees the message and knows it has a get_emails tool available.
Step 3: Model Requests a Tool Call
The API response looks like this:
{
"role": "assistant",
"content": null,
"tool_calls": [{
"function": {
"name": "get_emails",
"arguments": "{\"limit\": 10}"
}
}]
}
Notice: content is null. The model isn't generating text yet. It's requesting permission to call a function.
Step 4: Your Code Executes the Function
This is where you write actual code:
if tool_call.function.name == "get_emails":
args = json.loads(tool_call.function.arguments)
emails = your_email_client.get_unread(limit=args["limit"])
result = json.dumps(emails)
You call your email API, get real data, and format it as a string.
Step 5: Send the Result Back
You append a new message to the conversation:
{
"role": "tool",
"tool_call_id": "call_abc123",
"content": "[{subject: 'Urgent: Server down', from: 'ops@company.com'}]"
}
Now the model can see what actually happened.
Step 6: Model Generates Final Response
With the real email data, the model generates: "You have one urgent email from ops@company.com about a server being down."
Here's the full loop visualized:
This loop can repeat. The model might call multiple tools or call the same tool multiple times based on what it learns.
Common Schema Design Mistakes
Now that you understand the loop, let's talk about where developers mess up. These mistakes break the loop or make it unreliable.
Mistake 1: Vague Descriptions
Bad:
{
"name": "search",
"description": "Search for stuff"
}
Good:
{
"name": "search_documents",
"description": "Searches company documents by keyword. Returns document titles, snippets, and URLs. Use this when user asks about internal company information."
}
The model uses your description to decide when to call the function. Be specific. Include use cases.
Mistake 2: Missing Parameter Constraints
Bad:
{
"date": {
"type": "string"
}
}
Good:
{
"date": {
"type": "string",
"description": "Date in YYYY-MM-DD format",
"pattern": "^\\d{4}-\\d{2}-\\d{2}$"
}
}
Constrain your inputs. The model will try to match the pattern, reducing errors.
Mistake 3: Too Many Tools at Once
If you give the model 50 tools, it gets confused about which one to use. Start with 5 to 10 well-designed tools. Group related functions.
Instead of: create_task, update_task, delete_task, list_tasks, get_task, archive_task
Consider: manage_task with an action parameter.
Mistake 4: Not Handling Tool Call Failures
Your email API will fail sometimes. Your code needs to handle this:
try:
result = get_emails(limit=10)
except Exception as e:
result = f"Error retrieving emails: {str(e)}"
Return the error as the tool result. Let the model see it failed and decide what to tell the user.
Comparison: Good vs. Bad Tool Schemas
| Aspect | Bad Schema | Good Schema |
|---|---|---|
| Description | "Gets data" | "Retrieves user profile data including name, email, and subscription status" |
| Parameters | type only | type, description, format, constraints |
| Error handling | Crashes on failure | Returns error message as string |
| Naming | Generic (get, search) | Specific (get_user_profile, search_help_docs) |
Why This Matters More Than You Think
Tool calling is the difference between a chatbot and an agent. A chatbot talks. An agent acts.
Every demo you've seen that shows an AI "doing" something relies on this feature. Booking flights? Tool calling the airline API. Updating spreadsheets? Tool calling the Google Sheets API. Sending Slack messages? You guessed it.
But here's what most demos don't show: the bugs. The edge cases. The times when the model calls the wrong tool or formats the arguments incorrectly.
Good schema design reduces these failures. Clear descriptions help the model choose correctly. Proper constraints prevent malformed requests. Error handling keeps the loop running even when things break.
One more thing: security matters here. If an agent has access to a tool that can delete data or send emails externally, you need guardrails. Human-in-the-loop approval for sensitive actions. Rate limiting. Audit logs. The boring stuff that prevents your helpful agent from becoming a liability.
What's Next for Tool Calling
The industry is evolving beyond simple function calling. The Model Context Protocol (MCP) aims to standardize how models interact with external systems. Instead of every developer writing custom tool schemas, MCP provides a common language.
Some vendors are experimenting with "code mode," where instead of returning structured tool calls, the model writes and executes code directly. This is more flexible but also riskier.
But for now, standard tool calling is the foundation. Master this before chasing the next thing.
Conclusion: Respect the Plumbing
Tool calling isn't exciting. It won't get you on stage at a conference. But it's the foundational API feature that makes every impressive agent demo actually work.
Understand the loop: define tools, send context, handle tool requests, execute functions, return results, let the model respond. Get your schemas right: clear descriptions, proper constraints, good error handling. Start small: a few well-designed tools beat dozens of vague ones.
The next time you see an agent demo, remember: there's someone behind the scenes who got the boring plumbing right. Now you know how to be that person.