All Infographics
Tool Calling and Function Calling Explained infographic - How LLMs Use External APIs, Functions, and Tools

Click image to open full size

Computer Science

Tool Calling and Function Calling Explained

How LLMs Use External APIs, Functions, and Tools

Large language models are powerful at generating text, but by themselves they do not directly look up live data, run code, or access private systems. Tool calling, often called function calling, is the method that lets a model request help from external software in a structured way. This matters because it turns a text generator into a system that can calculate, search, retrieve records, and trigger real actions. It is a key idea behind modern AI assistants that connect language understanding with reliable computation and software workflows.

In a typical tool calling pipeline, the model reads a user request, decides whether a tool is needed, and outputs a structured call with a function name and arguments. Another program validates that call, executes the tool, and sends the result back to the model as new input. The model then uses that result to produce a final answer or decide on another step. Good tool calling depends on clear schemas, argument checking, permissions, and careful handling of errors so the system stays accurate and safe.

Key Facts

  • A tool call usually has the form: call = {name, arguments}
  • Arguments are often represented as key-value data such as args = {city: "Boston", units: "C"}
  • The basic loop is: user input -> model -> tool call -> tool result -> model -> final answer
  • If a calculator tool is available, the model can delegate arithmetic instead of estimating in text
  • A function schema defines allowed inputs and outputs, which reduces ambiguity and invalid calls
  • System reliability improves when execution is separated from generation: model decides, external code executes

Vocabulary

Tool calling
A process where a language model requests an external tool or program to perform a task using structured data.
Function schema
A formal description of a function's name, inputs, and expected argument types that guides the model's tool use.
API
An application programming interface is a defined way for one software system to send requests to another.
Argument validation
The step of checking whether the model's requested inputs are complete, correctly typed, and safe before execution.
Execution environment
The software context where the requested tool actually runs, such as a database server or code runner.

Common Mistakes to Avoid

  • Treating the model itself as the tool, which is wrong because the model usually only proposes the call while external software performs the real action.
  • Assuming tool output is always correct, which is wrong because APIs can fail, return stale data, or produce results that still need verification.
  • Ignoring argument formats, which is wrong because a function may require exact field names, units, or data types for successful execution.
  • Letting the model call any tool without restrictions, which is wrong because real systems need permissions, validation, and safety checks to prevent harmful actions.

Practice Questions

  1. 1 A weather function requires arguments {city, units}. A user asks, "What is the temperature in Madrid in Celsius?" Write the function name weather_lookup and a valid argument object the model should produce.
  2. 2 A calculator tool returns 17 for the call add({a: 9, b: 8}). If the model then asks multiply({x: 17, y: 3}), what final numerical result should be returned to the user?
  3. 3 A user asks for today's stock price, but the model answers from memory instead of calling the finance API. Explain why this can reduce accuracy and why tool calling is the better choice.