Function Calling (Tool Use)
LLMs call external tools to perform real-world tasks
Function Calling enables LLMs to go beyond text generation and call external tools. When developers provide available function names, descriptions, and parameter schemas (JSON Schema), the model analyzes user requests and outputs appropriate functions and arguments as JSON. This JSON is parsed to execute actual functions, and results are passed back to the model to generate final responses. It enables "things LLMs can't do" โ weather lookups, order processing, DB queries, code execution โ forming the foundation of AI Agents.
Key Concepts
Developer provides available function list and JSON Schema to the model
User makes request in natural language ("What's the weather in Seoul?")
LLM analyzes request and outputs appropriate function and arguments as JSON ({"name": "get_weather", "arguments": {"city": "seoul"}})
Application parses JSON and executes actual function/API
Add execution results to conversation context and pass to model
LLM interprets results and generates natural language response for the user
Pros
- ✓ Compensates for LLM limitations (real-time data, computation) with tools
- ✓ Structured output makes parsing easy
- ✓ Can integrate with existing APIs/systems
- ✓ Foundation for Agent workflows
Cons
- ✗ Function schema design required
- ✗ Possible incorrect function calls/arguments
- ✗ Security โ need to prevent unauthorized calls to sensitive functions
- ✗ Increased complexity with multi-turn tool calls