agents icon indicating copy to clipboard operation
agents copied to clipboard

Allow developer to choose to whether stop response.create when generate_reply timeout

Open moz164164 opened this issue 5 months ago • 0 comments

Feature Type

I cannot use LiveKit without it

Feature Description

According to https://deepwiki.com/search/after-failed-to-generate-a-rep_2136620f-4226-4394-96f6-b0867e3fd25b?mode=deep, the timeout of generate_reply does not trigger response.cancel to stop response.create and thus openai request pipeline triggered by generate_reply still keep running even though internal generate_reply timed out happened.

We want it can allow developer to choose to whether to stop response.create when generate_reply timeout due to following 3 reasons:

  1. Our use case want openai request pipeline triggered by generate_reply completely stop when internal generate_reply time out happened.

  2. According to https://deepwiki.com/search/after-failed-to-generate-a-rep_2745306e-349a-44c8-9b7a-3bbdc43d37ce?mode=fast, when generate_reply times out locally, the OpenAI server may still be processing the original request, and a subsequent generate_reply call can trigger the "OpenAI Realtime API returned an error: RealtimeError(message='Conversation already has an active response in progress:" error. The image below show the details Image

  3. We don't need the audio playback for response.create of the timeouted generate_reply. It is costly and wasteful that openai server is still processing it (input token and output token cost money)

Workarounds / Alternatives

No response

Additional Context

To force to trigger "failed to generate a reply: generate_reply timed out.", please following the steps below:

  1. Reduce the default timeout of the corresponding source code from 10 to 0.01 in livekit/plugins/openai/realtime/realtime_model.py
  2. Use openai realtime model with openai.realtime.RealtimeModel( model="gpt-realtime", voice="marin", turn_detection=ServerVad( type="server_vad" prefix_padding_ms=300, silence_duration_ms=500, threshold=0.5, create_response=False, interrupt_response=False, ), temperature=0.6, input_audio_noise_reduction=NOT_GIVEN ), input_audio_transcription=AudioTranscription(language=lang, model="whisper-1"), max_session_duration=55 * 60,
    )
  3. Implement await agent_session.generate_reply()

moz164164 avatar Jun 25 '26 07:06 moz164164