TokenPad

Agents

Tool calling

Tool calling lets a model request that your code run a named function with structured arguments, then continue with the result.

Also written: function calling

You supply each tool as a name, a description and a JSON schema for its parameters. The model returns a structured call rather than prose, your code executes it, and the result is sent back as another message.

The description is the only thing the model uses to decide whether to call a tool. A vague one means the tool fires at the wrong times or never fires at all.

In practice

The model produces the arguments; it does not guarantee them. A refund tool whose amount is not validated against a range will one day receive an amount from outside it. Validate tool arguments against a schema before execution the same way you validate a form field, because that is exactly what they are.

Common questions

Do I have to validate tool arguments?

Yes. The model produces arguments; it does not guarantee them. Validate against a schema including ranges and identifiers before execution, exactly as you would validate a form field — because that is what it is.

What happens if a tool fails?

Return the error to the model as a tool result rather than throwing. A loop that omits the result for a failed call leaves the conversation malformed, and most providers reject the next request outright.

Measure it

More in Agents