Configure tool and function calling for LLMs
Configure tool and function calling for LLMs
Learn how to deploy models with tool and function calling patterns to enable your LLM to interact with external tools, databases, and APIs.
To use full tool and function calling support, install ray>=2.49.0.
Understand tool and function calling
Tool calling allows your LLM to interact with external tools or functions, creating more modular applications.
Use tool and function calling when your application needs integrations with downstream tools, databases, APIs, or any other backend logic.
Deploy a model with tool calling enabled
To use tool calling, update your Ray Serve LLM deployment configuration with a few extra settings.
Ray Serve LLM uses vLLM as its backend engine. You can forward tool-related settings through the engine_kwargs field in your Serve config.
To enable tool calling:
- Set
enable_auto_tool_choice: true - Specify the correct
tool_call_parserfor your model
See the full list, or how to register your custom parser, in the vLLM documentation.
Create a file serve_my_llama.yaml with the following configuration:
applications:
- name: my-tool-calling-app
...
args:
llm_configs:
- ...
engine_kwargs:
...
enable_auto_tool_choice: true
tool_call_parser: <YOUR-TOOL-PARSER-ID>
Make a tool call request
To make a tool call request, you must first define your tool schemas, specify the strategy the LLM should follow, and include the tools in the request payload.
Define tools
Define your tools using standard JSON schema format. Each tool includes a name, description, and a list of expected parameters with their types and constraints.
This example defines two tools with signatures:
get_current_temperature(location: string, unit: string = "celsius")get_temperature_date(location: string, date: string, unit: string = "celsius")
# Tools schema definitions
tools = [
{
"type": "function",
"function": {
"name": "get_current_temperature",
"description": "Get current temperature at a location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The location to get the temperature for, in the format \"City, State, Country\"."
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The unit to return the temperature in. Defaults to \"celsius\"."
}
},
"required": ["location"]
}
}
},
{
"type": "function",
"function": {
"name": "get_temperature_date",
"description": "Get temperature at a location and date.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The location to get the temperature for, in the format \"City, State, Country\"."
},
"date": {
"type": "string",
"description": "The date to get the temperature for, in the format \"Year-Month-Day\"."
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "The unit to return the temperature in. Defaults to \"celsius\"."
}
},
"required": ["location", "date"]
}
}
}
]