Skip to main content
Function calling lets your voice agent take actions — call an API to book an appointment, transfer or end the call, fetch external knowledge — besides just talking. Supported LLMs can output a JSON object containing arguments to call one or many functions. This is also known as tool use. We recommend reading OpenAI’s function calling documentation to understand the concept. This guide uses OpenAI function calling as an example, but the same idea applies to other models like Claude.

Case Study: End the Call Intelligently

The following steps build on the LLM client class from the Integrate LLM guide.
1

Define the function

Note: for OpenAI, the model will either give a tool call or a text response — not both. The message parameter lets the LLM say something before ending the call.
Node.js
2

Add function calling to the chat request

Node.js
3

Extract function call arguments from the streaming response

Node.js
4

End the call when the LLM triggers the function

Node.js

Case Study: Make an Appointment

End call is the simplest function calling use case. In most cases, you’ll want your agent to say something while calling the function and say something after it returns.
This is not production-ready as-is. In production, you need to handle duplicate function calls, user interruptions, and more complex state management. A good practice is to maintain internal states to track what function to run and how it influences LLM responses.