(voice_env) PS D:\Voice\Voice_Agent\tier1_livekit_...
# ask-ai
c
(voice_env) PS D:\Voice\Voice_Agent\tier1_livekit_agent> python call_agent.py start {"message": "starting worker", "level": "INFO", "name": "livekit.agents", "version": "1.2.3", "rtc-version": "1.0.12", "timestamp": "2025-08-29T084505.823166+00:00"} {"message": "starting inference executor", "level": "INFO", "name": "livekit.agents", "timestamp": "2025-08-29T084505.823472+00:00"} {"message": "initializing process", "level": "INFO", "name": "livekit.agents", "pid": 35892, "inference": true, "timestamp": "2025-08-29T084506.489737+00:00"} {"message": "killing process", "level": "INFO", "name": "livekit.agents", "pid": 35892, "inference": true, "timestamp": "2025-08-29T084806.503255+00:00"} {"message": "worker failed", "level": "ERROR", "name": "livekit.agents", "exc_info": "Traceback (most recent call last):\n File \"D:\\conda\\envs\\voice_env\\Lib\\asyncio\\tasks.py\", line 507, in wait_for\n return await fut\n ^^^^^^^^^\n File \"D:\\conda\\envs\\voice_env\\Lib\\site-packages\\livekit\\agents\\ipc\\channel.py\", line 47, in arecv_message\n return _read_message(await dplx.recv_bytes(), messages)\n ^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\conda\\envs\\voice_env\\Lib\\site-packages\\livekit\\agents\\utils\\aio\\duplex_unix.py\", line 35, in recv_bytes\n len_bytes = await self._reader.readexactly(4)\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"D:\\conda\\envs\\voice_env\\Lib\\asyncio\\streams.py\", line 769, in readexactly\n await self._wait_for_data('readexactly')\n File \"D:\\conda\\envs\\voice_env\\Lib\\asyncio\\streams.py\", line 539, in _wait_for_data\n await self._waiter\nasyncio.exceptions.CancelledError\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"D:\\conda\\envs\\voice_env\\Lib\\site-packages\\livekit\\agents\\cli\\_run.py\", line 79, in _worker_run\n await worker.run()\n File \"D:\\conda\\envs\\voice_env\\Lib\\site-packages\\livekit\\agents\\worker.py\", line 400, in run\n await self._inference_executor.initialize()\n File \"D:\\conda\\envs\\voice_env\\Lib\\site-packages\\livekit\\agents\\ipc\\supervised_proc.py\", line 169, in initialize\n init_res = await asyncio.wait_for(\n ^^^^^^^^^^^^^^^^^^^^^^^\n ...<2 lines>...\n )\n ^\n File \"D:\\conda\\envs\\voice_env\\Lib\\asyncio\\tasks.py\", line 506, in wait_for\n async with timeouts.timeout(timeout):\n ~~~~~~~~~~~~~~~~^^^^^^^^^\n File \"D:\\conda\\envs\\voice_env\\Lib\\asyncio\\timeouts.py\", line 116, in __aexit__\n raise TimeoutError from exc_val\nTimeoutError", "timestamp": "2025-08-29T084806.503759+00:00"} {"message": "draining worker", "level": "INFO", "name": "livekit.agents", "id": "unregistered", "timeout": 1800, "timestamp": "2025-08-29T084807.117577+00:00"} (voice_env) PS D:\Voice\Voice_Agent\tier1_livekit_agent>
t
Thanks for reaching out, raj. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The errors
asyncio.exceptions.CancelledError
and
TimeoutError
you’re seeing in your logs usually point to some hiccups with task cancellation and timeouts during asynchronous operations in LiveKit agents. TimeoutError: This pops up when an operation takes longer than the set time limit. Here are a few friendly tips to get past this: • Try increasing the timeout settings in your configs, like
response_timeout
for RPC calls or
timeout
in
asyncio.wait_for()
. • Make sure your backend APIs are responding within the expected time. • If you’re on AWS, consider using sustained-performance instances (like m5 or c5) to avoid running out of CPU credits. CancelledError: This one happens when a task gets cancelled on purpose, often during shutdown or if a user interrupts. To handle it smoothly: • Wrap important operations with
asyncio.shield()
to keep them safe from cancellation. • Use `try`/`except` blocks to catch and manage the error without stress. • Don’t forget to clean up resources properly in
finally
blocks. If you want a hand tweaking your configs or code, just give me a shout—I’m here to help! Sources: livekit-rtc/livekit/rtc/audio_mixer.py | server/chatgpt.py | livekit-agents/livekit/agents/stt/fallback_adapter.py | External data and RAG | LiveKit Docs
c
howw do I reduce RAG latency
t
To help reduce RAG (Retrieval-Augmented Generation) latency in LiveKit, here are some friendly tips you might find useful: 1. Optimize Network Latency: • Try to keep your agent close to services like LLM, STT, and TTS so the round-trip times are shorter and things feel snappier. 2. Enable Preemptive Generation: • Set
preemptive_generation=True
in your
AgentSession
configuration. This way, the system can start crafting responses while the user is still talking—pretty neat, right? 3. Use Efficient RAG Lookups: • Run your RAG lookups once the user’s turn finishes using
on_user_turn_completed
. This helps inject relevant context smoothly without slowing things down. 4. Handle Delays with User Feedback: • If there’s a slight pause, try giving friendly cues like "Let me look that up..." or play a quick sound effect to keep users engaged and in the loop. 5. Use Unified Models: • Consider using unified models like GritLM—they combine retrieval and generation, cutting latency by over 60%! Pretty impressive. 6. Optimize Initialization: • Load static data during the prewarm phase and pass user-specific info via metadata. This helps avoid any slowdowns while things are running. 7. Monitor Metrics: • Keep an eye on performance with LiveKit’s
UsageCollector
. It’s a great way to spot any bottlenecks and keep everything running smoothly. If you want a hand putting any of these into action, just give me a shout—I’m here to help! Sources: Agent speech and audio | LiveKit Docs | agent_extensions/agent_extensions/rag/builder.py | rag/README.md | Voice Assistants | livekit/livekit_composite | DeepWiki | Voice Assistants | livekit/livekit_composite | DeepWiki