Tool Calling

Tool & Function Calling - Use tools in your prompts

Tool calling (also known as function calls) give an LLM access to external tools. The LLM does not call the tools directly. Instead, it suggests the tool to call. The user then calls the tool separately and provides the results back to the LLM. Finally, the LLM formats the response into an answer to the user's original question.

Tool calling provides LLMs with a powerful and flexible way to interface with external systems and access data beyond their training set. This guide shows how to connect a model to the data and actions provided by your application.

Tool calling is a multi-turn conversation between your application and the model. The tool calling flow has five main steps:

  1. Send a request to the model, including the tools it can call

  2. Receive tool calls from the model

  3. Execute code on the application side using the tool call inputs

  4. Send a new request to the model, including the tool outputs

  5. Receive the final response from the model (or additional tool calls)

Infron supports tool calling across multiple API protocols:

API protocols
parameters

Use the tools and tool_choice parameters

OpenAI Responses API (Beta)

Use the tools parameter; responses include the function_call type

Anthropic Messages API (Beta)

Use the tools parameter; tool definitions use input_schema

Protocol comparison

Feature
Chat Completion
Responses API
Anthropic Messages
Vertex AI

Tool parameter name

tools

tools

tools

tools

Schema field

parameters

parameters

input_schema

parameters

Tool call identifier

tool_calls

function_call

tool_use

functionCall

Result field

tool role

function_call_output

tool_result

functionResponse

Parallel calls

Forced calling

tool_choice

tool_choice

tool_choice

functionCallingConfig

Strict mode

strict: true

strict: true

VALIDATED mode

Streaming support

Supported Models: You can find models that support tool calling by filtering on https://infron.ai/models?supported_parameters=toolsarrow-up-right

If you prefer to learn from a full end-to-end example, keep reading.

OpenAI Chat Completion API

Tool calling example

Let’s look at a complete tool calling flow, using get_horoscope to fetch a daily horoscope for a zodiac sign.

Defining a function tool (function)

Function tools can be configured via the tools parameter. A function tool is defined by its schema, which tells the model what the function does and what input parameters it expects. A function tool definition includes the following fields:

Field
Description

type

Must always be function

function

The tool object

function.name

Function name (e.g., get_weather)

function.description

Detailed information on when and how to use the function

function.parameters

JSON Schema defining the function input parameters

function.strict

Whether to enable strict schema adherence when generating function calls

Below is the definition for a get_weather function tool:

Handling tool calls (Tool calling)

When the model calls a tool in tools, you must execute that tool and return the result. Since tool calling may include zero, one, or multiple calls, best practice is to assume there may be multiple.

Response format

When the model needs to call tools, the response finish_reason is "tool_calls", and message includes a tool_calls array:

Each call in the tool_calls array contains:

  • id: a unique identifier used when submitting the function result later

  • type: the tool type, typically function or custom

  • function: the function object

    • name: the function name

    • arguments: JSON-encoded function arguments

Example tool_calls containing multiple tool calls:

Execute tool calls and append results

Controlling tool calling behavior (tool_choice)

By default, the model decides when and how many tools to call. You can control tool calling behavior using the tool_choice parameter.

  1. Auto: (default) Call zero, one, or multiple tools. tool_choice: "auto"

  2. Required: Call one or more tools. tool_choice: "required"

When to use (allowed_tools)

If you want the model to use only a subset of the tool list in a given request—without modifying the tool list you pass in, to maximize prompt caching—you can configure allowed_tools.

You can also set tool_choice to "none" to force the model not to call any tools.

Streaming

Streaming tool calling is very similar to streaming normal responses: set stream to true and receive a stream of events.

Output events

When the model calls one or more tools, an event will be emitted for each tool call where tool_calls.type is not empty:

Below is a snippet showing how to aggregate delta values into the final tool_call object.

Accumulate tool_call content

Accumulated final_tool_calls[0]

Last updated