what is the simplest way to set a max call duratio...
# ask-ai
c
what is the simplest way to set a max call duration on a livekit agent conversation?
t
Thanks for reaching out, Faraz. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you're asking for the simplest way to enforce a max call duration on a LiveKit agent conversation. The easiest approach is to start a timer when the call/room starts and disconnect the room when the timer elapses. Example pattern (Python async):
Copy code
import asyncio

async def set_max_duration(room: rtc.Room, duration_seconds: int):
    await asyncio.sleep(duration_seconds)
    await room.disconnect()

# Start when session begins
asyncio.create_task(set_max_duration(ctx.room, 300))  # 5 minutes
What to consider: • Clean up any agent/user state after disconnect if needed. • If you need to notify participants before disconnecting, send a message/event a short time before calling
disconnect()
. • If you use a different runtime (Node, Go), I can provide the equivalent snippet — which language are you using? Sources: examples/voice_agents | livekit/livekit_composite | DeepWiki