is it possible to have an agent pre warmed so that...
# ask-ai
w
is it possible to have an agent pre warmed so that it is ready to talk as soon as I send a caller to it (i.e don't have to wait like 3 rings for the agent to be ready)
t
Thanks for reaching out, Drew. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can pre-warm an agent in LiveKit to make sure it’s all set and ready to handle a caller without any delay. This is done using the
prewarm
function in the LiveKit Agents framework. The
prewarm
function helps preload models and data into memory before a job even starts, which really cuts down on cold start latency. Here’s a simple way to get it going: • Create a
prewarm
function that loads resources such as voice activity detection (VAD) models or any external data you need. • Pass this
prewarm
function to
WorkerOptions
when you start the agent. • Use the
num_idle_processes
parameter in
WorkerOptions
to control how many idle warm processes you want. For example, setting
num_idle_processes=3
keeps three processes warm and ready to jump in. This way, your agent will be all warmed up and ready to respond right away when a call comes in. If you’d like, I’m here to help with any part of the setup or to provide more details! Sources: agent/main.py | examples/voice_agents/multi_agent.py | External data and RAG | LiveKit Docs | Worker options | LiveKit Docs
w
I mean can I dispatch an agent before a request is received? The use case is I want to transfer a caller to my number, then have the agent be able to start talking immediately
t
Absolutely! You can definitely dispatch an agent before a request comes in by using explicit agent dispatch during the token generation phase. This way, the agent connects to the room right alongside the user and can start interacting immediately. Here’s a simple way to get this set up: • Register the Agent: Just set the
agent_name
field in
WorkerOptions
when defining your agent. This turns on explicit dispatch and turns off automatic dispatch. • Dispatch via API: Use the
AgentDispatchService
API to explicitly dispatch the agent while generating the user’s access token. This makes sure the agent joins the room as soon as the user does. • Room Creation: Don’t worry about the room—it’s created automatically during dispatch if it doesn’t already exist. This method works really well if you want your agent ready and waiting as soon as the caller is transferred. If you’d like, I’m here to help with more details or even some code examples tailored to your setup! Sources: livekit-api/livekit/api/agent_dispatch_service.py | src/main/kotlin/io/livekit/server/AgentDispatchServiceClient.kt | pkg/agent/client.go | Web and mobile frontends | LiveKit Docs | Agent dispatch | LiveKit Docs