Lesson 11.2 · 25 min · video lesson
Function Calling: Giving LLMs Tools to Act on the World
If a language model can only output text, how does it “check the weather”, “query a database” or “book a meeting”?
In short: Function calling (also called tool calling) lets an LLM ask our application to run a function. We describe the available functions with names, descriptions and JSON Schemas; the model replies with a structured request naming a function and its arguments; our code runs it and sends the result back; the model then answers using that result. The model never executes anything itself, which is exactly what makes the pattern safe and controllable.
What you will learn
- What is Function Calling
- Why We Need Function Calling
- The Key Insight: The Model Does Not Run the Function
- How Function Calling Works Step by Step
- A Concrete Example: get_weather(city)
- The Conversation Loop
- Multi-Step and Parallel Function Calling
- Relation to Structured Outputs and JSON Mode
- Real-World Use: The Backbone of AI Agents
- Quick Summary
In this lesson
- What is function calling?
- Why we need function calling
- The key insight: the model does not run the function
- How function calling works step by step
- A concrete example: get_weather(city)
- The conversation loop
- Multi-step and parallel function calling
- Relation to structured outputs and JSON mode
- Real-world use: the backbone of AI agents
- Common mistakes and how to spot them
- Practice: try it yourself
Key terms in this lesson
- Function calling (tool use)
- An LLM API feature where the model returns a structured request to call a described function instead of plain text.
- Tool definition
- The name, description and JSON Schema of parameters we send so the model knows what it can call.
- JSON Schema
- A standard way to describe the shape of JSON data: field names, types, required fields and allowed values.
- Tool result
- The message we send back with the output (or error) of a function, linked to the call by its id.
- Parallel function calling
- The model returning several independent tool calls in one reply so they can run together.
- Constrained decoding
- Restricting which tokens the model may generate so the output always matches a grammar or schema.
This lesson is part of the Generative AI Engineering and Complete AI Engineer tracks. See plans and pricing to open the full lesson, its video, labs and quiz, or try the free lesson first (free account needed).
← 11.1 AI Agents: Autonomous Decision-Making Systems · 11.3 The Agent Loop: Observe, Think, Act, Repeat →