Skip to main content

Introduction

Certain models support function calling (also called tool calling), which gives them the ability to respond to queries with function names and arguments that you can then invoke in your own application code. To use it, pass an array of function descriptions to the tools key. If the LLM decides one or more of the available functions should be used to answer a query, it will respond with an array of the function names and their arguments to call in the tool_calls key of its response. You can then use the data from tool_calls to invoke the named functions and get the results, which you can then provide directly to the user or pass them back into subsequent LLM queries for further processing.

Supported models

The following models currently support function calling:
  • meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8
  • meta-llama/Llama-4-Scout-17B-16E-Instruct
  • meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo
  • meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo
  • meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo
  • meta-llama/Llama-3.3-70B-Instruct-Turbo
  • meta-llama/Llama-3.2-3B-Instruct-Turbo
  • Qwen/Qwen2.5-7B-Instruct-Turbo
  • Qwen/Qwen2.5-72B-Instruct-Turbo
  • Qwen/Qwen3-235B-A22B-fp8-tput
  • deepseek-ai/DeepSeek-V3
  • mistralai/Mistral-Small-24B-Instruct-2501

Basic example

Let’s say our application has access to a get_current_weather function which takes in two named arguments,location and unit:
We can make this function available to our LLM by passing its description to the tools key alongside the user’s query. Let’s suppose the user asks, β€œWhat is the current temperature of New York, San Francisco and Chicago?”
In response, the tool_calls key of the LLM’s response will look like this:
As we can see, the LLM has given us three function calls that we can programmatically execute to answer the user’s question.

Selecting a specific tool

By default, an LLM that’s been provided with tools will automatically attempt to use the most appropriate one when generating responses. If you’d like to manually select a specific tool to use for a completion, pass in the tool’s name to the tool_choice parameter:
This ensures the model will use the provided function when generating its response:

Multi-turn example

Here’s an example of passing the result of a tool call from one completion into a second follow-up completion:
And here’s the final output from the second call:
We’ve successfully used our LLM to generate three tool call descriptions, iterated over those descriptions to execute each one, and passed the results into a follow-up message to get the LLM to produce a final answer!