Given a agent session configured like this, is the...
# agents
t
Given a agent session configured like this, is there any reason why we would see high CPU usage even with just 1-2 sessions?
Copy code
session = AgentSession[InterviewSessionData](
    stt=NOT_GIVEN,
    tts=NOT_GIVEN,  
    vad=NOT_GIVEN,
    llm=openai.realtime.RealtimeModel(
        voice="alloy",
        model="gpt-realtime",
        temperature=0.6,
        turn_detection=openai.realtime.realtime_model.TurnDetection(
            eagerness="low",
            type="semantic_vad",
        ),
        input_audio_transcription=openai.realtime.realtime_model.InputAudioTranscription(
            model="gpt-4o-mini-transcribe",
            language="en",
        ),
        speed=1.0
    )
    turn_detection='realtime_llm',
    allow_interruptions=True,
    discard_audio_if_uninterruptible=True,
    min_interruption_duration=0.5,
    min_interruption_words=0,
    min_endpointing_delay=0.4,
    max_endpointing_delay=6.0,
    min_consecutive_speech_delay=0.0
)
We keep seeing errors like this after a while
Copy code
"Running <Task pending name='Task-20188' coro=SpeakingRateStream._main_task() running at /root/.local/lib/python3.12/site-packages/livekit/agents/utils/log.py:16 wait_for=Future pending cb=[Task.task_wakeup()] cb=[SpeakingRateStream.__init__.locals.lambda() at /root/.local/lib/python3.12/site-packages/livekit/agents/voice/transcription/_speaking_rate.py:66]> took too long: 4.00 seconds"
Which then leads to spam like this with a few seconds between messages
Copy code
2025-09-12T18:07:01.096Z
{"message": "worker is at full capacity, marking as unavailable", "level": "INFO", "name": "livekit.agents", "load": 0.7097309168000004, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:07:01.096315+00:00"}
2025-09-12T18:07:03.876Z
{"message": "worker is below capacity, marking as available", "level": "INFO", "name": "livekit.agents", "load": 0.6279540712000005, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:07:03.875975+00:00"}
2025-09-12T18:07:19.347Z
{"message": "worker is at full capacity, marking as unavailable", "level": "INFO", "name": "livekit.agents", "load": 0.7694618414000004, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:07:19.346754+00:00"}
2025-09-12T18:07:21.873Z
{"message": "worker is below capacity, marking as available", "level": "INFO", "name": "livekit.agents", "load": 0.6999146682000005, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:07:21.873386+00:00"}
2025-09-12T18:07:42.334Z
{"message": "worker is at full capacity, marking as unavailable", "level": "INFO", "name": "livekit.agents", "load": 0.7174924972000004, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:07:42.334188+00:00"}
2025-09-12T18:07:44.846Z
{"message": "worker is below capacity, marking as available", "level": "INFO", "name": "livekit.agents", "load": 0.6934305794000004, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:07:44.845841+00:00"}
2025-09-12T18:07:58.019Z
{"message": "worker is at full capacity, marking as unavailable", "level": "INFO", "name": "livekit.agents", "load": 0.7475017008000006, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:07:58.018947+00:00"}
2025-09-12T18:08:03.112Z
{"message": "worker is below capacity, marking as available", "level": "INFO", "name": "livekit.agents", "load": 0.6091444522000005, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:08:03.112315+00:00"}
2025-09-12T18:08:05.735Z
{"message": "worker is at full capacity, marking as unavailable", "level": "INFO", "name": "livekit.agents", "load": 0.7143783202000005, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:08:05.735453+00:00"}
2025-09-12T18:08:10.801Z
{"message": "worker is below capacity, marking as available", "level": "INFO", "name": "livekit.agents", "load": 0.6931043136000004, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:08:10.801046+00:00"}
2025-09-12T18:08:13.489Z
{"message": "worker is at full capacity, marking as unavailable", "level": "INFO", "name": "livekit.agents", "load": 0.7137814910000004, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:08:13.489098+00:00"}
2025-09-12T18:08:16.264Z
{"message": "worker is below capacity, marking as available", "level": "INFO", "name": "livekit.agents", "load": 0.6262047228000005, "threshold": "_WorkerEnvOption(dev_default=inf, prod_default=0.7)", "timestamp": "2025-09-12T18:08:16.263768+00:00"}
I suspect this is due to us using aws ecs with fargate, and running out of burstable cpu credits, but even then as long as we are running openai realtime then I would assume the load on the agent server is minimal as realtime handles vad and transcripts for us? Worth noting the metrics for the ecs fargate task show usage equal to 1vcpu at 100%, so for example a 4vcpu task would be at ~25% usage while this occurs. We also only recently encountered this issue. We added the ability to dynamically configure the agent to run using a stt-llm-tts pipeline, which also meant optionally enabling things like silero per session, after which we started running into these issues intermittently.
w
Would be great to get your input @refined-appointment-81829 ๐Ÿ™Œ Really a big issue for our users at the moment
โž• 1
t
We have now tried deploying our agent onto EC2 to get around the issue of burst credits hiding the problem, and we again observe the same issue. At some point the error in
transcription/_speaking_rate.py:66
happens where the task takes too long, and after that we observe degraded performance and the agent thinking it is out of capacity, this time we also observe lots of;
Copy code
2025-09-14T18:40:40.504Z
{"message": "job executor is unresponsive", "level": "WARNING", "name": "livekit.agents", "delay": 1510, "tid": 397, "timestamp": "2025-09-14T18:40:40.504017+00:00"}
2025-09-14T18:40:40.504Z
{"message": "job executor is unresponsive", "level": "WARNING", "name": "livekit.agents", "delay": 640, "tid": 440, "timestamp": "2025-09-14T18:40:40.504195+00:00"}
2025-09-14T18:40:41.281Z
{"message": "job executor is unresponsive", "level": "WARNING", "name": "livekit.agents", "delay": 1396, "tid": 379, "timestamp": "2025-09-14T18:40:41.280958+00:00"}
The usage sits neatly at 25% of a 4vcpu compute optimized machine, once an agent reaches this state we can only restart it to resolve the problem, it never recovers on its own.
w
@dry-elephant-14928 @refined-appointment-81829 would really be great if someone from LiveKit could help us out with this. Really a critical issue for our users ๐Ÿ™
@jolly-air-155 would really appreciate your input here - any idea how we can solve this? ๐Ÿ™
t
Whenever this issue happens for us, it is not a gradual increase in cpu usage until we reach a limit, the usage spikes within a few minutes and then stays stuck.
j
which version and cpu are you using? and what if you disable the transcription/audio sync via
RoomOutputOptions.sync_transcription=False
?
t
We have tried both versions 1.2.6 and 1.2.8, we use aws c7a.xlarge instances, so its 4 cores of a 4th gen amd epyc. We have not tried explicitly setting that option no, i can disable it, but we have no reliable way of reproducing so it would take some time to know. Worth noting that not all jobs fail this way, sometimes it works just fine for a few jobs before breaking.
j
this sounds like an issue of the server, maybe you can try the agents cloud for deployment and see if itโ€™s stable
t
We have tried both removing any references to our non-realtime pipeline, so no more silero VAD etc that could for some reason be hogging the CPU, we also disabled transcription syncing, and we have encountered the error again. We will try migrating to livekit agent cloud but im not super-optimistic about that working.
p
I modified the LiveKit code to perform profiling 10s before the worker is getting killed (with
_WorkerOptions._multiprocessing_context=spawn
). Below is the exported files. Both the speedscope and chrometrace states that the _`_wait_buffered_audio`_ keep taking the main event loop. Do we have any solution for them?
t
@jolly-air-155 I can confirm that the issue persists even in the livekit agent cloud, the agent did restart itself after a while of this behavior, but that still took almost 3 hours during which the agent was unusable.
j
I donโ€™t think _`_wait_buffered_audio`_ is the reason, itโ€™s just waiting for the audio to be played out. can you share a reproducible example?
I am suspecting there are some synced method like threading/multiprocessing Queue used in your agent in the async event loop that blocked the event loop.
๐Ÿ‘€ 1
p
@tall-librarian-71494 can you try to downgrade livekit-agents to 1.2.6? I've tried it and seem the worker is not getting killed anymore (not really sure, I'm still tracking)
t
We first noticed the issue on 1.2.6, we only upgraded to 1.2.8 as an attempt to fix it.
๐Ÿ‘€ 1
p
@tall-librarian-71494 can you try
AgentSession.resume_false_interruption = false
? Perhaps I found the issue.
t
We have rewritten some of our logic which we suspect could have stalled the main event loop until it became unrecoverable, however since we could never reproduce the issue reliably, right now we are monitoring the agent for a few days.
If we end up seeing the issue again, I will try this!
๐Ÿ™ 3