Generative AI Tutorial 0/80 lessons ~6 min read Lesson 53
Tool Calling
Tool calling (a.k.a.
Course progress0%
Focus
7 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Tool calling (a.k.a. function calling) lets the LLM choose which function to invoke and with what arguments. Provider APIs return the function name + args as structured JSON; your code runs the function and returns the result.
Beginner analogy: Like giving the AI a remote control — it picks which button to press; you actually press it.
Understanding the topic
Core concepts to understand:
- Define tools as JSON schemas (name, description, parameters).
- LLM decides which tool to call based on the user's request.
- Your code executes the tool, returns the result back to the LLM.
- Supported by OpenAI, Anthropic, Gemini, open models.
Syntax reference
Visual workflow / architecture:
bash
User: "What's the weather in Tokyo?"│▼LLM (sees tools: get_weather, search)│▼ decidescall get_weather(city="Tokyo")│▼ your code runs it{"temp_c": 22, "rain": false}│▼ back to LLM"It's 22°C and dry in Tokyo."
Real-world use
Powers ChatGPT plugins, Claude tool use, Cursor file actions, and every AI agent built since 2023.
Best practices
- Write clear tool descriptions — the LLM relies on them to choose correctly.
- Validate tool inputs (Zod / Pydantic) before executing.
- Always have a 'reply directly' option so the LLM doesn't force a tool.
Common mistakes
- Vague tool descriptions → wrong tool chosen.
- Forgetting to validate args → runtime crashes.
Hands-on exercise
Interview preparation — practice these questions:
- Q1. How does tool calling work?
- Q2. How does the LLM choose which tool to call?
- Q3. Why validate tool args?
Ready to mark this lesson complete?Track your journey across the entire course.