Tool Calling
Overview
Tool calling allows you to define functions that the model can call to access external data or perform actions. This enables the model to interact with databases, APIs, and other external systems.
Defining tools
Define functions the model can call to access external data or functionality:
Handling tool calls
Execute tools and send results back to continue the conversation:
Tool call flow
The complete tool calling process:
- Send user message with
tools
array defining available functions - Model responds with
tool_calls
if it needs to use a tool - Execute the tool in your application code
- Add
function_call
andfunction_call_output
to conversation history - Send updated history back to the API
- Model incorporates results and either calls more tools or provides final answer
Message types
When using tools, structure your conversation history with these message types to track the complete interaction flow:
- user - Messages from the user
- assistant - Messages from the AI model
- system - System instructions or context
- function_call - Records a tool being called by the model
- function_call_output - Records the result of executing a tool
API reference
Request
The LLM Gateway accepts POST requests to https://llm-gateway.assemblyai.com/v1/chat/completions
with the following parameters:
Request parameters
Message object
Tool object
Tool choice object
The tool_choice
parameter can be:
"none"
- The model will not call any tools"auto"
- The model can choose whether to call tools- An object with
type: "function"
and afunction.name
to force calling a specific function
Response
The API returns a JSON response. When the model wants to call a tool:
Response fields
Tool call object
When the model wants to call a tool, the response includes a tool_calls
array:
Error response
If an error occurs, the API returns an error response: