Tool calling and function calling, explained
Tool calling, also called function calling, is how a language model asks your software to do something. You describe a set of tools to the model, each with a name, a description and a JSON Schema for its inputs. When the model decides a tool would help, it replies with a structured call naming the tool and its arguments instead of plain text. Your application runs the tool and sends the result back, and the model carries on. Anthropic's documentation puts it this way: "Claude determines when to call a tool based on the user's request and the tool's description. It then returns a structured call that your application runs" (Tool use with Claude, read November 2026). The model never runs your code itself.
The loop, step by step
OpenAI's function calling guide lists five steps (Function calling, read November 2026):
- Make a request to the model with tools it could call.
- Receive a tool call from the model.
- Execute code on the application side with input from the tool call.
- Make a second request to the model with the tool output.
- Receive a final response from the model, or more tool calls.
In Anthropic's API, the same exchange shows up as a response with stop_reason: "tool_use" and one or more tool_use blocks. Your code sends back a tool_result. An agent is this loop repeated until the task is done. Our post on how AI agents work covers the whole agent loop.
What a tool definition looks like
A tool is a name, a description and an input schema. Here is a small one in Anthropic's format:
{
"name": "get_invoice_status",
"description": "Look up an invoice in the accounting system by its number and return its status (draft, sent, paid or overdue), amount, currency and due date. Use this when the user asks whether an invoice has been paid or when it is due. Invoice numbers look like INV-2026-0142.",
"input_schema": {
"type": "object",
"properties": {
"invoice_number": { "type": "string", "description": "The invoice number, for example INV-2026-0142" }
},
"required": ["invoice_number"]
}
}
Anthropic's names must match ^[a-zA-Z0-9_-]{1,128}$, and its input schema is "A JSON Schema object defining the expected parameters for the tool." OpenAI describes a function as "a specific kind of tool, defined by a JSON schema." Both providers support a strict: true setting so that calls match the schema exactly.
Writing tools the model uses well
The description does most of the work. Anthropic calls detailed descriptions "by far the most important factor in tool performance" and suggests writing at least three or four sentences for each one. In its guide to building agents, it adds that "we actually spent more time optimizing our tools than the overall prompt."
OpenAI suggests keeping fewer than 20 functions available at the start of a turn, "though this is just a soft suggestion", and offers a simple check it calls the intern test: could a new intern use the function correctly from its description alone?
Tool definitions also cost tokens. Anthropic counts the tool names, descriptions and schemas in each request, plus the call and result blocks.
Controlling when tools are called
Both APIs let you decide how freely the model may use tools:
Anthropic tool_choice | OpenAI equivalent | Effect |
|---|---|---|
auto (the default) | Auto (the default) | The model decides whether to call a tool |
any | Required | The model must call at least one tool |
tool | Forced function | The model must call one named tool |
none | None | No tools this turn |
OpenAI also has an allowed-tools option that limits a turn to a subset of tools.
Models can also call several tools in one response. Anthropic notes that "Independent, read-only operations are usually safe to run in parallel", while "Tools with side effects, shared state, or ordering requirements might be better run sequentially." Both APIs can switch parallel calls off.
When a tool call fails
A failed call should go back to the model as a result, not crash the loop. Anthropic says to send a tool_result with is_error set to true. The model "might then call the tool again with a new tool_use block, so limit how many retries your loop allows." The Model Context Protocol spec makes the same point: tool errors should carry "actionable feedback that language models can use to self-correct and retry with adjusted parameters."
Where MCP fits
The Model Context Protocol is a standard way to publish tools so that any compatible agent can use them. An MCP server lists its tools through tools/list, and the client invokes them with tools/call. Each tool carries an input schema, much like the definitions above. The spec says "there SHOULD always be a human in the loop with the ability to deny tool invocations", and that clients must treat a tool's annotations, the hints a server gives about how a tool behaves, as untrusted unless they come from a trusted server (MCP tools spec). Our MCP explainer covers the protocol.
How Neotask handles tool calls
Which tools an agent sees
A Neotask agent doesn't get every tool at once. Built-in tools, such as file editing, shell commands, web fetch, the browser and scheduling, are filtered by policy into profiles. The agent's instructions say: "Available tools are policy-filtered." Tools from connected apps keep the name, description and schema their MCP server publishes. A company's agents see only the app tools that company allows.
When an agent runs on a model on your own computer, Neotask loads a short list of tools and keeps the rest in a searchable catalog that the agent can look up when needed.
The same tool also has to be adjusted for each model provider. Neotask's runtime notes that Gemini rejects several JSON Schema keywords, OpenAI needs the top level of a function schema to be an object, Anthropic expects full JSON Schema 2020-12, and xAI rejects validation keywords such as minLength.
What happens before a call runs
Before any tool runs, Neotask checks it in this order:
- The destructive command guard, for shell commands. It blocks a short list outright, such as deleting files outside the workspace or erasing a disk, and sends dangerous categories, such as database and cloud commands, to approval.
- The run's budget and loop detection.
- The company's approval rules. Each call gets a risk level from the tool's name: read-only work is low, creating and writing is medium, deleting, sending and running commands is high, and irreversible or destructive operations sit at the level the app labels "Critical". A tool with an unknown name counts as medium. The company's approval mode then decides whether the call runs, goes to Auto review or asks you. Payments ask a person in every mode.
A call waiting for approval doesn't time out. The agent's thread is suspended until someone decides. A refused call goes back to the model as a tool result that gives the reason, so the agent can change course instead of failing.
Loops and budgets
Agents sometimes call the same tool over and over. Neotask's loop detection keeps a history of the last 30 calls, warns at 10 repeats and blocks at 20. It is off by default in interactive chats and on for background runs.
A background run that nobody is watching, such as a scheduled company task, also has a budget: at most 200 tool calls, 15 calls with the same intent, and an hour of working time. When the budget is spent, every tool call except the run's final report is refused. Neotask's code gives the reason for the same-intent limit: a run once made 36 different curl and grep commands looking for an analytics tag that didn't exist.
How results come back
Results from outside sources, including emails, webhooks, web pages, web searches and MCP tools, reach the model wrapped in markers that label them untrusted. Each wrapper has a random ID so the content can't fake its own end. Very long results are cut at 16,000 characters, and the agent can read the rest in order with a continuation tool for an hour.
Limits
- The command guard covers shell commands only. Other tools are governed by risk level and approvals.
- Risk comes from the tool's name. A badly named tool can land at the wrong level.
- Injection is labelled, not blocked. Neotask logs suspicious patterns in outside content but still passes the wrapped content to the model, so approvals remain the backstop. The AI agent security guide covers the rest.
- Autonomous mode runs every risk level apart from the fixed checks and your own "Always ask" rules.
Frequently asked questions
Is tool calling the same as function calling? Yes. Anthropic's docs say tool use is "also called function calling", and OpenAI's function calling guide uses both terms.
Does the model run the function itself? No. The model returns a structured call, and your application runs it. The exception is server tools, which some providers run on their own infrastructure, such as Anthropic's web search.
How many tools can an agent have? There is no fixed number, but every definition costs tokens and makes the choice harder. OpenAI suggests keeping fewer than 20 available at the start of a turn.
How does MCP relate to tool calling? MCP is a standard way to publish tools. An agent lists a server's tools, offers them to the model as tool definitions, and runs the calls the model makes through the server.