elegant-coat-98622
09/30/2025, 8:38 AMtall-airline-16756
09/30/2025, 8:38 AMtall-airline-16756
09/30/2025, 8:38 AMload_threshold or load_func to allow 7-10 concurrent jobs per agent worker. You can achieve this by defining a custom load_func that calculates the worker's load based on the number of active jobs. Just a quick note: this setup is supported only in custom deployments, not in LiveKit Cloud.
Here are some examples in Python and Node.js to guide you:
Python Example:
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,
)
Node.js Example:
import { Worker, WorkerOptions } from '@livekit/agents';
const computeLoad = (worker: Worker): Promise<number> => {
return Math.min(worker.activeJobs.length / 10, 1.0);
};
const opts = new WorkerOptions({
loadFunc: computeLoad,
loadThreshold: 0.9,
});
In these examples, the load_func calculates the load as the ratio of active jobs to a maximum of 10. The load_threshold is set at 0.9, which means the worker will stop accepting new jobs once it reaches 9 or more concurrent jobs. Feel free to adjust the denominator or threshold value to better fit your specific needs. If you have any questions or want to explore this further, I'm here to help!
Sources: Docs::Agents | Worker options | LiveKit Docselegant-coat-98622
09/30/2025, 8:49 AMtall-airline-16756
09/30/2025, 8:50 AMload_threshold is crossed, LiveKit updates the worker's availability status automatically. This status change lets the LiveKit server know the worker should pause accepting new jobs, and it’s really handy for external autoscalers to manage scaling smoothly.
Here’s a simple breakdown:
• The worker regularly checks its load using the load_fnc, which gives a value between 0 and 1.
• When the load goes over the load_threshold, the worker marks itself as unavailable (WS_FULL), and this update is logged and sent to the LiveKit server.
• Your autoscaler (like Kubernetes Horizontal Pod Autoscaler) can watch these updates to decide when to scale.
To set this up, just configure your autoscaler to keep an eye on the same load metric from load_fnc. You’d want it to scale out a bit before hitting the threshold—say, if your threshold is 0.9, you might start scaling at 0.7—to keep everything running smoothly.
If you’d like, I’m here to provide more details or walk you through some examples. Just let me know!
Sources: Deployment and scaling | LiveKit Docs | Docs::Agents | agents/src/worker.ts | livekit-agents/livekit/agents/worker.py