Example: Function calling
This example answers an inbound Voximplant call, connects it to Deepgram Voice Agent, and handles function calls (tool requests) from the agent inside VoxEngine.
⬇️ Jump to the Full VoxEngine scenario.
Prerequisites
- Set up an inbound entrypoint for the caller:
- Phone number: https://voximplant.com/docs/getting-started/basic-concepts/phone-numbers
- WhatsApp: https://voximplant.com/docs/guides/integrations/whatsapp
- SIP user / SIP registration: https://voximplant.com/docs/guides/calls/sip
- Voximplant user: https://voximplant.com/docs/getting-started/basic-concepts/users (see also https://voximplant.com/docs/guides/calls/scenarios#how-to-call-a-voximplant-user)
- Create a routing rule that points the destination (number / WhatsApp / SIP username) to this scenario: https://voximplant.com/docs/getting-started/basic-concepts/routing-rules
- Store your Deepgram API key secret value in Voximplant
ApplicationStorageunderDEEPGRAM_API_KEY.
Session setup
The Voice Agent session is configured via a settingsOptions object passed to Deepgram.createVoiceAgentClient(...).
For function calling, the key part is SETTINGS_OPTIONS.agent.think.functions:
name,description,parameters: define the tool schema the LLM can callclient_side: true: ensures VoxEngine receivesFunctionCallRequestand can respond
Connect call audio
Once the Deepgram.VoiceAgentClient is created, bridge audio both ways:
Function calling
In the scenario, Deepgram.VoiceAgentEvents.FunctionCallRequest delivers one or more function calls requested by the agent.
Each call includes an id, a name, and JSON string arguments. Respond using voiceAgentClient.sendFunctionCallResponse(...) with a FunctionCallResponse message containing the same id:
Barge-in
As in the other examples, keep the experience interruption-friendly by clearing buffered audio on UserStartedSpeaking:
Events
The function calling flow is driven by:
Deepgram.VoiceAgentEvents.FunctionCallRequest: agent requests a client-side function executionDeepgram.VoiceAgentEvents.FunctionCallResponse: emitted when a function call response is processed
For the complete list of supported events:
- Voice Agent events: https://voximplant.com/docs/references/voxengine/deepgram/voiceagentevents
- WebSocket media events: https://voximplant.com/docs/references/voxengine/deepgram/events
Notes
See the VoxEngine API Reference for more details.