Tool calling is the feature that turns a language model from a text generator into something that can look up an order, query a database or send an email. OpenAI calls it function calling, Anthropic calls it tool use, and most frameworks say tool calling. This glossary page defines tool calling, shows the request and response cycle with a real run, explains parallel calls, and separates tool calling from MCP, structured outputs and agents.
What is tool calling?
Tool calling (also called function calling) is an LLM API feature that lets a model ask your application to run a function. You send tools as names, descriptions and JSON schemas. When a tool would help, the model replies with a structured call instead of text. Your code runs it and returns the result.
Key takeaways:
The model never executes anything. It returns a tool name and JSON arguments. OpenAI's function calling guide puts it plainly: when the model calls a function, you must execute it and return the result.
The schema is the interface. The model only knows what the name, description and parameter schema tell it. Vague descriptions cause wrong calls.
One turn can contain several calls. Models can request parallel tool calls when the calls don't depend on each other.
Tool calling is the building block of agents. An agent is tool calling in a loop.
[02]
How does tool calling work?
Every provider follows the same cycle. OpenAI's guide lists five steps: send a request with the tools the model may call, receive a tool call, run your code with the call's arguments, send a second request with the tool output, and receive a final answer or more tool calls.
your app model API
│ 1. messages + tool schemas │
│ ────────────────────────────────────────▶ │
│ 2. tool call: get_weather {"city":"Paris"}│
│ ◀──────────────────────────────────────── │
│ │
│ 3. your code runs get_weather("Paris") │
│ │
│ 4. messages + tool result (same call id) │
│ ────────────────────────────────────────▶ │
│ 5. final answer, or more tool calls │
│ ◀──────────────────────────────────────── │The details differ by provider. In the OpenAI API the reply carries tool_calls, and you return each result as a tool message with the matching call ID. In the Anthropic API the reply has stop_reason: "tool_use" and one or more tool_use blocks, and you answer with tool_result blocks, as its tool use docs describe. Anthropic also runs some server tools, such as web search, on its own infrastructure; for your own tools, your code still does the work.
Two options matter in practice. Parallel tool calls let the model ask for several calls in one turn; OpenAI's parallel_tool_calls: false limits it to zero or one. Strict mode (strict: true) makes the arguments match your schema exactly, which OpenAI recommends enabling. OpenAI introduced function calling in June 2023, and every major model API now supports some version of it.
[03]
A tool calling example
The script prints the schema the model receives for a small Python function, then asks a question that needs two lookups. Promptise Foundry generates the schema from the function's signature and docstring and runs the call cycle for you.
import asyncio
import json
from langchain_core.tools import tool
from langchain_core.utils.function_calling import convert_to_openai_tool
from promptise import build_agent
FORECASTS = {"Paris": "14°C, light rain", "Tokyo": "22°C, clear"}
@tool
def get_weather(city: str) -> str:
"""Current weather for a city."""
return FORECASTS.get(city, "No data")
async def main():
# 1. What the model receives: a name, a description and a JSON schema.
print(json.dumps(convert_to_openai_tool(get_weather), indent=2))
# 2. What the model sends back, and what the agent does with it.
agent = await build_agent(
model="openai:gpt-5-mini",
instructions="Answer briefly.",
extra_tools=[get_weather],
)
try:
result = await agent.ainvoke(
{"messages": [{"role": "user", "content": "Is it warmer in Paris or Tokyo?"}]}
)
for msg in result["messages"][1:]:
for call in getattr(msg, "tool_calls", None) or []:
print(f"tool call id={call['id'][:12]}... {call['name']} {call['args']}")
if msg.type == "tool":
print(f"result id={msg.tool_call_id[:12]}... {msg.content}")
elif msg.content:
print(f"answer {msg.content}")
finally:
await agent.shutdown()
asyncio.run(main())Real output from one run with gpt-5-mini:
{
"type": "function",
"function": {
"name": "get_weather",
"description": "Current weather for a city.",
"parameters": {
"properties": {
"city": {
"type": "string"
}
},
"required": [
"city"
],
"type": "object"
}
}
}
tool call id=call_5jlX5k4... get_weather {'city': 'Paris'}
tool call id=call_dOEVOYD... get_weather {'city': 'Tokyo'}
result id=call_5jlX5k4... 14°C, light rain
result id=call_dOEVOYD... 22°C, clear
answer Tokyo is warmer: 22°C (clear) vs Paris 14°C (light rain).The first block is everything the model knows about the tool: its name, one sentence of description and a schema with one required string. The model then asked for both cities in a single turn, two parallel calls with different IDs. Each result goes back with the ID of the call it answers, which is how the model matches results to requests. The answer comes from the tool results, not from the model's training data.
Note what is missing from the schema: the city parameter has no description. For a tool this simple that's fine. For tools with dates, IDs or units, describe each parameter, or the model will guess the format. How LLM tool calling works has more design rules for tools and results.
[04]
Tool calling vs function calling, MCP and structured outputs
Term | What it is | Who runs the code | Use it for |
|---|---|---|---|
---|---|---|--- | |||
Tool calling | Model API feature: the model returns a structured call to one of your tools | Your application | Letting a model use APIs, databases and code |
Function calling | OpenAI's name for the same feature | Your application | Same as tool calling |
MCP (Model Context Protocol) | A protocol for discovering and calling tools that live in a separate server | The MCP server, called by your app's MCP client | Reusing tools across agents and apps |
Structured outputs | The model's final answer is forced to match a JSON schema | Nobody: it is just output | Extracting data in a fixed shape |
AI agent | A loop that repeats tool calling until a goal is met | Your application, or a framework | Multi-step tasks |
MCP and tool calling work together rather than compete. An agent connects to an MCP server, lists its tools, and passes their schemas to the model through the model's tool calling API. When the model asks for a tool, the agent forwards the call to the server. What is MCP explains the protocol, and MCP tools vs resources vs prompts covers what else a server can offer.
[05]
Common misconceptions about tool calling
"The model runs my function." It doesn't, and that is the most useful fact about tool calling. Because your code runs every call, you can validate the arguments, check permissions, ask a human, or refuse. Human approval for tool calls builds on exactly this.
"Tool call arguments can be trusted." The model fills in arguments from the conversation, which may include text from a user, a web page or another tool. Treat arguments as untrusted input: validate types and ranges, and never pass them straight to a shell or SQL query. Prompt injection defense for AI agents explains why.
"The model picks the right tool every time." It picks based on names and descriptions. Overlapping tools, vague descriptions and long tool lists all cause wrong choices. Too many MCP tools shows what happens past a few dozen tools.
"Tool schemas are free." Every schema is sent as input tokens on every model call. Large tool lists add cost to each round of an agent.
[06]
Frequently asked questions
Is tool calling the same as function calling?
Yes. Function calling is OpenAI's name for the feature, and its docs say it is also known as tool calling. Anthropic calls it tool use. They all describe the same idea: the model returns a structured request to call a function you defined, and your application runs it.
Does the LLM execute the function?
No. The model only produces a tool name and arguments as JSON. Your application, or the framework you use, runs the function and sends the result back to the model in the next request. Some providers also host built-in server tools such as web search, which run on the provider's side.
What is parallel tool calling?
Parallel tool calling means the model asks for several tool calls in one reply, for example the weather in two cities. Your code can run them at the same time and return each result with its call ID. Disable it when calls must happen in order or when you want to approve them one at a time.
What is the difference between tool calling and MCP?
Tool calling is how a model asks for a tool. MCP is how an application finds tools and calls them in a separate server. An agent uses both: MCP to list and run the tools, tool calling to let the model choose them. You can use tool calling without MCP by passing plain functions.
Which models support tool calling?
All major model APIs support it, including OpenAI, Anthropic, Google and Mistral, and many open-weight models served through tools like Ollama or vLLM. Quality varies: smaller models are more likely to pick the wrong tool or produce invalid arguments, so test with the model you plan to use.
[07]
Next steps
See tool calling inside an agent loop: How to build an AI agent in Python.
Design tools the model uses well: How LLM tool calling works.
Put tools in a server: What is MCP?
All guides on the topic: the tools and MCP hub.
Reference: Building agents in the Promptise docs.