Our product requires an agent being in the room, o...
# ask-ai
p
Our product requires an agent being in the room, otherwise it's all moot. It's a 1 to 1, user to agent conversation. How to handle a scenario in the frontend if the agent doesn't join the room? Which kinds of events that can help in the situation?
t
Thanks for reaching out, Bilal. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let's walk through some helpful ways to handle a situation where the agent doesn't join the room. These strategies can be implemented on the frontend to improve the user experience: • Keep an Eye on the
ParticipantConnected
Event:
This event fires when someone joins the room. By checking if the participant's kind is
ParticipantKind.AGENT
, you can tell if the agent has connected. If this event doesn’t show up for the agent within a reasonable amount of time, it likely means the agent hasn’t joined yet. • Track the Agent’s State: Using the
useVoiceAssistant()
hook, you can monitor the agent’s current state, such as
initializing
,
listening
,
thinking
, or
speaking
. If the state stays at
connecting
or
initializing
longer than expected, that’s a sign the agent might not be initializing properly. • Set Up a Timeout: Consider setting a time limit, like 10 seconds. If after this time the agent is still
connecting
and you haven’t seen the
ParticipantConnected
event for the agent, you can gently notify the user about the delay. Here’s a simple example of how you might implement this in your code:
Copy code
useEffect(() => {
  if (props.state === "connecting") {
    timeoutRef.current = window.setTimeout(() => {
      if (props.state === "connecting" && agentHasConnected.current === false) {
        setShowNotification(true);
      }
    }, 10_000);
  }
}, [props.state]);
If the agent doesn’t join, it’s a good idea to kindly inform the user with a message like "Agent did not join the room." You might also want to disconnect the room to avoid users speaking into an empty session. This way, users feel informed and supported, even when things don’t go as planned. Sources: Docs::Agents | Web and mobile frontends | LiveKit Docs | agent-console/lib/event-definitions.tsx | complex-agents/role-playing/role_playing_frontend/components/session-view.t...