Give the LLM tools it can call. Text generation becomes agency.
Function calling transforms LLMs from text generators into agents that can take actions and interact with the world.
Text Generator Agent
────────────── ──────
LLM → Text only LLM + Tools → Can act
Function calling lets the LLM invoke predefined functions to access data or perform actions it cannot do alone.
User: "What time is it?"
↓
LLM thinks: "I need current time"
↓
LLM calls: getCurrentTime()
↓
Tool returns: "1:46:36 PM"
↓
LLM responds: "It's 13:46"
This is agency - the ability to DO, not just SAY.
getCurrentTime = {
description: "Get the current time",
handler: () => new Date().toLocaleTimeString()
}
Available functions:
- getCurrentTime: "Get the current time"
- getWeather: "Get weather for a city"
- calculate: "Perform math"
"What time?" → getCurrentTime() ✓
"What's 5+5?" → calculate() ✓
"Tell a joke" → No tool needed
Personal Assistant: Calendar, email, reminders Research Agent: Web search, document reading Coding Assistant: File operations, code execution Data Analyst: Database queries, calculations
When you have many tools, sending the full catalog on every turn can waste context and increase wrong-tool calls; see Example 15: tool routing with embeddings for a small embedding + exemplar pre-filter before the chat model runs.
Function calling is THE feature that enables AI agents. Without it, LLMs can only talk. With it, they can act.
This is the foundation of all modern agent systems.