How to apply a max lifetime of a created room thro...
# ask-ai
c
How to apply a max lifetime of a created room through agent session? Is there any option for a ttl, time to live?
t
Thanks for reaching out, Orjan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
LiveKit lets you set up room timeouts like emptyTimeout (how long to keep the room open if no one joins) and departureTimeout (how long to keep it open after everyone leaves). You can apply these settings when creating the room or through access tokens before joining. To make sure I guide you in the best way, could you please share a bit more about what you’re aiming to do? • Are you looking to set a timeout right when the agent first joins the room? • Or maybe you want to adjust timeouts dynamically during the session based on the agent’s actions? • Or perhaps you want to have an absolute maximum duration no matter what? Knowing this will really help me assist you better! Sources: packages/livekit-server-sdk/src/RoomServiceClient.ts | Core Platform Architecture & Authentication | livekit/livekit_composite | D... | livekit-agents/livekit/agents/voice/agent_session.py | Sources/LiveKit/Types/RoomConfiguration.swift
c
await session.start( room=ctx.room, agent=Assistant(), room_input_options=RoomInputOptions( noise_cancellation=noise_cancellation.BVC(), ), ) Instead of getting a room from context, can we instead just create our own room?
t
Rooms in LiveKit can't be created directly within an agent session, but don’t worry! Agents connect to rooms that are provided through the JobContext, like ctx.room. You can create rooms manually using the server API, or they can be created automatically by the system when the first participant joins, depending on how you’ve set things up. If you’re looking to create a room dynamically, the best approach is to handle this outside the agent session—perhaps through the server API—and then pass the room context into the agent session. I hope this helps clarify things! Feel free to ask if you need more guidance.
c
How is a room initially created through context?
t
Rooms are initially created in LiveKit through the following process: 1. A
Room
object is instantiated before the
JobContext
is initialized. This object serves as the client-side representation of the room. 2. The room name is assigned from the job information, ensuring the room's identity is established. 3. The
JobContext
is created with the room object, but no connection to the LiveKit server is established at this point. 4. The LiveKit server automatically creates the room during agent dispatch if it doesn't already exist. This ensures the room is available for the agent to connect. 5. To establish the connection, you must explicitly call
JobContext.connect()
. This step joins the agent as a participant in the room and enables full room functionality. If you have any questions or need a bit more help with this process, please don’t hesitate to reach out. I’m here to make sure everything goes smoothly for you! Sources: Agent dispatch | LiveKit Docs | Job lifecycle | LiveKit Docs | agents/src/ipc/job_proc_lazy_main.ts | examples/voice_agents/annotated_tool_args.py | Core Platform Architecture & Authentication | livekit/livekit_composite | D...
c
I want to overwrite the system room creating and instead use our own room creation method
t
LiveKit's default room creation system is managed by the server, but there are some great ways you can customize or take control of the process: • Explicit Room Creation: You can use the RoomService APIs to create rooms manually with specific parameters before connecting agents, giving you more control. • Token-Based Configuration: Including room configuration in access tokens lets you define room properties dynamically, which can be really handy. • Disable Auto-Creation: By setting
AutoCreate = false
in the server configuration, you can handle room creation entirely through your own application logic. • Room Presets: Server-side presets allow you to apply default configurations to rooms effortlessly. At the moment, the system doesn’t support overriding the core room creation logic (like replacing the allocator) directly. To better assist you, could you please clarify if you’re looking to: • Modify how rooms are allocated across nodes? • Implement custom naming, validation, or configuration schemes? • Integrate external systems during room creation? Understanding this will help me guide you to the best solution for your needs. Looking forward to your thoughts! Sources: Core Platform Architecture & Authentication | livekit/livekit_composite | D... | src/main/kotlin/io/livekit/server/RoomServiceClient.kt | protobufs/rpc/roommanager.proto | pkg/service/roomallocator.go | Authentication | LiveKit Docs