๐Ÿ”ง

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

1

Developer provides available function list and JSON Schema to the model

2

User makes request in natural language ("What's the weather in Seoul?")

3

LLM analyzes request and outputs appropriate function and arguments as JSON ({"name": "get_weather", "arguments": {"city": "seoul"}})

4

Application parses JSON and executes actual function/API

5

Add execution results to conversation context and pass to model

6

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

Use Cases

ChatGPT Plugins / GPT Actions Claude Tool Use AI chatbot DB queries/order processing AI coding assistant file read/write Multi-tool Agent (chaining multiple tool calls)