quick-cartoon-22764
11/24/2025, 5:03 AMtall-airline-16756
11/24/2025, 5:03 AMtall-airline-16756
11/24/2025, 5:03 AMquick-cartoon-22764
11/24/2025, 5:15 AMtall-airline-16756
11/24/2025, 5:16 AMentrypoint can read ctx.job.metadata to determine which agent to instantiate.
• A single worker process can run multiple isolated agent sessions concurrently; selecting the agent based on metadata is a supported pattern.
Quick implementation notes
• Parse agent_name (or agent_type) in the entrypoint and instantiate the corresponding agent class before starting the session.
• Ensure each agent’s code is importable in the worker process.
• Keep session isolation (separate tasks/processes or careful async isolation) so agent state, plugins (STT/TTS/LLM), and event handlers don’t interfere.
• Prewarm shared resources if needed to reduce startup latency.
• Monitor CPU/memory and scale by adding workers when concurrency approaches capacity.
If you want, share:
• the isolation model you’ll use (in-process async tasks vs separate processes/containers) and
• an estimate of concurrent agents
I’ll suggest concrete code patterns and sizing guidance.
Sources: Job lifecycle | LiveKit docs | Agents v0.x migration guide - Node.js | LiveKit Docs | Agent server options | LiveKit docs | SIP participant | LiveKit docsquick-cartoon-22764
11/24/2025, 5:17 AMtall-airline-16756
11/24/2025, 5:17 AMJobContext and Room — so sessions are separated by design.
• You must avoid introducing cross-session shared state in your application code.
Practical steps (do these)
• Instantiate one AgentSession per job. Keep all session state inside that session object.
• Parse agent_name from ctx.job.metadata in your entrypoint and create the appropriate agent instance for that session.
• Do not use global mutable variables for session-specific data. Use:
◦ ctx.proc.userData for shared, stateless prewarmed resources (models, VAD).
◦ session.userdata or ctx for per-session state.
• Use prewarm() to load heavy shared resources once (store in proc.userData) — only share stateless objects.
• Add per-job shutdown/cleanup callbacks (via ctx.add_shutdown_callback) to release resources and prevent leaks.
• Ensure unique participant identities per session (e.g., agent-<jobid>) to avoid naming collisions.
• Monitor CPU/memory and scale workers if concurrency approaches capacity.
Optional security
• Enable per-room E2EE if you need stronger cryptographic separation.
If you want, share:
• whether you’ll run sessions as in-process async tasks or rely on the framework’s subprocess model, and
• expected concurrent sessions
I’ll provide a short code pattern and sizing tips based on that.
Sources: Job lifecycle | LiveKit docs | Agent server | LiveKit docs | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | Agent session | LiveKit docs | Agent server options | LiveKit docs