When I setup a worker, I'm using cli.run_app(opts)...
# ask-ai
p
When I setup a worker, I'm using cli.run_app(opts) where opts is the worker options, that I'm able to specifiy the agent name, in a usecase where different agents might be dispatched to a session, is there a way I can setup a single Worker that will be able to dispatch different agents with different entrypoint_fn and different agent-name?
t
Thanks for reaching out, Kaique. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Just a quick heads-up: a single LiveKit worker can’t be set up with multiple different
entrypoint_fn
and
agent_name
combos. Each worker is meant to have one entrypoint function and, if you want, one agent name. If you want to run different agents with their own entrypoint functions and agent names, the best way is to create separate worker processes—each with its own specific
entrypoint_fn
and
agent_name
. Here’s a simple example: • Worker 1 - Customer Service Agent:
Copy code
async def customer_service_entrypoint(ctx: JobContext):
    # Customer service specific logic
    pass

if __name__ == "__main__":
    cli.run_app(
        WorkerOptions(
            entrypoint_fnc=customer_service_entrypoint,
            agent_name="customer-service-agent",
        )
    )
• Worker 2 - Sales Agent:
Copy code
async def sales_entrypoint(ctx: JobContext):
    # Sales specific logic
    pass

if __name__ == "__main__":
    cli.run_app(
        WorkerOptions(
            entrypoint_fnc=sales_entrypoint,
            agent_name="sales-agent",
        )
    )
Once you have these workers up and running, you can dispatch the right agent using the
AgentDispatchService
like this:
Copy code
# Dispatch customer service agent
await lkapi.agent_dispatch.create_dispatch(
    api.CreateAgentDispatchRequest(
        agent_name="customer-service-agent", 
        room=room_name, 
        metadata="customer_service_job"
    )
)

# Dispatch sales agent
await lkapi.agent_dispatch.create_dispatch(
    api.CreateAgentDispatchRequest(
        agent_name="sales-agent", 
        room=room_name, 
        metadata="sales_job"
    )
)
This way, everything stays nicely separated and flexible for your different agent types. If you want me to walk you through anything else or have questions, just let me know—I’m here to help!