Is there a way for me to give more priority to a s...
# ask-ai
b
Is there a way for me to give more priority to a specific worker entrypoint?
t
Thanks for reaching out, miguel. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To give more priority to a specific worker entrypoint in LiveKit, you can use the following approaches: • Explicit Dispatch with Agent Names: Use the
agent_name
parameter in
WorkerOptions
to enable explicit dispatch. This allows you to specify the agent(s) to be dispatched in the end-user's token or use the
AgentDispatch.createDispatch
API. For example:
Copy code
opts = WorkerOptions(
    entrypoint_fnc=entrypoint,
    agent_name="my-priority-agent"  # Enable explicit dispatch
)
• Request Handler for Job Control: Use the
request_fnc
parameter to control which jobs a worker accepts. You can implement prioritization logic to accept or reject jobs based on your criteria. For example:
Copy code
async def request_fnc(req: JobRequest):
    # Add your prioritization logic here
    await req.accept(
        name="agent",
        identity="identity",
        attributes={"myagent": "rocks"},
    )
    # or reject it
    # await req.reject()

opts = WorkerOptions(
    entrypoint_fnc=entrypoint, 
    request_fnc=request_fnc
)
• Load-Based Job Management: Control job acceptance through load functions. The
load_fnc
and
load_threshold
parameters can limit the number of concurrent jobs a worker accepts. For example:
Copy code
from livekit.agents import Worker, WorkerOptions

def compute_load(worker: Worker) -> float:
    return min(len(worker.active_jobs) / 10, 1.0)

opts = WorkerOptions(
    load_fnc=compute_load,
    load_threshold=0.9,
)
These methods allow you to prioritize specific worker entrypoints by controlling job dispatch and acceptance. Let me know if you need further clarification or assistance with implementation. Sources: Worker options | LiveKit Docs