I’m using explicit agent dispatch in LiveKit (by s...
# ask-ai
f
I’m using explicit agent dispatch in LiveKit (by setting the agent name in the access token). When a participant leaves a room and tries to rejoin immediately with the same access token, the agent doesn’t start up. However, if I wait a few minutes and then rejoin with the same token, the agent instantiates correctly. There are no errors in the logs when this happens — text data is being sent, but the agent does not respond. My setup also includes a cleanup callback that is run asynchronously when a participant leaves. My questions are: 1. Is there a short period after leaving a room where rejoining with the same token is not possible? 2. Could the cleanup callback (which may take some time to finish) be blocking the agent from being dispatched immediately? 3. Is this expected behavior when using explicit dispatch with tokens, or should the agent always rejoin immediately as long as the token is valid?
t
Thanks for reaching out, Mok. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thank you for your questions about explicit agent dispatch in LiveKit! I’m happy to help clarify things for you: 1. There’s no built-in restriction stopping a participant from rejoining a room right away with the same token, as long as that token is still valid. Just keep in mind that rejoining might trigger agent dispatch again if your token includes dispatch directives. 2. The cleanup callback could sometimes slow down agent dispatch if it’s doing something that blocks or interferes with the process. To keep things running smoothly, it’s best to make sure this callback is quick and non-blocking. 3. Generally, rejoining with the same token should dispatch the agent right away, assuming the token is valid and there aren’t any blocking operations or bugs in the system. Since LiveKit doesn’t automatically prevent duplicate dispatches, it’s a good idea to add some safeguards on your side—like checking existing dispatches with
listDispatch()
, using short-lived tokens, and managing dispatch state in your backend—to keep everything consistent. Please feel free to reach out if you’d like me to explain anything further or if you need a hand setting up these safeguards. I’m here to help! Sources: Managing participants | LiveKit Docs | Authentication | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts | Dispatching agents | LiveKit Docs | Agent dispatch | LiveKit Docs