I would like to A/B test agents. is there anyway t...
# ask-ai
w
I would like to A/B test agents. is there anyway to non-deterministically dispatch agents into a room? ex. 50% of the time dispatch agent named A and 50% agent named B
t
Thanks for reaching out, Drew. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether LiveKit can non-deterministically dispatch agents (e.g., 50/50 A vs B) for A/B testing. LiveKit does not provide probabilistic or traffic-splitting dispatch built into agent routing. Agent dispatch is deterministic — agents are selected explicitly via the Agent Dispatch API, room token
RoomConfiguration.agents
, or SIP dispatch rules. You can A/B test by implementing the split in your own backend before calling LiveKit: • Use your backend to randomly (or via experiment IDs) choose Agent A or B per room with your desired distribution. • Call the Agent Dispatch API (or set
RoomConfiguration.agents
in the room token) with the chosen agent name to create the room/dispatch. If you’d like, I can: • Give a short code example in your preferred language showing a 50/50 dispatch decision and the corresponding API call, or • Suggest ways to log/measure which agent handled each room for experiment analysis. Which would you prefer? Sources: Agent dispatch | LiveKit docs | SIP dispatch rule | LiveKit docs
m
agent not joining : (index):68 [LiveKit Loader] Script execution started (index):69 [LiveKit Loader] Document ready state: loading (index):73 [LiveKit Loader] Creating script element... (index):78 [LiveKit Loader] Script src set to: https://cdn.jsdelivr.net/npm/livekit-client@1.15.0/dist/livekit-client.umd.min.js (index):138 [LiveKit Loader] Appending script to document.head... (index):140 [LiveKit Loader] Script appended, waiting for load... app.js:4 [App] Script execution started app.js:5 [App] Document ready state: interactive app.js:315 [App] DOM already loaded app.js:318 [App] LiveKit not ready, setting up event listeners... (index):81 [LiveKit Loader] Script onload fired (index):86 [LiveKit Loader] Checking for window.LiveKit: undefined (index):87 [LiveKit Loader] Checking for window.LivekitClient: object (index):88 [LiveKit Loader] Checking for window.livekit: undefined (index):97 [LiveKit Loader] Found LivekitClient (lowercase k) (index):109 [LiveKit Loader] LiveKit client loaded successfully, aliases set app.js:321 [App] Received livekit-ready event Object app.js:49 Using window.LiveKit (index):114 [LiveKit Loader] Dispatched livekit-ready event app.js:109 [App] Start button clicked app.js:119 [App] Fetching /api/connect... app.js:132 [App] Received API response: Object app.js:141 [App] Checking for LiveKit: Object app.js:155 [App] Connecting to LiveKit room... app.js:160 [App] Room connected successfully app.js:190 [App] Room connect() completed app.js:200 [App] Checking microphone permission... app.js:205 [App] Microphone permission granted app.js:213 [App] Enabling microphone in LiveKit room... utils.ts:178 publishing track Object app.js:185 [App] Local track published: audio app.js:215 [App] Microphone enabled successfully app.js:268 LiveKit detected, initializing app... app.js:40 App already initialized, skipping... initApp @ app.js:40Understand this warning utils.ts:178 disconnect from room {identity: 'user-1764708463668'} app.js:165 [App] Room disconnected: 1
t
Thanks — I looked over your logs. You’re seeing the client load, connect briefly, then immediately disconnect, which prevents the agent from being dispatched or joining. Here’s what to check and next steps to get the agent joining. What I’m responding to: your browser console logs showing the LiveKit client loading, a successful room connect, then an immediate disconnect. Immediate checks and fixes 1. Fix the client global name • Use the official UMD export
window.LiveKit
. Update your script tag to:
Copy code
<script src="https://cdn.jsdelivr.net/npm/livekit-client@1.15.0/dist/livekit-client.umd.min.js"></script>
• Verify:
Copy code
console.log(window.LiveKit); // should be defined
const { Room } = window.LiveKit;
1. Capture the disconnect reason • Add a listener to see why the client disconnected:
Copy code
room.on('disconnected', (reason) => {
  console.error('Disconnected:', reason);
});
Common reasons: duplicate identity, join failure, room deleted, or an explicit
room.disconnect()
call. 1. Check for accidental disconnect calls or identity conflicts • Search your frontend/backend for any
room.disconnect()
calls or logic that might end the session after connect. • Make sure each participant identity is unique (duplicate identities cause immediate disconnect). 1. Ensure your agent dispatch flow runs after a stable join • Agent dispatch relies on a stable participant. If your client disconnects right away, the agent won’t be created. • If you dispatch via backend, call the Agent Dispatch API after confirming the participant has fully joined (or use server-side logic tied to your connect endpoint). If you want, I can: • Provide a short code example (Node/Python) that does a 50/50 backend A/B dispatch and calls the Agent Dispatch API, or • Help interpret any disconnect reason you get from step 2 — paste the exact value and I’ll explain next steps. Which would you like me to do next? Sources: Agent dispatch | LiveKit docs | SIP dispatch rule | LiveKit docs | Connecting to LiveKit | LiveKit docs
I can help — I’ll provide a concise patch/workflow you can apply to ensure a LiveKit Cloud agent is dispatched and joins a room. I’ll include: • backend dispatch example (50/50 A/B split) • ensure agent registration/name matching • token/room configuration notes • client-side checks to keep the participant connected Which language do you want the code in? (Node.js or Python)