In a Python agent, how do I run code after a call ...
# ask-ai
d
In a Python agent, how do I run code after a call has finished
t
Thanks for reaching out, Martin. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To run code after a call has finished in a Python agent, you can use event handlers. The system typically uses an event-driven architecture where you can register handlers for specific events. For example: • To handle function calls completion, you can use the
@self._session.on("function_calls_finished")
decorator to register a handler that emits a
function_calls_finished
event with the list of called functions. • To handle response completion, you can use a handler like
_handle_response_done
to process response data and emit a
response_done
event when the response is completed. By registering your own event handlers or extending these existing ones, you can execute custom code after a call has finished. Sources: livekit.agents.multimodal.multimodal_agent API documentation | livekit.plugins.openai.realtime API documentation