<@U084APK40NS> this is defination of agent dispatc...
# ask-ai
b
@millions-hair-24956 this is defination of agent dispatch in agent lifecycle 1. Agent dispatch: When an end-user connects to a room, LiveKit server selects an available worker and sends it information about that session. The first worker to accept that request will instantiate your program and join the room. A worker can host multiple instances of your agent simultaneously, running each in its own process for isolation. it says it selects the available worker, so what do you mean by available worker. how livekit identify the available worker, does worker handles one call at a time if not how many call can a worker can handle, which params define this. what info does LiveKit server sends to agent
g
An "available worker" in LiveKit is defined by its ability to accept new jobs based on its current load. According to LiveKit documentation, worker availability is determined by the
load_fnc
and
load_threshold
parameters in the
WorkerOptions
configuration. The
load_fnc
returns a value between 0 and 1, indicating how busy the worker is, while the
load_threshold
is the load value at which the worker will stop accepting new jobs. By default, the
load_fnc
returns the CPU usage of the worker, and the
load_threshold
is set to 0.75. The number of calls a worker can handle depends on the system resources and the configuration of the worker. For example, a 4-core machine can typically handle about 30 concurrent voice agents, as mentioned in LiveKit's deployment guide. The LiveKit server sends session information to the worker, which includes details necessary for the worker to instantiate the agent and join the room. Would you like more detail on any specific aspect? Sources: - https://docs.livekit.io/agents/deployment/#Rollout - https://docs.livekit.io/agents/build/anatomy/ 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
how do we write load_fnc
@millions-hair-24956 how do we write load_fnc
g
To write a
load_fnc
, you need to define a function that returns a value between 0 and 1, representing the current load of the worker. This function can be customized to measure different metrics, such as CPU usage, memory usage, or any other relevant resource metric. According to LiveKit documentation, the
load_fnc
is typically used to determine how busy a worker is and whether it can accept new jobs. Here's a basic example of how you might implement a
load_fnc
that measures CPU usage:
Copy code
import psutil

def load_fnc():
    # Return the current CPU usage as a value between 0 and 1
    return psutil.cpu_percent() / 100.0
Would you like more detail on implementing or customizing this function? Sources: - https://docs.livekit.io/python/livekit/agents/index.html#livekit.agents.WorkerOptions 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
b
@millions-hair-24956 suppose load_fnc returns more then 1 am I am calling through sip trunk then what will happen and what will be end user experiance?
g
I'm not able to find any data sources to answer your question. You might want to specify what kind of fallback or error handling mechanisms you have in place for such scenarios. If this doesn't help, please reach out to the Livekit support team for further assistance. 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.