Function Calling
How to do Function Calling with your Voice Agent.
What is Function Calling?
LLM function calling is the ability of large language models (LLMs) to invoke external functions or APIs in response to user queries. For example, if a user asks for the current weather in a specific location, the LLM can use function calling to call a weather API, fetch real-time data, and present it in a structured response.
This capability allows LLMs to enhance their functionality by integrating with other systems, services, or databases to provide real-time data, perform specific tasks, or trigger actions.
How Function Calling Works
- User Query: A user asks the LLM something that requires external data or specific action (e.g., “Check the weather in New York” or “Book an appointment”).
- Function Identification: The LLM identifies that the query requires a specific function to be called. For instance, if the user asks for the weather, the model recognizes that it needs to call a weather API rather than generate a general response.
- Parameter Extraction: The LLM analyzes the user’s query to extract the required parameters (e.g., location, date, or other variables). For example, in the weather query, “New York” would be extracted as the location parameter.
- Call the Function: The LLM triggers an external function or API with the appropriate parameters. This could involve fetching live data, performing a task (e.g., making a booking), or retrieving information that is outside the LLM’s static knowledge.
- Return the Result: The function returns the result (such as the current weather data), which the LLM incorporates into its response back to the user.
A process flow of the Voice Agent API with function calling.
Settings Configuration
Here is an incomplete Settings Configuration object showing what properties can be added to configure function calling with Deepgram’s Voice Agent API. (See a more complete Settings Configuration object in the relevant documentation.)
Not all of the fields are required in every function calling example. If the function will run client-side and you do not need to make a request to your server, you may not need fields such as url
, headers
, or method
, for example. To help visualize this, here is the configuration settings for the client-side weather example:
The function itself would be called when the user interacting with the LLM requests weather information for a specific location:
Server and Client Function Calling Messages
Function calling messages are exchanged between the client and Deepgram’s Voice Agent API server through the websocket.
Server Messages (Sent by Deepgram)
FunctionCalling
– Indicates that the agent is invoking a function. Read more.FunctionCallRequest
– Requests execution of a function with extracted parameters. Read more.FunctionCalling
(Tool Response) – Returns the function’s output after execution. Read more.
Example:
Client Messages (Sent by your application)
FunctionCallResponse
– Sent after executing the function to return the result.
Example:
Message Flow
- User Query → The agent determines a function is needed.
- Server Sends
FunctionCallRequest
→ Requests function execution. - Client Executes & Sends
FunctionCallResponse
→ Returns the function result. - Server Uses Response → The agent continues the conversation.
What’s Next