Is there an event generated by livekit that is emi...
# ask-ai
c
Is there an event generated by livekit that is emitted when a function call is executed?
t
Thanks for reaching out, Yousri. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether LiveKit emits an event when a function call is executed — yes. LiveKit emits the event named
function_tools_executed
after all function tools run for a given user input. The event includes: •
function_calls
— list of function call objects •
function_call_outputs
— list of outputs returned by those calls •
zipped()
— pairs each call with its corresponding output Example listener (Python):
Copy code
@session.on("function_tools_executed")
def on_function_tools_executed(event: FunctionToolsExecutedEvent):
    for call in event.function_calls:
        print(f"Function called: {call.name}")
    for output in event.function_call_outputs:
        print(f"Output received: {output.output}")
Would you like a JavaScript/TypeScript example or details on the structure of
FunctionToolsExecutedEvent
? Sources: Events and error handling | LiveKit docs
c
Is there a way to pass a variable created inside a function call through the
FunctionToolExecutedEvent
? That variable is not the output of the function call
t
The
function_tools_executed
event only exposes
function_calls
,
function_call_outputs
, and
zipped()
(pairings of calls and outputs). It does not automatically include internal/local variables created inside the function unless those values are included in the function's returned output. Options you can use to surface that internal value: • Return it from the function call (add it to the function's output payload). The event will include it via
function_call_outputs
. • Store it in session/state that your agent/session manages (e.g., session variables or a datastore) during the function execution, then read that state after the event fires. • Attach metadata to the function call object itself (if your function-call system supports custom metadata) so the event's
function_calls
contains the extra data. Which approach would you prefer? I can provide a code example for returning the value in the function output or for storing/retrieving it from session state.