Explain workers in agents
# ask-ai
c
Explain workers in agents
t
Thanks for reaching out, Subham. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Let’s chat about how the LiveKit Agents framework uses something called a worker. Think of a worker as the main helper that signs in with the LiveKit server and takes care of running agent instances. So, when you start an agent app (like with
python agent.py dev
), it registers itself as a worker and patiently waits for the server to send over tasks. This worker is kind of like a web server process—it keeps an eye on things and launches agent instances in separate child processes. When someone joins a room, the LiveKit server sends a job request to a free worker, and that worker spins up a new process to handle the task. We call this process agent dispatch. Here are some neat features of workers: • Job Isolation: Workers can juggle multiple agent jobs at once, keeping each one in its own little bubble so if something goes wrong, it doesn’t mess up the others. • Load Balancing: Workers chat with the server about how busy they are, so jobs get spread out nicely based on who has the capacity. • Overload Protection: When a worker’s getting too busy—usually if CPU usage is high—it politely stops taking new jobs to avoid getting overwhelmed. • Graceful Shutdown: If a worker needs to stop, it won’t take on new jobs but will finish up the ones it’s already working on before shutting down. You can customize how a worker behaves using the
WorkerOptions
class. This lets you tweak things like load limits, permissions, dispatch rules, and health check settings to fit your needs. So, to sum it up: workers are the heart and soul of the LiveKit Agents system. They keep everything running smoothly by handling scalability, managing loads, and making sure programmable participants—like AI agents, media processors, or your own real-time logic—work reliably. Sources: Worker lifecycle | LiveKit Docs | Anatomy of an Agent | LiveKit Docs | Deployment and scaling | LiveKit Docs | README.md | livekit-agents/livekit/agents/worker.py
c
How to kill workers?
t
If you want to stop workers in LiveKit Agents, you can send a termination signal (like
SIGTERM
) to the worker process. This gently tells the worker to stop taking new jobs but lets it finish up any active sessions first, so nothing gets interrupted. If you have any questions or need a hand with this, just give me a shout—I’m here to help!
c
Can you tell me how to send the signal, any cli commands?
t
If you want to send a termination signal (SIGTERM) to a worker, you can do it easily using some standard operating system commands. Here’s a quick guide: 1. First, find the worker process ID (PID):
ps aux | grep livekit-worker
2. Then, send the SIGTERM signal to shut it down gracefully:
kill -15 <worker-pid>
And if you’re running a development worker, a simple Ctrl+C in the terminal where it’s running will send a SIGINT signal to stop it. Feel free to reach out if you want me to walk you through this or if you have any other questions! Sources: LiveKit CLI | livekit/livekit_composite | DeepWiki | agents/src/ipc/job_proc_lazy_main.ts | Worker options | LiveKit Docs
c
When we dispatch an outbound call to an agent how does it assign a worker to it? can we configure to use a specific worker?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
c
I want to kill a worker live in lk cloud, how to proceed?