Tool Use & Function Calling
How agents interact with external tools and APIs.
Tool Use & Function Calling
The difference between a chatbot and an agent is tools. Tools give agents the ability to do things in the real world — not just talk about doing things.
What Are Agent Tools?
A tool is any external capability that an agent can invoke. Think of it like giving an employee access to the company's software:
Common Agent Tools
| Tool Category | Examples | What It Enables |
|---|---|---|
| Web Search | Google, Bing, Perplexity | Finding current information |
| Code Execution | Python, JavaScript | Running calculations, data processing |
| File Operations | Read/write documents | Processing uploads, generating reports |
| APIs | CRM, email, calendar, payment | Interacting with business systems |
| Databases | SQL queries, Airtable | Reading and writing structured data |
| Communication | Email, Slack, SMS | Sending messages to people |
| Memory | Vector stores, knowledge bases | Remembering past interactions and facts |
How Function Calling Works
When you give an agent tools, here's what happens behind the scenes:
- 1.You define the tools: "This agent can search the web, look up customer data, and send emails"
- 2.User sends a request: "Send a follow-up email to John about his order"
- 3.Agent thinks: "I need to look up John's order first, then draft and send an email"
- 4.Agent calls tool 1: Looks up John's order in the database → gets order details
- 5.Agent calls tool 2: Drafts an email using the order details
- 6.Agent calls tool 3: Sends the email via the email API
- 7.Agent responds: "Done! I sent John a follow-up about his order #1234, mentioning the delivery date of March 20."
The key insight: the agent decides which tools to use and in what order based on the request. You don't program each step — you give it tools and let it figure out the workflow.
Tool Design Principles
1. Clear Names and Descriptions
Bad: tool_1()
Good: search_customer_database(customer_name: string)
The agent uses the name and description to decide when to use a tool. If the name is vague, the agent will misuse it.
2. Minimal Scope
Each tool should do one thing. Don't create a "do everything" tool.
3. Error Handling
What happens when a tool fails? Good agents handle errors gracefully:
- •"I couldn't find a customer named 'Jon Smith.' Did you mean 'John Smith'?"
- •"The email service is unavailable. I've saved the draft for you to send later."
4. Guardrails
Tools should have safety limits:
- •A "send email" tool that requires human approval before sending
- •A "database write" tool that can only modify specific fields
- •A "payment" tool with a maximum transaction amount
No-Code Tool Connections
You don't need to write code to give agents tools. Modern platforms handle this:
- •Custom GPTs: Add "Actions" that connect to any API
- •Claude Projects: Attach files and use built-in tools (web search, code, file analysis)
- •Zapier AI: Pre-built connections to 5,000+ apps
- •Make/Integromat: Visual workflow builder with AI steps
The principle is always the same: define what the agent can access, set boundaries, and let it decide when to use each tool.
Security Considerations
When you give agents access to tools, you're giving them capabilities. Be thoughtful:
- •Principle of least privilege: Only give access to what's needed for the task
- •Read before write: Start with read-only access, add write access when you trust the agent
- •Audit logging: Track every tool invocation for review
- •Rate limits: Prevent runaway agents from making thousands of API calls
- •Sensitive data: Never give agents access to credentials, encryption keys, or admin panels
Exercises
0/3Think of an agent you want to build. List 3-5 tools it would need, following the tool design principles: give each tool a clear name, a description, required inputs, and expected output. Also list one guardrail for each.
Hint: Example: search_product_catalog(query: string) - Searches the product database and returns matching items with prices. Guardrail: Returns max 20 results per search.
What does the "principle of least privilege" mean for AI agents?
In function calling, who decides which tools to use and in what order?