refined-hydrogen-81988
11/13/2025, 11:01 PMasync def *on_exit*(_self_): method, how to do that?tall-airline-16756
11/13/2025, 11:01 PMtall-airline-16756
11/13/2025, 11:02 PMon_exit method, you can use the update_metadata method on the local_participant object. Here’s a simple example to guide you:
import json
import time
from livekit.agents.voice import Agent
class MyAgent(Agent):
def __init__(self):
super().__init__(
instructions="Your agent instructions here",
# ... other configuration
)
async def on_exit(self):
# Update metadata with exit information
exit_metadata = json.dumps({
"status": "exited",
"exit_timestamp": time.time(),
"session_duration": time.time() - self.session_start_time,
"final_state": "completed"
})
# Update the agent's metadata
await self.session.room.local_participant.update_metadata(exit_metadata)
# Optional: Say goodbye before exiting
await self.session.say("Goodbye!")
Just a quick reminder: make sure your agent has the canUpdateMetadata permission to modify its own metadata. Without this permission, the update won’t go through.
If you have any questions or need a bit more help, please don’t hesitate to ask—I’m here for you!
Sources: lib/src/proto/livekit_models.pb.dart | Pipeline nodes and hooks | LiveKit docs | livekit-agents/livekit/agents/voice/room_io/room_io.py | server/agent.pyrefined-hydrogen-81988
11/13/2025, 11:07 PMself.session.room.local_participant.update_metadata as AttributeError: 'AgentSession' object has no attribute 'room'tall-airline-16756
11/13/2025, 11:07 PM