Skip to main content
Kliff

Tool calling

How a model asks for an action, who actually carries it out, and what that means for safety.

Video coming soon

On its own, a model can only produce text. Tool calling is what lets it read a file, run a test, or search the web. Every coding agent depends on it, so it is worth knowing exactly how it works: what the model does, what the application does, and where the risks sit.

The model asks, the application acts

A tool is a capability the application offers the model, described in the context. The application sends a short definition for each tool: its name, what it does, and what inputs it takes.

Here is a simplified definition of a tool that reads a file:

Tool definitionjson
{
  "name": "read_file",
  "description": "Read a text file from the repository and return its contents.",
  "parameters": {
    "type": "object",
    "properties": {
      "path": { "type": "string", "description": "Path from the repository root." }
    },
    "required": ["path"]
  }
}

When the model decides it needs the tool, it does not open the file. It writes a structured request instead:

Tool call from the modeljson
{ "name": "read_file", "arguments": { "path": "src/billing/refund.ts" } }

The application reads that request, checks it, and runs the real code. Then it sends the result back to the model as new input, and the model continues with that result in view.

The key point is the split. The model only ever chooses which tool to call and with what arguments. The application decides whether to run it and does the running.

Why the descriptions matter

The model picks tools based on their names and descriptions, the same way it reads everything else: as text in its context.

That has two effects:

  • A clear description gets the tool used at the right time. A vague one leads to the wrong tool, or to no tool when one was needed.
  • Every tool definition takes room in the context window. Offering dozens of tools the task does not need costs tokens and gives the model more ways to choose badly.

When you connect extra tools to an agent, connect what the work needs, and leave the rest off.

Tool results are input, not instructions

A tool result goes into the context like any other text. The model cannot tell, from the text alone, whether a sentence came from you or from a web page it fetched.

That opens the door to prompt injection: text inside a file, issue, web page, or email that tries to give the model orders. For example, a fetched page might contain a hidden line telling the agent to send your environment variables somewhere.

Well built agents defend against this in layers:

  • They tell the model that tool output is data to read, not instructions to follow.
  • They limit what each tool can do, so even a fooled model cannot do much harm.
  • They ask a person before risky actions, such as deleting files, pushing code, or calling outside services.

As a user, the habit is simple. Be careful about pointing an agent at content you do not trust, and treat its requests for approval as real decisions, not prompts to click through.

Permissions are the real safety line

Since the application does the acting, the application is where safety lives. A model can be asked politely not to run a dangerous command, but a rule that refuses the command is far more reliable.

Most agent tools give you some mix of:

  • Allow: the tool runs without asking.
  • Ask: a person approves or denies each call.
  • Deny: the call is refused, and the model is told why.

A good default is to allow reading freely, ask before changes that are hard to undo, and deny what should never happen in that environment.

Key points

  • A tool is described to the model as a name, a description, and its inputs.
  • The model writes a structured request. The application decides whether to run it and returns the result as new input.
  • Clear descriptions and a small set of relevant tools help the model choose well.
  • Tool results can carry prompt injection, so they are data, not instructions.
  • Permission rules enforced by the application are more reliable than asking the model to behave.