← Lessons

quiz vs the machine

Gold1420

Machine Learning

Tool Calling Protocol Deep Dive

How a model requests a function and the runtime executes it.

5 min read · core · beat Gold to climb

The contract

Tool calling is a structured protocol. The application gives the model a list of available tools with names and argument schemas. The model emits a structured request naming one tool and its arguments. The runtime executes it and returns the result for the model to read.

The round trip

  • The app sends the user message plus tool definitions
  • The model replies with a tool call rather than plain text
  • The runtime runs the function and captures the output
  • The output is appended to the conversation and the model continues

Why structure matters

Because the call is structured, the runtime can validate arguments before running anything. The model never executes code itself, it only asks. This separation keeps execution under the application's control, which is essential for safety and auditing.

Practical tips

Return errors as readable text the model can reason about, support parallel tool calls when steps are independent, and always validate arguments against the schema before execution.

Key idea

Tool calling is a structured request and response: the model asks for a named function with arguments, and the runtime validates, executes, and returns the result.

Check yourself

Answer to earn rating on the learn ladder.

1. In tool calling, who actually executes the function?

2. Why is a structured tool call preferable to free text?