I get the error "cannot schedule new speech, the s...
# ask-ai
w
I get the error "cannot schedule new speech, the speech scheduling is draining/pausing" I am trying to do a session.say after switching agents. How long do I have to wait for this error to not happen?
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.
Hey! Could you let me know if your
session.say()
call is happening during an agent transition or maybe inside a lifecycle callback like
on_exit
? Understanding this will really help us pinpoint what's causing the error and find the best fix for you. Sources: livekit-agents/livekit/agents/voice/agent_session.py
w
It's happening on an asyncio task I create like the following: asyncio.create_task(_periodic_task())
t
Hey there! This error pops up because
session.say()
depends on the agent's scheduling system, which might be paused during transitions or other lifecycle moments. So, when you're using
asyncio.create_task()
, just make sure that the task isn't trying to call
session.say()
while the agent is in the middle of transitioning or if scheduling is paused. Here’s a quick way to fix it: • Double-check that
session.say()
isn’t called during active agent transitions or when scheduling is paused. • If you want to call
say()
right after switching agents, try using the new agent’s
on_enter
callback—that way, scheduling will definitely be up and running. • Also, you might want to consider using
generate_reply()
instead of
say()
because it plays nicer with the agent’s state management. If anything’s unclear or you want a hand with these changes, just let me know—I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent.py | Agent speech | LiveKit Docs
w
can I use generate_reply with just instructions (i.e no user_input)?
t
Absolutely! You can use
generate_reply
with just
instructions
and skip the
user_input
altogether. This way, the agent creates a response based on the instructions you give, and that response gets added to the chat history—while the instructions themselves stay private. This is a great way to kick off conversations or share responses without needing any user input. If you'd like, I’m here to help you set this up! Sources: Agent speech and audio | LiveKit Docs | Voice AI quickstart | LiveKit Docs
w
how does this work under the hood? how is the llm prompted with just instructions?
t
When
generate_reply
is called with just
instructions
, the LLM creates a response based on those instructions while keeping the existing chat context intact. Think of the instructions as helpful tips guiding the agent’s reply—they don’t get added to the chat history. Here’s what’s happening behind the scenes: • For realtime models (like OpenAI or Google Gemini), a
ResponseCreateEvent
or placeholder user turn kicks off the LLM to generate a response. • For pipeline-based LLMs, the instructions get combined with the agent’s base instructions before being sent to the LLM. • A
SpeechHandle
is set up to manage the speech lifecycle, while a background task handles response generation and synthesis. • The final response is added to the chat as an assistant message, and a
speech_created
event is triggered. This setup lets agents jump in proactively with things like greetings or status updates, even when the user hasn’t said anything. If you want me to walk you through more details or share some examples, just let me know—I’m happy to help! Sources: Agent speech | LiveKit Docs | Agent speech and audio | LiveKit Docs | tests/fake_llm.py | Agents Core Architecture | livekit/livekit_composite | DeepWiki
w
I get the error ERROR livekit.agents - Error in _llm_inference_task                                                                                  Traceback (most recent call last):                                                                                                         File "/home/drew/.cache/pypoetry/virtualenvs/agent-6qPOri2k-py3.10/lib/python3.10/site-packages/livekit/agents/utils/log.py", line 16, in async_fn_logs                                              return await fn(*args, **kwargs)                                                                                                        File "/home/drew/.cache/pypoetry/virtualenvs/agent-6qPOri2k-py3.10/lib/python3.10/site-packages/opentelemetry/util/_decorator.py", line 71, in async_wrapper                                            return await func(*args, **kwargs) # type: ignore                                                                                               File "/home/drew/.cache/pypoetry/virtualenvs/agent-6qPOri2k-py3.10/lib/python3.10/site-packages/livekit/agents/voice/generation.py", line 124, in _llm_inference_task                                       async for chunk in llm_node:                                                                                                          File "/home/drew/.cache/pypoetry/virtualenvs/agent-6qPOri2k-py3.10/lib/python3.10/site-packages/livekit/agents/voice/agent.py", line 365, in llm_node                                               activity = agent._get_activity_or_raise()                                                                                                   File "/home/drew/.cache/pypoetry/virtualenvs/agent-6qPOri2k-py3.10/lib/python3.10/site-packages/livekit/agents/voice/agent.py", line 318, in _get_activity_or_raise                                        raise RuntimeError("no activity context found, the agent is not running")                                                                                  RuntimeError: no activity context found, the agent is not running {"version": "0.11.0", "id": "call_+14439006480_k5M9qBnhXpBU", "call_stage": "inbound-call", "environment": "development", "location": "us-east5", "config_name": "theinsuran cesaver", "pid": 3156033, "job_id": "AJ_GcQNnoCGRuhD"}                                                                                              2025-08-22 004636,009 - ERROR livekit.agents - Error in _tts_inference_task                                                                                  Traceback (most recent call last):                                                                                                         File "/home/drew/.cache/pypoetry/virtualenvs/agent-6qPOri2k-py3.10/lib/python3.10/site-packages/livekit/agents/utils/log.py", line 16, in async_fn_logs                                              return await fn(*args, **kwargs)                                                                                                        File "/home/drew/.cache/pypoetry/virtualenvs/agent-6qPOri2k-py3.10/lib/python3.10/site-packages/opentelemetry/util/_decorator.py", line 71, in async_wrapper                                            return await func(*args, **kwargs) # type: ignore                                                                                               File "/home/drew/.cache/pypoetry/virtualenvs/agent-6qPOri2k-py3.10/lib/python3.10/site-packages/livekit/agents/voice/generation.py", line 212, in _tts_inference_task                                       async for audio_frame in tts_node:                                                                                                       File "/home/drew/.cache/pypoetry/virtualenvs/agent-6qPOri2k-py3.10/lib/python3.10/site-packages/livekit/agents/voice/agent.py", line 386, in tts_node                                               activity = agent._get_activity_or_raise()                                                                                                   File "/home/drew/.cache/pypoetry/virtualenvs/agent-6qPOri2k-py3.10/lib/python3.10/site-packages/livekit/agents/voice/agent.py", line 318, in _get_activity_or_raise                                        raise RuntimeError("no activity context found, the agent is not running") RuntimeError: no activity context found, the agent is not running
t
Hey there! This error pops up because the agent's activity context isn’t set up right when you try to run LLM or TTS inference tasks. It usually happens if the agent isn’t running inside a session. Here’s how you can fix it: • Make sure the agent is added to an
AgentSession
. • Start the session with
await session.start(agent)
. • Only call LLM and TTS inference tasks when the agent is actively running within that session. This error usually means the inference tasks are being triggered outside of a properly started agent session. If you want, I’m here to help you get it sorted! Sources: livekit-agents/livekit/agents/voice/agent_activity.py
w
are there any recent bugs of session.say or session.generate_reply?
t
Hey there! Just to let you know, there haven't been any recent bugs or issues reported with
session.say
or
session.generate_reply
. Both of these methods should work smoothly when used as described, and tests have shown they behave well in different situations. If you’re running into any specific problems, don’t hesitate to share the details—things like error messages, stack traces, or anything unexpected you’re seeing. Also, letting us know which version of
livekit-agents
you’re using and whether you’re on LiveKit Cloud or self-hosted would be super helpful. That way, we can get you the best support possible! Sources: Agent speech and audio | LiveKit Docs | Agent speech | LiveKit Docs | examples/voice_agents/multi_agent.py | Community & Support | livekit/livekit_composite | DeepWiki | Community & Support | livekit/livekit_composite | DeepWiki
w
@wooden-librarian-60399 did you resolve this? Running into the same issue
t
Looks like someone else ran into the same issue. If you’ve already figured it out, please share how you did it! And if you’re still having trouble, just let me know—I’m here to help you out.
w
@worried-kite-20319 Unfortunately not. It was a non-critical .say(), so I just catch the exception and move on. @refined-appointment-81829 any insight here?
t
Thanks so much for the update! Catching the exception is a smart way to handle those non-critical
.say()
calls. If you want to take another look at the issue or need a hand with anything else, just give me a shout. I’m always happy to help!