fierce-jordan-44682
09/11/2025, 9:37 AMtall-airline-16756
09/11/2025, 9:37 AMtall-airline-16756
09/11/2025, 9:38 AMentrypoint
function runs whenever a new job is assigned to the worker, it's designed to set up any job-specific state or configurations—like initializing your database connection.
On the other hand, the prewarm
function is great for preparing resources that many jobs will share, such as preloading models or other heavy resources. However, it’s not the best place for tasks tied to individual jobs, like database initialization.
Sources: complex-agents/nutrition-assistant/agent.py | Worker options | LiveKit Docs | Anatomy of an Agent | LiveKit Docs | Anatomy of an Agent | LiveKit Docs | examples/other/transcription/multi-user-transcriber.pyfierce-jordan-44682
09/11/2025, 9:41 AMtall-airline-16756
09/11/2025, 9:42 AMfierce-jordan-44682
09/11/2025, 9:46 AMtall-airline-16756
09/11/2025, 9:46 AMentrypoint
function is great for setting up resources specific to each session, but for something shared like your database connection, it’s best to initialize it in a way that it can live across sessions—like using a global context or a shared resource pool.
If you are setting up the database connection inside the entrypoint
function, don’t worry! Just make sure to close it properly when the session ends. You can do this by adding a cleanup callback with ctx.add_shutdown_callback()
, which will help you close the connection and keep everything running smoothly without leaks.
Please feel free to reach out if you’d like me to walk you through the implementation or if you have any other questions—I’m here to help!