Enable models to fetch data and take actions.
Fetching Data | Retrieve up-to-date information to incorporate into the model’s response (RAG). Useful for searching knowledge bases and retrieving specific data from APIs (e.g. current weather data). |
Taking Action | Perform actions like submitting a form, calling APIs, modifying application state (UI/frontend or backend), or taking agentic workflow actions (like handing off the conversation). |
https://api.inference.net/v1
.
In this example, we are reading the API key from the environment variable INFERENCE_API_KEY
.
tools
. This is also called “function calling”.
get_weather
function defined below:
latitude
and longitude
instead of a general location
parameter.
get_weather
functiontools
parameter of each API request.
A function is defined by its schema, which informs the model what it does and what input arguments it expects. It comprises the following fields:
Field | Description |
---|---|
name | The function’s name (e.g. get_weather) |
description | Details on when and how to use the function |
parameters | JSON schema defining the function’s input arguments |
parameters
are defined by a JSON schema, you can leverage many of its rich features like property types, enums, and descriptions.
pydantic
and zod
objects into schemas.
pydantic
and zod
features are currently supported by Function Calling, but simple, flat schemas are supported.toggle_light(on: bool, off: bool)
allows for invalid calls)order_id
based on a previous menu, don’t have an order_id
param – instead, have no params submit_refund()
and pass the order_id
with code.mark_location()
after query_location()
, just move the marking logic into the query function call.stream
to true
and get chunks with delta
objects.
delta.tool_calls
:
content
string, however, you’re aggregating chunks into an encoded arguments
JSON object.
When the model calls one or more functions the tool_calls
field of each delta
will be populated. Each tool_call
contains the following fields:
Field | Description |
---|---|
index | Identifies which function call the delta is for |
id | Tool call id. |
function | Function call delta (name and arguments) |
type | Type of tool_call (always function for function calls) |
delta
of each tool call, like id
, function.name
, and type
.
Below is a code snippet demonstrating how to aggregate the delta
objects into a final tool_calls
object.