Skip to main content

How does tool calling work?

Agents and tools · Intermediate 3

Short answer

You describe tools to the model with a name, description and input schema. When a tool would help, the model replies with a structured request to call it with arguments. Your code runs the tool and sends the result back, and the model uses it to continue. The model never runs your code itself.

Deeper answer

The loop: send the user message and tool definitions; if the response stops for tool use, parse the requested tool and arguments, validate them, run the function, and send a tool result message; repeat until the model answers in text. Some providers also run certain server-side tools, such as web search, for you.

Quality depends heavily on tool design: clear names and descriptions, tight input schemas, and useful error messages returned as tool results. Validate arguments before acting, because the model can produce wrong or harmful ones, especially if its input was manipulated.

What a strong answer covers

Answer it out loud in the mock interview about 1 min

Follow-ups to expect

Common mistakes

Learn it

Tool calling

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.