Tool calling (also called function calling) is how AI models execute actions in the real world. Instead of just generating text, the model outputs a structured request to call a specific function with specific parameters.
How it works
User: "What's the weather in Tokyo?"
β
Model decides to call: get_weather(city="Tokyo")
β
Your code executes the function
β
Result: {temp: 22, condition: "sunny"}
β
Model: "It's 22Β°C and sunny in Tokyo."
The model doesnβt execute the function itself β it tells YOUR code what to call. You execute it and return the result.
Why it matters
Tool calling is the foundation of:
- MCP β the standard protocol for AI tool integration
- AI agents β agents that read files, run tests, deploy code
- RAG β retrieving documents before generating answers
- AI coding tools β Claude Code, Aider, Cursor
Example (OpenAI format)
response = client.chat.completions.create(
model="gpt-5.4",
messages=[{"role": "user", "content": "Check if my server is up"}],
tools=[{
"type": "function",
"function": {
"name": "check_server",
"parameters": {
"type": "object",
"properties": {"url": {"type": "string"}},
"required": ["url"]
}
}
}]
)
Learn more
- Tool Calling Patterns β sequential, parallel, conditional, recursive
- MCP Complete Guide β the standardized protocol for tool integration
- How to Build an AI Agent β agents that use tools autonomously
- What is Prompt Engineering? β crafting instructions for AI
Related: Best Hosting for AI Projects