This message was deleted.
# ask-ai
s
This message was deleted.
t
Thanks for reaching out, Purushottam. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about how to import
LiveKitAPI
from the
livekit
Python package (version >= 1.1.3). You can import it from the
livekit.api
module. Example usage:
Copy code
from livekit import api

lk_api = api.LiveKitAPI(
    url="https://your-instance.livekit.cloud",
    api_key="your-api-key",
    api_secret="your-api-secret"
)
Installation note: • Install the package with:
pip install livekit-api
If you’d like, tell me: • which environment you’re running (local, Docker, serverless), and • the exact import error you’re seeing (if any), and I’ll help troubleshoot further. Sources: Python SDKs | livekit/livekit_composite | DeepWiki, with interactive elements
Thanks — I’m responding to your question about how you currently start a worker every time a "start-call" is hit and then dispatch an agent. I’ll explain how this works in a real (production) system and give practical steps to change your design. Short answer • Don’t start a worker per call. In production, workers are long-running processes that stay up and wait for dispatches. When a call starts you should dispatch an agent to an already-running worker, which then creates the agent session for that call. This avoids startup latency and scales much better. Why your current approach is problematic • Starting a new worker per call adds significant latency (process start, initialization). • It wastes resources (CPU/memory) and makes load prediction and autoscaling harder. • It prevents efficient reuse of resources and centralized management (logging, health checks, graceful shutdown). Recommended production pattern (practical) 1. Run persistent workers ◦ Start one or more worker processes at application startup (one per host or container); they should run continuously in a production "start" mode rather than dev/autoreload mode. ◦ Workers listen for job/dispatch requests and accept jobs when they arrive. 1. Dispatch agents via the API when a call starts ◦ When a "start-call" event happens, create the room or identify the room and send an agent dispatch request to the LiveKit Agent Dispatch API (don’t start a new worker process). ◦ The running worker will pick up the dispatch and spawn an agent session (JobContext) to handle that call. 1. Scale workers separately from calls ◦ Scale the number of workers based on expected concurrent calls and CPU/memory usage. A single worker can handle many sequential/parallel agent sessions depending on your load pattern. ◦ Use autoscaling groups or container orchestration (Kubernetes, ECS) to add/remove workers based on queue depth or CPU. 1. Use proper startup modes and lifecycle management ◦ Use the production-ready startup mode (for example
start
) to run workers with graceful shutdown and stable performance. ◦ Monitor health, metrics, and logs centrally so you can detect if workers are overloaded or failing. Example flow (high level) 1. Your service receives a "start-call" webhook or request. 2. Service creates/ensures the LiveKit room exists. 3. Service calls the Agent Dispatch API to request an agent for the room. 4. A running worker picks up the dispatch and starts the agent session for that room. 5. Worker manages the session until call end, then becomes available for the next dispatch. If you want, I can help you next with any of these specifics: • Example code for sending an agent dispatch request from Python. • How to run the worker in production mode (command + options). • Suggestions for autoscaling policy and metrics to monitor. • Debugging advice if your worker currently isn’t picking up dispatches. Which of these would be most helpful right now, and can you share how you currently start workers (command/container config) and how you send the dispatch today? Sources: Server startup modes | LiveKit Documentation | Introduction | LiveKit Documentation | Agent dispatch | LiveKit Documentation | Agents (Python) | livekit/livekit_composite | DeepWiki | Outbound Calling Script | LiveKit Documentation, with interactive elements
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!
a
give me a sample agent_worker code, which i can run for production
whats the problem if i run agent worker on each start-call