What is function calling (tool use) in AI?
Function calling β also called tool use β is how a language model reaches beyond text and gets real work done. Instead of guessing an answer, the model outputs a structured request to run a specific function you've defined, like get_weather(city) or search_flights(from, to, date). Your code runs it, hands the result back, and the model uses that real data to continue.
How does function calling work?
You give the model a list of tools it's allowed to use, each with a name, a description, and the inputs it expects. When a request needs one, the model doesn't invent the answer β it returns a structured message (usually JSON) naming the function and the arguments to pass. The model itself never runs anything; your program executes the call, then feeds the output back so the model can respond or take the next step.
A typical exchange looks like this:
- You ask, "What's the weather in Tokyo?"
- The model replies with a call:
get_weather(city: "Tokyo"). - Your code runs that function and returns the real data.
- The model turns the data into a plain-language answer.
Why does structured output matter?
The magic is that the model produces a clean, machine-readable request instead of loose prose. Because the arguments come back in a fixed shape, your code can act on them reliably β no fragile parsing of a sentence. That structure is what lets an LLM connect safely to APIs, databases, and other software.
Why is this the mechanism behind agents?
Function calling is the bridge between thinking and doing. An agent's act-observe loop runs on it: each "action" the agent takes is a function call, and each "observation" is the result coming back. Chain those together and a model can complete real tasks.
- Access live data β look up prices, records, or the current time instead of relying on stale training.
- Take actions β send an email, create a ticket, update a row, run code.
- Stay grounded β answer from real results rather than guessing.
Without tool use, an LLM is stuck describing what it would do. With it, the same model can actually do it β which is exactly what turns a chatbot into an agent.
Related Questions
Related News
More in AI Fundamentals