// How AI talks to external tools, APIs, and the real world
๐ก The core idea: By default, an AI only produces text โ it can't check the weather, look things up, or send emails. Function calling lets you tell the AI: "Here are tools you can use." The AI decides when to use a tool, calls it with the right inputs, reads the result, and then answers. It's like giving a clever assistant access to a toolbox.
Watch an AI use a real tool
0 / 5 steps
You describe your tool in JSON so the AI knows what it does and what inputs it takes:
{ "name": "get_weather", "description": "Get the current weather for a city. Use when the user asks about weather.", "parameters": { "type": "object", "properties": { "city": { "type": "string", "description": "City name, e.g. 'London' or 'New York'"
}, "unit": { "type": "string", "enum": ["celsius", "fahrenheit"], "description": "Temperature unit"
}
}, "required": ["city"]
}
}
How the AI uses this: The AI reads the description to know when to call the tool. It reads the parameters to know what to send. The AI never sees your actual code โ just this JSON contract. You run the actual function on your side and send the result back.
search_web(query)
Search the internet for current information
send_email(to, body)
Send an email on the user's behalf
run_python(code)
Execute Python code and return results
query_database(sql)
Run a SQL query against your database
The big idea: AI + tools = agent
Without function calling, an AI only produces text. With function calling, an AI can take actions in the world โ search the internet, read files, write to a database, call any API. This is what transforms an AI chat interface into an AI agent that can actually do things for you.
AI DECIDES WHEN TO CALLYOU DECIDE WHAT TOOLS EXISTYOU RUN THE ACTUAL CODE