Hey everyone
I’m working with LiveKit agents and running into a performance issue with the per-process worker architecture. Looking for advice on best practices.
My setup:
Using livekit.agents with WorkerOptions
Running workers with uv run python -m livekit_worker dev
Each agent requires expensive initialization (DB connections, Redis pools, loading configs from disk, building complex agent objects)
The problem:
Since LiveKit spawns a new process for each request, my WorkflowEngine gets re-initialized every single call, which includes:
Loading agent configurations from disk
Creating database connection pools
Building Redis connections
Instantiating multiple agent objects
Validating complex workflow graphs
This adds 2-3 seconds to every call start time.
I have tried prewarm, it doesn’t work and same for singleton patterns (as its a new process)
Questions:
1. What’s the recommended pattern for expensive agent initialization in LiveKit’s architecture?
2. Are there any worker configuration options to reuse processes across requests?
3. How do others handle heavy infrastructure (DB pools, etc.) that needs to be initialized?