What is the order in which things get created duri...
# ask-ai
r
What is the order in which things get created during a calls lifecycle? I have the idea that first the room is created, then a participant joins the room. In what time or moment the agent is created before it joins the room? Tell me in as much detail as possible all the stages
t
Thanks for reaching out, Santiago. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let’s walk through the lifecycle of a call in LiveKit—it’s pretty straightforward and helps keep everything running smoothly: 1. Room Creation: The moment the first participant tries to join a room that doesn’t exist yet, the system automatically creates it. This way, there’s always a room ready and waiting for new connections. 2. Participant Joining: When someone joins, they move through these stages: ◦ JOINING: They’re just starting to connect. ◦ JOINED: They’ve received confirmation and are officially in. ◦ ACTIVE: Fully connected and able to interact with everyone in the room. ◦ DISCONNECTED: They’ve left or lost connection. 1. Agent Creation and Dispatch:Automatic Dispatch: If automatic dispatch is turned on, agents get assigned to rooms as soon as those rooms are created—no extra steps needed. ◦ Explicit Dispatch: You can also assign agents to rooms manually using the API whenever you want, giving you flexibility to bring in specific agents as needed. So, to sum it up: first, a room gets created, then participants (including agents) join in. Agents can either be assigned automatically right away or added later through API calls. And as participants go through their journey, they move from JOINING to JOINED, then ACTIVE, and finally DISCONNECTED. Hope this helps clarify how it all works!
r
I have one more question. I need to provide the Agent that will be created some context that is variable and is based on the participant that is joining the call. Is it possible to first detect the participant that is joining the call and then we pass that information of the participant as context in the system prompt right before creating it?
t
Hey there! Just a quick heads-up: we can't detect participant info or pass it to an agent's system prompt before the agent is actually created. Things like identity and attributes only become available once the agent connects to the room. But no worries! You can kick things off by initializing the agent's context with some predefined info, like job metadata or other static details, before the agent gets started. Then, as participants join the room, you can update the agent's context on the fly with their attributes. Pretty handy, right? Sources: Inside a session | LiveKit Docs | mcp/server.py | External data and RAG | LiveKit Docs | Job lifecycle | LiveKit Docs