AI Dictionary of Terms

Tool Use / Function Calling

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.

The Simple Version

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:

The model decides when to use a tool, what parameters to pass, and how to incorporate the results into its response.

Detailed Explanation

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:

  1. Tool Definition: Developer defines available tools with names, descriptions, and parameter schemas (JSON Schema)
  2. Model Invocation: User sends a request that requires a tool
  3. Tool Selection: Model decides which tool to call and generates the parameters
  4. Execution: System executes the tool (API call, database query, etc.)
  5. Result Integration: Tool results are fed back to the model
  6. Final Response: Model generates a response incorporating tool results

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:

Key Characteristics

Business Context

Tool use is foundational for building practical AI applications:

Enterprise Applications:

Strategic Benefits:

Security Considerations:

Real-World Analogy

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.

Code Example

# 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

Common Misconceptions

Sources & Further Reading