Production ready

One LiveKit account often runs many workers. You need dispatch rules so the triage worker picks up medical rooms and not, say, a sales demo. Explicit dispatch with a named agent is the clean way to do it.

triage_agent.py
python
if __name__ == "__main__":
    # Explicit dispatch: this worker only runs when a room
    # asks for "medical-triage-agent" by name
    cli.run_app(
        WorkerOptions(
            entrypoint_fnc=entrypoint,
            agent_name="medical-triage-agent",
        )
    )

Setting agent_name switches the worker from automatic to explicit dispatch. Rooms that do not request this agent by name never wake it up. That is how you keep many workers in one project without stepping on each other.

router.py
python
from livekit import api

async def get_connection(request: ConnectionRequest):
    room_name = generate_room_name()  # returns "medical_AB12CD34"
    token = create_access_token(room_name, identity, name)

    lk_api = api.LiveKitAPI(
        url=server_url.replace("wss://", "https://"),
        api_key=LIVEKIT_API_KEY,
        api_secret=LIVEKIT_API_SECRET,
    )

    # Ask LiveKit to dispatch our named worker into this room
    await lk_api.agent_dispatch.create_dispatch(
        api.CreateAgentDispatchRequest(
            agent_name="medical-triage-agent",
            room=room_name,
            metadata='{"demo": "medical-office-triage"}',
        )
    )

    return ConnectionResponse(
        server_url=server_url,
        room_name=room_name,
        participant_token=token,
    )

Your backend mints a LiveKit access token for the caller, then explicitly dispatches the named worker into the room. The caller joins, the worker joins, triage starts talking. No ambiguity about which agent handles the call.

Ordering exercise: Order the production dispatch flow

Loading practice…

Validation checklist: Production readiness checklist

Loading practice…

Automatic dispatch is fine when you have one worker per project. The moment you run multiple demos or multiple products in the same LiveKit account, workers start grabbing rooms that do not belong to them. Explicit dispatch with a named agent is the boundary you want. It is also how LiveKit handles canary deploys and A/B testing between agent versions.

Checkpoint: Production readiness checkpoint

Loading practice…