Triggered when the AI determines that a function call is needed during the conversation. Handle this event to execute external API calls, query knowledge bases, or integrate with external systems.
Event Properties
Event type. Always "realtime.response.function_call_arguments.done" for this event.
Event data object containing function call information.
JSON string containing function call parameters.Example: "{\"userInput\": \"What's the weather in Beijing?\"}"
Unique identifier for this function call.Example: "call-123456"
{
"type": "realtime.response.function_call_arguments.done",
"data": {
"arguments": "{\"userInput\": \"What's the weather in Beijing?\"}",
"call_id": "call-123456"
}
}
Usage Example
const NavTalkMessageType = Object.freeze({
REALTIME_RESPONSE_FUNCTION_CALL_ARGUMENTS_DONE: "realtime.response.function_call_arguments.done",
// ... other event types
});
async function handleReceivedMessage(data) {
const nav_data = data.data;
switch (data.type) {
case NavTalkMessageType.REALTIME_RESPONSE_FUNCTION_CALL_ARGUMENTS_DONE:
const arguments = nav_data.arguments;
const callId = nav_data.call_id;
// Parse function call arguments
const functionCallArgs = JSON.parse(arguments);
// Execute function call
const result = await executeFunctionCall(functionCallArgs);
// Send result back
sendFunctionCallResult(result, callId);
break;
}
}
function sendFunctionCallResult(result, callId) {
const resultJson = {
type: "conversation.item.create",
item: {
type: "function_call_output",
output: result,
call_id: callId
}
};
socket.send(JSON.stringify(resultJson));
// Request AI response
const rpJson = { type: "response.create" };
socket.send(JSON.stringify(rpJson));
}
After sending the function call result, always send a response.create message to trigger AI processing.