Week 5

Tools & Function Calling

Step 1 of 5

1. Giving LLMs Hands

By default, Large Language Models are "brains in a jar." They are trapped in a text box. They can generate brilliant poetry, write complex code, and reason through difficult problems, but they cannot do anything. They cannot check the current weather, query your production database, send an email, or book a flight.

To build true AI Agents, we need to give LLMs "hands." We do this through a mechanism called Function Calling (or Tool Use).

The Illusion of Execution

A common misconception is that when you give an LLM a tool, the LLM actually runs the code. This is false.

LLMs are text prediction engines; they cannot execute Python scripts or make HTTP requests. Instead, Function Calling is a clever protocol:

  1. You tell the LLM what tools (functions) you have available in your application.
  2. If the user asks a question that requires a tool, the LLM stops generating normal text.
  3. Instead, it generates a structured JSON object containing the name of the tool to use and the arguments to pass to it.
  4. Your application intercepts this JSON, runs the actual code locally, and hands the result back to the LLM.

The Paradigm Shift

Introduced natively by OpenAI in mid-2023, Function Calling fundamentally changed how we build AI applications.

Before Function Calling, developers had to use complex "prompt engineering" hacks (like the ReAct framework) to coax the LLM into outputting a specific string like Action: Search, Input: Weather in Tokyo, and then use fragile Regular Expressions to parse that string.

Now, models are explicitly fine-tuned to detect when a tool is needed and to output perfectly formatted, guaranteed-to-parse JSON matching a schema you define. This makes building robust, deterministic AI systems possible.