Agents & Tool Use
Tool Use and Function Calling
How models invoke external tools to fetch data, run code, and take actions in the world.
intermediate · 7 min read
A language model with tools can do more than answer questions: it can search the web, run code, query databases, send emails. Tool use is the mechanism. Function calling is how modern APIs expose it.
The loop
- The user asks a question.
- The model decides whether to call a tool. If yes, it emits a structured tool-call message: tool name + arguments.
- The host executes the tool and returns the result.
- The model integrates the result and either answers or calls another tool.
- Repeat until done.
Schema design
Function schemas are JSON Schema with name, description, and parameters. The model uses descriptions to decide which tool fits. Underspecified descriptions are the biggest cause of wrong-tool calls.
Good description:
"Look up a customer's current subscription status by user ID. Returns the plan, valid_until, and recent payment history."
Bad description:
"Get user info."
Parallel and serial calls
Modern APIs let the model request multiple tool calls in one turn. Use this for independent lookups (fetch customer + fetch order in parallel). Serial calls (fetch customer, then use that to fetch their orders) need separate turns.
Reliability
Tool-use loops can spiral. Always cap iterations (3-5 typical), validate tool arguments before executing, and consider sandboxing tools that touch the file system or network.