Function Calling
What is it?
Function calling lets a language model decide to use external tools or functions you provide, by outputting a structured request your code can run.
Explain like I'm 5
Why was it created?
Models alone can't fetch live data or take actions. Function calling was created so they can reliably ask your code to do those things.
Where is it used?
- AI agents and assistants
- Fetching live data
- Triggering actions in apps
- Connecting models to APIs
Why should developers care?
It's the foundation of AI agents and tool-using assistants, so it's central to building capable AI features.
How does it work?
You describe available functions and their inputs to the model. When useful, the model returns a structured call (function name plus arguments); your code runs it and feeds the result back so the model can continue.
Real-world example
Asked 'what's the weather in Paris?', the model returns a call like getWeather(city='Paris'); your code fetches real data and the model answers with it.
Common use cases
- Tool use in agents
- Live data lookups
- Structured output
- Automating actions via APIs
Advantages
- Connects models to real tools/data
- Structured, reliable requests
- Foundation for agents
- Keeps the model grounded in real results
Disadvantages
- You must implement and secure the functions
- Model may call the wrong tool
- Adds round-trips and latency
- Requires validating arguments
When should you use it?
When a model needs live data or to perform actions beyond generating text.
When should you avoid it?
For pure text generation that needs no external data or actions.
Alternatives
Related terms
Interview questions
Beginner
- What is function calling?
- Why would a model need to call a function?
Intermediate
- What does the model return when it calls a function?
- How does the result get back to the model?
Senior
- How do you secure and validate function calls?
- How does function calling enable agents?
Common misconceptions
- "The model runs the function itself" — it only requests the call; your code actually executes it.
- "Function calling always picks the right tool" — it can choose wrong, so validate and guard.
Fun facts
- Function calling is what turns a chat model into a tool-using agent.
- The model outputs a structured request, not free text, so your code can parse it reliably.
Timeline
- 2020s — Function/tool calling becomes a standard LLM capability
Learning resources
Quick summary
Function calling lets a model request external tools via structured calls your code runs, grounding it in real data and enabling agents.
Cheat sheet
- Model requests a tool call
- Your code runs it, returns result
- Structured, not free text
- Foundation of agents