Hi team. I have implemented a session restart mech...
# agents
h
Hi team. I have implemented a session restart mechanism when an error occurs by doing the following: await session.aclose() await session.start() The problem im facing is that Im unable to access the tracks/ transcript of the agent. I am able to hear it and it responds normally but I stop receiving the transcripts. Can someone please guide me on how to resolve this?
r
What if you use a new session instead of reusing the old one?
h
how do i use a new session?
r
You could do something like this:
Copy code
session = AgentSession(
            vad=ctx.proc.userdata["vad"],
            llm=openai.LLM(model="gpt-5"),
            stt=deepgram.STT(model="nova-3", language="multi"),
            tts=deepgram.TTS(),
            # use LiveKit's turn detection model
            turn_detection=MultilingualModel(),
        )

        await session.start(
            agent=MyAgent(),
            room=ctx.room,
            room_input_options=RoomInputOptions(
                text_input_cb=custom_text_input_cb,
                close_on_disconnect=False,
                # uncomment to enable Krisp BVC noise cancellation
                # noise_cancellation=noise_cancellation.BVC(),
                noise_cancellation=noise_cancellation.BVCTelephony(),
            ),
            room_output_options=RoomOutputOptions(transcription_enabled=True),
        )
h
this doesnt work, instead gives an error that activity happening in the previous session. Can you instead guide me on how i can just access the transcripts once i restart the session because everything else works fine
r
I don't think what you are doing is going to work.
During the close process, the session explicitly detaches all inputs and outputs, including the transcription output. I don't think all those get reconnect to and "old" session when you call
start()
I think you will need something like this:
Copy code
await session.start(  
    agent=MyAgent(),  
    room=ctx.room,  
    room_output_options=RoomOutputOptions(transcription_enabled=True),  
)
h
this is my code: try: await session.aclose() except Exception as close_err: logger.warning(f"Error while closing session during test restart: {close_err}") await session.start( agent=agent, room=ctx.room, room_input_options=RoomInputOptions( noise_cancellation=noise_cancellation.BVC(), close_on_disconnect=False, ), room_output_options=RoomOutputOptions(transcription_enabled=True), )
im doing the same thing as you're recommending, no?
r
you are reusing the old session object. I don't think you can do that
h
I'll declare a new one and see if it helps
r
pretty sure the contract on the session object is that start can only be called once. But would need to read the code to verify htat.
Curious what your usecase is?
h
I'm trying to implement a restart mechanism so that whenever an error occurs like timeout etc, the session just restarts and the conversation isnt disturbed
im using openai realtimemodal
r
fallback adapter does not do what you need?
I see
h
fallback adapter isnt available for realtime as far as I know
r
I think we have en example of recovering open ai session for instance when the session timeout happens.
h
if you can share for my pipeline set up, thatd be great!
r
h
for my usecase, autoreconnection makes sense but how do i trigger that? its not mentioned
i mean, lets assume a timeout error occurs, how do i trigger a reconnection in that scenario
r
I is built into the plugin now. Set:
Copy code
max_session_duration: float | None
    """reset the connection after this many seconds if provided"""
h
just to clarify, the time we set here is the time it will take to reconnect after it timesout, correct?
r
No. Open AI realtime sessions have a session time limit. So set the number less than what the OpenAI limit is See
DEFAULT_MAX_SESSION_DURATION
in the plugin for a recommended value.
h
thank you for sharing but this isnt my usecase. My usecase is that, if lets say an error occurs, such as openai took too long to reply for example, how do i cater to such scenarios? My approach was that i just restart the session.Can you guide me with regards to that?
r
I don't really have any examples for that.
h
alright. thank you so much for your time 🙂
r
Also, I thought the plugin handled that internally.
h
are you saying, if i use max_session_duration, all other errors such as generate_reply() timeout etc will also be catered internally? if yes then this solves my usecase
r
I don't think the retry is connected to
max_session_duration
but I maybe wrong
would have to read that plugin code to verify
h
generally speaking, what is the recommended approach by livekit in handling errors like the one i mentioned?
r
My recommendation is to use
max_session_duration
h
my usecase: if any error occurs during a conversation for example if open ai timedout midway because of taking too long to reply etc, how to handle this gracefully. sharing this just incase it helps you and livekit team. I'll try the max_session_duration in the meantime
👍 1