Module 2: Tools and function calling · 11 min
How function calling works
You describe each tool to the model: its name, what it does and what inputs it needs. When the model decides to use a tool, it replies with the tool name and the inputs as structured data, such as JSON.
# 1. You describe the tool
tool = {
"name": "get_weather",
"description": "Get today's weather for a city",
"input": {"city": "string"}
}
# 2. The model replies (instead of text):
{"tool": "get_weather", "args": {"city": "Lahore"}}
# 3. Your code runs get_weather("Lahore") and sends the result back.
# 4. The model reads the result and writes the final answer.
Always check the inputs the model gives before running a tool. Treat them like input from any untrusted user.