The capability of language models to generate structured calls to external functions, APIs, or tools — enabling AI systems to interact with databases, execute code, search the web, send emails, and perform actions beyond text generation.
Imagine you have a smart assistant who can’t directly access your calendar, email, or bank account. But you can give them a phone, a computer, and a credit card, and they can use those tools to get things done.
Tool use (or function calling) is how AI models “use tools.” Instead of just generating text, the model can output structured requests like:
search_web(query="weather in Tokyo")send_email(to="boss@company.com", subject="Report", body="...")query_database(sql="SELECT * FROM users WHERE active=true")The model decides when to use a tool, what parameters to pass, and how to incorporate the results into its response.
Tool use extends LLMs from text generators to action executors. The model is given a set of available tools (functions) with descriptions and parameter schemas, and it can choose to invoke them during generation.
How It Works:
Example Flow:
User: "What's the weather in Paris?"
Model: [decides to call weather tool]
Tool Call: get_weather(city="Paris", unit="celsius")
Tool Result: {"temperature": 18, "condition": "cloudy"}
Model: "The weather in Paris is currently 18°C and cloudy."
Popular Implementations:
Tool Categories:
Tool use is foundational for building practical AI applications:
Enterprise Applications:
Strategic Benefits:
Security Considerations:
A personal assistant with access to your phone, computer, and credit card. You say “Book me a flight to London.” The assistant uses the airline website (tool) to search for flights, your calendar (tool) to check availability, and your credit card (tool) to make the purchase. Each tool is a specific capability the assistant can invoke to complete the task.
# Tool use with OpenAI function calling
from openai import OpenAI
import json
client = OpenAI()
# Define available tools
tools = [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string", "description": "City name"},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["location"]
}
}
}
]
# User request
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "What's the weather in Tokyo?"}],
tools=tools,
tool_choice="auto"
)
# Check if model wants to call a tool
message = response.choices[0].message
if message.tool_calls:
tool_call = message.tool_calls[0]
function_name = tool_call.function.name
arguments = json.loads(tool_call.function.arguments)
print(f"Model wants to call: {function_name}")
print(f"Arguments: {arguments}")
# Output:
# Model wants to call: get_weather
# Arguments: {"location": "Tokyo", "unit": "celsius"}
# In a real application, you would:
# 1. Execute the function
# 2. Send the result back to the model
# 3. Get the final response
Reality: Models can only use tools explicitly defined by developers. They can’t invent new tools or access systems without permission.
Reality: Plugins are a specific implementation (e.g., ChatGPT plugins). Tool use is the general capability; plugins are one way to expose tools to models.