damp-belgium-53878
08/07/2025, 10:00 AMsession.interupt()
session.update_agent(new_agent)
I get an error: ❌ Error during handoff to interviewer: AgentSession is closing, cannot use generate_reply()
Which I do not have with regular pipeline ( stt, llm, tts )tall-airline-16756
08/07/2025, 10:00 AMtall-airline-16756
08/07/2025, 10:00 AMinterrupt()
method of AgentSession
to stop the current speech and update the chat context. This method returns an asyncio.Future
that completes once the interruption is fully processed.
2. Await the Interruption: Ensure you await the returned Future
from interrupt()
to allow the operation to complete before proceeding.
3. Check Session Activity: After the interruption, verify if the session activity is still running. If it is, you can safely call generate_reply()
to produce a new response.
Here’s an example implementation:
async def handle_interruption(session: AgentSession):
try:
# Interrupt the current session
await session.interrupt()
except RuntimeError as e:
logger.warning(f"Interrupting the session failed: {e}")
return
# Check if the session is still active
if session._activity is None:
logger.warning("Session activity is closed, cannot generate reply.")
return
# Generate a new reply after interruption
try:
handle = session.generate_reply()
await handle
except RuntimeError as e:
logger.warning(f"Generating reply after interruption failed: {e}")
This ensures the session is interrupted properly and the agent can continue processing without errors.
Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real...damp-belgium-53878
08/07/2025, 10:06 AMasync def start_interview(self):
"""Manually start the interview process"""
<http://logger.info|logger.info>(":dart: Starting interview process")
# Generate initial reply based on the prompt
await self.session.generate_reply()
tall-airline-16756
08/07/2025, 10:08 AM