boundless-author-7811
03/04/2026, 7:24 AMtall-airline-16756
03/04/2026, 7:24 AMtall-airline-16756
03/04/2026, 7:24 AMproc.userdata and those resources are reused across jobs.
What to do (concrete steps)
1. Start the server in production mode:
◦ Use the start command (for example: uv run agent.py start). Production mode enables process reuse, graceful shutdown, and prewarmed idle processes.
1. Configure/process prewarming:
◦ Add a setup_fnc (prewarm function) to the AgentServer to initialize heavy resources once per process:
def prewarm(proc: JobProcess):
proc.userdata["vad"] = silero.VAD.load()
server.setup_fnc = prewarm
• That stored proc.userdata persists for that process while it remains in the idle pool and will be available when the process picks up the next job.
1. Set the number of idle processes (keep-warm pool):
◦ Configure the server’s idle-process settings (often via a num_idle_processes parameter) to the number of prewarmed workers you want to keep ready. This ensures processes are returned to the idle pool rather than terminated after each job.
Notes and expected behavior
• In production mode the framework manages a pool of reusable worker processes; after a job completes a worker will return to the idle pool (if the server is configured to keep idle workers) rather than terminate.
• If you need to change how many are kept warm, adjust the idle pool size (num_idle_processes) accordingly.
• The worker will only terminate if the server is instructed to shut down, scaled down, or if you explicitly create one-off processes that are not part of the idle pool.
If you want, tell me:
• How you currently start the agent (development vs. production command), and
• Whether you’re using a config file or environment variables for agent settings.
I can then give exact config snippets or commands tailored to your setup.
Sources: Server options | LiveKit Documentation | Server startup modes | LiveKit Documentation | Server lifecycle | LiveKit Documentationboundless-author-7811
03/04/2026, 7:28 AMnum_idle_processestall-airline-16756
03/04/2026, 7:28 AMnum_idle_processes.
Short answer
• Yes. When you run the agent in production (start) mode and don’t explicitly set num_idle_processes, the server will still keep and reuse worker processes (prewarmed/idle processes) rather than terminating them after each job. That means the same process — along with any proc.userdata you populated in your setup_fnc — can be reused for subsequent jobs.
What you can do next
• If you want to control how many prewarmed workers are kept ready, set num_idle_processes to the desired value. That determines the size of the idle pool and how many processes will be retained for reuse.
• Keep using a setup_fnc to load heavy resources into proc.userdata so reused workers don’t need to reinitialize those resources.
Quick clarifying question
• How are you starting the agent now (development vs. production command)? If you tell me that, I can suggest the exact place to add num_idle_processes or show a config snippet for your setup.boundless-author-7811
03/04/2026, 7:33 AMtall-airline-16756
03/04/2026, 7:33 AMproc.userdata during setup_fnc, and increment a job counter each time the process runs a job.
What to add (quick implementation)
1. Prewarm / initialize per-process state:
from datetime import datetime
def prewarm(proc: JobProcess):
proc.userdata["initialized_at"] = datetime.utcnow().isoformat()
proc.userdata["job_count"] = 0
<http://logger.info|logger.info>(f"Prewarmed process {proc.pid}")
server.setup_fnc = prewarm
1. Increment and log reuse in your entrypoint:
@server.rtc_session()
async def entrypoint(ctx: JobContext):
ctx.proc.userdata["job_count"] += 1
job_count = ctx.proc.userdata["job_count"]
<http://logger.info|logger.info>(f"Job started in process {ctx.proc.pid}; reused {job_count} times")
# ... job work ...
1. Optional lifecycle hooks / shutdown logging:
def on_shutdown():
<http://logger.info|logger.info>(f"Shutting down process {ctx.proc.pid}")
ctx.add_shutdown_callback(on_shutdown)
What this gives you
• Repeated logs for the same pid show reuse.
• proc.userdata gives persistent per-process metadata (init time, job count, cached resources).
• Combined with num_idle_processes, you can infer pool size and reuse behavior.
If you want more visibility
• I can show how to push these events to a metrics system (Prometheus/Grafana) or a structured logging/trace pipeline so you can query reuse counts over time.
• Or, tell me how you run the agent (command/host) and your preferred logging/metrics stack and I’ll provide a tailored snippet. Sources: Server options | LiveKit Documentationboundless-author-7811
03/04/2026, 7:36 AMtall-airline-16756
03/04/2026, 7:36 AMboundless-author-7811
03/04/2026, 7:40 AMtall-airline-16756
03/04/2026, 7:40 AM