agents icon indicating copy to clipboard operation
agents copied to clipboard

Bug: StreamAdapter (text_pacing =True) + ElevenLabs causes tools to loop & agent to go silent (works without text_pacing)

Open affablebloke opened this issue 1 year ago • 4 comments

Package/version • livekit-agents==1.2.5 • ElevenLabs plugin from livekit.plugins.elevenlabs. • Observed only when wrapping ElevenLabs TTS with livekit.agents.tts.StreamAdapter. https://github.com/livekit/agents/pull/3074

What’s happening

When the agent invokes any function/tool: 1. Spoken output stops (agent goes quiet), then 2. The agent repeatedly re-invokes the same tool call in a loop when it hears new audio from the user.

If I remove text_pacing=True from StreamAdapter or use ElevenLabs TTS directly, it works as usual.

How to reproduce:

from livekit.agents.tts.stream_adapter import StreamAdapter
from livekit.plugins import elevenlabs

class MyAgent(Agent):
    def __init__(self) -> None:
        super().__init__(
            tts=StreamAdapter(
                tts=elevenlabs.TTS(
                    model=XXXXXX,
                    voice_id=XXXXXX,
                    voice_settings=elevenlabs.VoiceSettings(
                        stability=XXXXXX, similarity_boost=XXXXXX
                    ),
                    api_key=XXXXXX,
                ),
                text_pacing=True,
      ),
   tools=[...]
)

affablebloke avatar Aug 11 '25 22:08 affablebloke

I cannot reproduce the issue, can you share the logs and a reproducible example? and what is the output of pip list | grep livekit?

longcw avatar Aug 12 '25 01:08 longcw

@longcw I'll try to come up with a minimal repro. I have a PR that fixes it for my large dynamic tool calls, but it's too large and bespoke to submit as a repro right now.

https://github.com/livekit/agents/pull/3140

affablebloke avatar Aug 12 '25 17:08 affablebloke

~can you share the steps to reproduce your issue? I'd like to understand it better.~

ok I found the reason, it's when the text is empty "" the _wakeup_event is never set since there is no sentences pushed, and then the stream never closed. The empty text usually happens when LLM returns a tool call.

created a fix https://github.com/livekit/agents/pull/3146.

longcw avatar Aug 13 '25 02:08 longcw

Thanks @longcw great work!

affablebloke avatar Aug 13 '25 15:08 affablebloke