Is there a way I can configure dispatch to return ...
# ask-ai
c
Is there a way I can configure dispatch to return error if the agent is not found?
t
Thanks for reaching out, Subham. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The LiveKit dispatch API doesn’t currently have a built-in feature to return an error if an agent isn’t found right when you create a dispatch. This is because the dispatch process works asynchronously and doesn’t check agent availability during creation. But don’t worry! You can handle this on your side by keeping an eye on participants and using timeouts. For instance, once you connect to a room, you can watch
room.remoteParticipants
to see if the agent you’re expecting joins, and set a timeout to catch if they don’t show up. I’d be happy to help you set up a pre-dispatch check for agent availability or guide you through creating a timeout and retry approach in the SDK you’re using. Just let me know what would be most helpful for you! Sources: livekit-api/livekit/api/agent_dispatch_service.py | lib/controllers/app_ctrl.dart | Voice Assistants | livekit/livekit_composite | DeepWiki | Web and mobile frontends | LiveKit Docs | examples/agent-dispatch/index.ts
c
Do the room events give something similar?
t
Yes, room events are a great way to help detect when an agent is present. You can keep an eye on the
ParticipantConnected
event and see if the participant is an agent by checking
participant.kind === ParticipantKind.AGENT
. Also, there's a handy
isAgent
utility function that you can use in your event handlers for
participantConnected
and
participantDisconnected
to easily spot agents. For instance, you might use this approach to create messages whenever an agent joins or leaves the room. Plus, webhooks like "Participant Joined" come with metadata that helps identify agents too. If you'd like, I’d be happy to share more details or examples to help you implement this smoothly in your setup. Just let me know! Sources: Web and mobile frontends | LiveKit Docs | agent-console/lib/event-types.ts | Webhooks | LiveKit Docs | How to Enable Agent-to-Agent Speech Detection in LiveKit | livekit-agents/livekit/agents/voice/room_io/room_io.py