What is tool calling?
On its own, a large language model can only produce text. Tool calling, also called function calling or tool use, gives it a structured way to ask for something to be done. The developer describes the available tools to the model, each with a name, a purpose and a schema for its inputs. When the model decides a tool would help, it responds with a call that names the tool and supplies the arguments.
Crucially, the model does not run the tool itself. The application receiving the response executes the call, whether that means querying a database, calling a REST API, reading a file or running a shell command, and sends the result back. The model then decides what to do next: answer the user, call another tool, or try again with different arguments.
Most major model providers support tool calling in their APIs, and agent frameworks build on it to manage the loop of calls and results. Developers rarely write the loop from scratch: coding agents, assistant applications and agent SDKs handle it, while the developer focuses on which tools to expose and how to secure them.
Tool calling is the mechanism that turns a chatbot into an AI agent. Every coding agent, AI assistant that reads your calendar, or agent that operates software through an API depends on it.
Why tool calling matters
Tool calling matters because it connects models to current data and real actions.
- Live information: Models can look up current records instead of relying on training data.
- Real actions: Models can create, update and configure things in other systems.
- Structured output: Arguments follow a schema, so applications can validate them before acting.
- Composable workflows: Chaining several tool calls lets an agent complete multi-step tasks.
- Clear control points: Each call is a discrete event the application can log, approve or block.
How tool calling works
Tool calling follows a request-and-result loop between the model and the application.
Define the tools
The application sends tool definitions with the request. Each definition includes a name, a natural-language description and a JSON Schema describing the parameters. Good descriptions are essential, because the model chooses tools based on them.
The model returns a call
When a tool fits the request, the model returns a structured call instead of, or alongside, a text reply. Some models can request several calls at once when the tasks are independent.
The application executes
The application validates the arguments, checks permissions, runs the tool and captures the output or error. This is the right place for authorization, because the model's request is a suggestion, not a guarantee of safe intent.
The result goes back
The output is returned to the model as part of the conversation, and the loop continues until the model produces a final answer or the application stops it.
Limits on the loop
Because every round trip is another model request, an agent that misreads its goal can keep calling tools for a long time. Applications usually cap the number of steps, set timeouts, and rely on budget limits on the model key so a runaway loop stops before it becomes expensive. Logging each call also makes it possible to see afterward where the agent went wrong.
Tool calling vs Model Context Protocol
Tool calling is a capability of the model, while the Model Context Protocol is a standard for packaging and sharing tools across applications.
- Layer: Tool calling happens between an application and a model; MCP connects applications to external servers that provide tools.
- Scope: With plain tool calling, each application defines its own tools; with MCP, any compatible host can use tools from any MCP server.
- Discovery: Plain tool definitions are written into the application; MCP clients discover tools from servers at runtime.
- Relationship: MCP relies on tool calling: tools discovered from an MCP server are passed to the model and invoked through tool calls.
Common use cases
- Coding agents: Tools for reading files, editing code and running tests or terminal commands.
- Product operation: Agents call a vendor's API, CLI or MCP server to configure software on a user's behalf.
- Data retrieval: Assistants query databases, search indexes or knowledge bases before answering.
- Workflow automation: Agents create tickets, send notifications or update records in business systems.
- Training exercises: Learners watch how an agent chooses and sequences tool calls inside an agent lab.
Best practices
- Expose the smallest set of tools the task needs, with granular functions rather than open-ended ones like arbitrary shell access.
- Enforce authorization in the application or downstream system, never by trusting the model's judgment.
- Require human approval for destructive or high-impact calls.
- Treat tool results as untrusted input, since web pages, files and API responses can carry injected instructions.
- Log every call and cap usage so a looping agent cannot run indefinitely.
How Heropa helps
Heropa provides isolated hands-on environments where agents can make real tool calls against real software without risk to production. Each user gets a dedicated lab from a template, so commands, file edits and API calls stay inside an environment that is destroyed at the end of the session. See sandbox environments.
With AI Lab Keys, the model behind those tool calls runs on a key Heropa mints for that user and environment, limited to the models, budget and duration you set. When the budget is reached, AI calls stop being authorized while the environment keeps running.
Frequently asked questions
Is tool calling the same as function calling?
Yes. Function calling, tool calling and tool use describe the same capability: a model returns a structured request naming a tool and its arguments, and the application runs it. Different model providers use different names for it.
Does the AI model run the tool itself?
No. The model only produces a structured request. The application or agent harness decides whether to execute it, runs it, and returns the result. That separation is what lets developers validate arguments, enforce permissions and require approval.
How does tool calling relate to AI agents?
Tool calling is the mechanism agents use to act. An agent repeatedly asks the model what to do next, executes any tool calls it returns, and feeds the results back, continuing until the task is complete or a limit is reached.
What are the security risks of tool calling?
The main risks are excessive permissions, actions triggered by manipulated input such as prompt injection, and runaway loops that consume budget. Limit tools to what is needed, enforce authorization outside the model, require approval for risky actions and run agents in isolated environments.