Skip to content

05. Function Calling

Overview

Function calling (also called tool calling) is the mechanism that allows LLMs to produce structured requests to invoke external functions. It's the production-grade evolution of the ReAct prompt — more reliable, more parsable, and the current industry standard for building AI agents.

Architecture at a Glance

flowchart LR
    User["👤 User Query"] --> LLM["🤖 LLM\n(with bound tools)"]
    LLM -->|"Structured JSON"| App["🖥️ Application"]
    App -->|"Execute function"| Tool["🔧 External Tool"]
    Tool -->|"Result"| App
    App -->|"Tool result"| LLM
    LLM --> Answer["📝 Final Answer"]

    style LLM fill:#4a9eff,color:#fff
    style Tool fill:#10b981,color:#fff

Lesson Map

# Lesson Focus
1 Introduction Why function calling replaced the ReAct prompt
2 Understanding Function Calling How it works, advantages, tradeoffs, and two use cases

Key Concepts

Concept Description
Function calling LLM produces structured JSON specifying function name + arguments
Tool binding Attaching function definitions (name, params, description) to the LLM
ReAct prompt The predecessor — text-based reasoning that's parsed with regex (fragile)
Structured output Using function calling not for tools, but to enforce response format