Function Calling
Giving LLMs abilities
The Problem: AI can talk, but it can't do things in the real world. It can tell you about the weather forecast formula, but it can't actually check today's weather for your city.
The Solution: Teach AI to Use Tools
Function calling is like teaching AI to use a phone. Instead of just talking, it can now "call" different services to get things done. The AI translates your request into a structured output that specifies which tool to invoke -- and that is what powers the ReAct pattern.
Think of it like a waiter in a restaurant:
- 1. : You say: "I'd like a margherita pizza"
- 2. : The waiter understands and writes: order_pizza(type="margherita")
- 3. : The kitchen (tool) receives the order and makes the pizza
- 4. : The waiter brings you the result
The AI "translates" your natural language into a structured function call!
Where Is This Used?
- Smart Assistants: "Set an alarm for 7am"
set_alarm(time="07:00") - Customer Service: "Cancel my order #12345"
cancel_order(id=12345) - Data Analysis: "Show me sales for Q4"
get_sales(quarter=4) - Home Automation: "Turn off the lights"
control_lights(action="off")
Fun Fact: Function calling was a game-changer for AI! Before it, chatbots could only chat. Now they can actually do things — book flights, send emails, control smart homes. It's what makes AI truly useful as an assistant.
Try It Yourself!
Use the interactive demo below to see how AI converts your request into a function call. Watch the magic of translation happen in real time!
🤖 By itself, AI can only generate text. But if you give it descriptions of tools (functions), it can decide when to call them and with what parameters.
Select a tool above to see an example
Function Calling is like giving AI a phone number for a service. AI doesn't do the work itself, it "calls" the right function and uses its response. This lets you connect AI to databases, APIs, file systems — anything!
You are an assistant with access to tools.
When the user asks for something that requires a tool:
1. Identify which tool is needed
2. Call it with correct parameters
3. Use the result to answer
Available tools are provided in the tools parameter.This prompt explains to the model that it has access to tools and how to use them.
{
"name": "get_weather",
"description": "Get current weather in a city",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name"
},
"units": {
"type": "string",
"enum": ["celsius", "fahrenheit"]
}
},
"required": ["city"]
}
}JSON Schema describes the function parameters: which fields are required, what data types are accepted.
- •Use clear descriptions: AI needs to understand when to use each tool
- •Specify required parameters via "required" in JSON Schema
- •Add example values in description for better understanding
- •Test your prompts: verify that AI correctly selects and calls functions
Try it yourself
Interactive demo of this technique
What is the current weather in Paris?
Paris usually has a mild climate. Right now it is probably around 18°C and cloudy.
Calling a tool to get current data:
→ get_weather("Paris") ← { "temp": 12, "condition": "rain", "humidity": 85, "wind": "15 km/h" }
Currently in Paris it is 12°C, rainy, humidity 85%, wind 15 km/h. I recommend taking an umbrella!
Without tools the model is forced to "guess" the weather using general knowledge. Function Calling enables getting accurate real-time data.
Create a free account to solve challenges
3 AI-verified challenges for this lesson
This lesson is part of a structured LLM course.
My Learning Path