1:1 mentoring with Big Tech AI engineers
LLM & Agentic

How LLMs Call Tools

How LLMs use function calling and tool use — the mechanics behind tool-calling agents, from prompt engineering to structured output.

Last updated

Foundations8 min readFirst readStateless vs Stateful

After this section you can

  • Trace the tool loop and say which steps the model does and which your code does
  • Predict when a model can call tools in parallel and what that saves
  • Name the common tool-calling failures, including poisoned results, and the mitigation for each
04

How LLMs Actually Call Tools

A model cannot run code, query a database or send an email. It can write a structured request for one. Learn who does what in that exchange and agents stop being magic.

Key idea

The model never executes anything. It writes a request naming a tool and its arguments, then stops. Your code runs the tool and sends the result back as one more message, and the model carries on from there.

The model only writes a request. Everything that touches the world happens in your code.
THE MODEL reads and writes tokens, nothing else YOUR CODE 2 · Decide answer now, or ask for a tool? 3 · Request a tool name + arguments, then stop Final answer text for the user 1 · Send messages + tool list 4 · Run it validate, call, catch errors 5 · Send the result back as one more message model stops and waits no tool needed the model reads the result and decides again: another tool, or the answer Steps 2 to 5 can repeat many times in one user turn. That repetition is the agent loop.

Related

More in LLM & Agentic

Get full access to all 74+ sections with code examples, diagrams, and interactive animations.

Unlock Premium