Modern AI Engineering

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

  1. What is function calling?
  2. Why we need function calling
  3. The key insight: the model does not run the function
  4. How function calling works step by step
  5. A concrete example: get_weather(city)
  6. The conversation loop
  7. Multi-step and parallel function calling
  8. Relation to structured outputs and JSON mode
  9. Real-world use: the backbone of AI agents
  10. Common mistakes and how to spot them
  11. 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 →