is there a way to fix fix an issue where the agent...
# ask-ai
f
is there a way to fix fix an issue where the agent is repeating full sentences after a slight interruption or even with no interruption between consecutive turns? Happning for me with gpt-realtime-mini.
t
Thanks for reaching out, Gad. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Are you using the OpenAI Realtime API or a custom pipeline with gpt-realtime-mini? I want to make sure we find the best solution for you, and it can depend on whether you're working with a realtime model or a traditional STT-LLM-TTS pipeline. Let me know, and we'll figure this out together! Sources: Live Conversations with AI using ChatGPT and WebRTC | pipeline-llm/interrupt_user.py | livekit-agents/livekit/agents/voice/agent_session.py | OpenAI and LiveKit | LiveKit Docs | Turn detection and interruptions | LiveKit Docs
f
this is my llm: return openai.realtime.RealtimeModel( voice=voice_name, model=model_name, input_audio_transcription= InputAudioTranscription( model="gpt-4o-mini-transcribe", language="en", ), turn_detection= TurnDetection( type="semantic_vad", eagerness="auto", ) )
t
I understand how frustrating it can be to deal with repeated sentences in your setup using the OpenAI Realtime API. Let’s work through some adjustments together that might help: 1. Use Native Turn Detection: Since you’re already using
semantic_vad
for turn detection, it’s best to stick with it and avoid overriding it unnecessarily. This approach usually helps prevent repetition. 2. Stream Responses Sentence by Sentence: Try modifying your implementation to segment and stream responses at sentence boundaries. This can really reduce the chance of full sentences repeating after interruptions. 3. Prime the LLM for Concise Responses: Adding system instructions to encourage shorter, non-redundant replies can make a big difference. For example, you might use:
"You are a voice assistant. Respond concisely in short sentences."
4. Control Interruptions: Setting
allow_interruptions=False
during the agent’s speech can help prevent overlapping input and output, and then you can re-enable it afterward. 5. Handle False Interruptions: Using
false_interruption_timeout
and
resume_false_interruption=True
is a great way to manage brief noise or false triggers effectively. Give these a try, and please feel free to reach out if you’d like any more help implementing these adjustments. I’m here to support you!
f
can i do this through livekit: 1. Stream Responses Sentence by Sentence: Try modifying your implementation to segment and stream responses at sentence boundaries. This can really reduce the chance of full sentences repeating after interruptions.
t
Absolutely, LiveKit does support streaming responses sentence by sentence, which is a great way to reduce repetition and improve latency in real-time AI models. Here’s how you can do it: • Stream tokens incrementally from the LLM and detect sentence boundaries, such as by looking for periods. • Send complete sentences to a TTS engine for immediate synthesis and stream the audio back to your users. • Utilize tools like
SentenceTokenizer
to help with sentence segmentation in your real-time processing pipelines. These features really help create smooth, natural voice interactions with low latency while keeping repetition to a minimum. If you’d like, I’m here to help guide you through implementing this in your setup—just let me know! Sources: Live Conversations with AI using ChatGPT and WebRTC | Live Conversations with AI using ChatGPT and WebRTC | livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real...
f
what param can i tweak in livekit in order to mitigate this issue?
t
I understand how frustrating sentence repetition can be, and I’m here to help you with LiveKit! You might find it helpful to adjust a few parameters to improve the flow: • Presence Penalty: This gently discourages the model from repeating tokens it has already used, helping to keep things fresh. • Frequency Penalty: It nudges the model away from frequently used tokens, encouraging more varied responses. • Repeat Last N: This lets you control how many recent tokens the model considers when avoiding repetition. • Temperature: Lowering this (say, below 0.8) makes the model's responses more predictable and less repetitive. • Top-K and Top-P Sampling: These settings narrow down token choices to help prevent repetitive patterns. Also, for real-time conversational agents, using prompt engineering to ask for concise responses can really help cut down on redundancy. If you'd like, I’d be happy to walk you through how to apply these tweaks to your setup—just let me know! Sources: tools/server/tests/README.md | livekit-plugins/livekit-plugins-google/livekit/plugins/google/realtime/real... | Live Conversations with AI using ChatGPT and WebRTC
f
give me a code sample
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!