how long does it take to switch agents using sessi...
# ask-ai
w
how long does it take to switch agents using session.update_agent? how long does draining / pausing go on for?
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.
Just a heads-up: the time it takes to switch agents using
session.update_agent
and how long draining or pausing lasts can vary. It really depends on wrapping up current tasks, like finishing speech generation and getting the new agents ready to go.
w
what's the average time
t
Hey there! Just a quick note about switching agents using
session.update_agent
or when draining/pausing — there isn't an exact average time documented. The time it takes can vary depending on things like the size of the model, how busy the system is, and network speed. For draining, there's a
drain_timeout
parameter in
WorkerOptions
that defaults to 30 minutes, but that's more of a maximum timeout rather than a typical duration. Hope that helps clear things up!
g
Hi @wooden-librarian-60399, Did you got any solution here? I am also facing this draining/pausing issue when trying to emit speech (session.say) after session.update_agent, it was working fine with some small delays like 0.3s before but now I added extra delay, and still sometimes its failing with agent is on draining state. Please help
t
I'd love to help you get to the bottom of this! Could you please share a bit more about the issue you're experiencing? Specifically: • What exact error message or behavior do you notice when the agent is in a draining state? • What kind of delay have you added, and how are you applying it? • Are there any particular settings or parameters you're using with
session.update_agent
or
session.say
? With these details, I'll be better equipped to assist you. Looking forward to your reply!
g
I am updating tts, stt and llm for Agent (type) with
session.update_agent
, then added a delay with
await asyncio.sleep(0.3)
then speaking a phrase
await session.say(phrase, allow_interruptions=False)
But sometimes getting error --> in entrypoint: cannot schedule new speech, the speech scheduling is draining/pausing Traceback (most recent call last): File "/home/appuser/main.py", line 1198, in entrypoint
t
Hi there! The error message "cannot schedule new speech, the speech scheduling is draining/pausing" usually pops up when speech is being scheduled during an
AgentActivity
transition, like inside
session.update_agent()
. This happens because the current activity is in a draining state, which means new speech can’t be scheduled unless it’s explicitly allowed. Here’s how you can smoothly resolve this: 1. Try using
session.say()
to schedule speech. This method is designed to handle the draining state gracefully and will route speech to the next available activity for you:
Copy code
await session.say("Hello, how can I help you?", allow_interruptions=False)
1. Make sure to sequence your calls properly when using
session.update_agent()
. For any speech during the transition, use session-level methods like `say()`:
Copy code
await session.update_agent(new_agent)
await session.say("Switching to new agent configuration.")
By following these steps, you’ll help ensure that speech scheduling fits nicely with the agent’s state transitions and avoid running into that draining/pausing error. If you need any more help, feel free to ask—we’re here for you! Sources: tests/test_agent_session.py | agents/src/voice/agent_session.ts
g
yes I am following same, but still getting this error some of the times, how I can make sure to emit speech with
await session.say("Switching to new agent configuration.")
only after its explicitly allowed
t
I’m glad you reached out! To make sure speech only happens after it’s clearly allowed during agent transitions, here’s a helpful approach you can try: 1. Use
session.say()
to schedule your speech. This handy method takes care of the draining state for you and makes sure the speech flows smoothly to the next activity when it’s ready. 2. Keep an eye on the order of your calls. For instance, it’s best to wait until the agent update process finishes before you schedule any speech. Here’s a little example to guide you:
Copy code
# Step 1: Update the agent\nawait session.update_agent(new_agent)\n\n# Step 2: Schedule speech\nawait session.say("Switching to new agent configuration.", allow_interruptions=False)
This way, you’re making sure speech only happens after the agent transition is fully done and the system is all set to handle new speech requests. If you have any questions or want to chat more about this, I’m here to help! Sources: Agent speech and audio | LiveKit Docs | tests/test_agent_session.py | agents/src/voice/agent_session.ts