How to implement filler response programatically i...
# ask-ai
l
How to implement filler response programatically in LiveKit agent? I don't want to rely on LLM only rather basically want to invoke filler response in before calling each tool , does LiveKit provides any functionality to facilitate this?
t
Thanks for reaching out, Munim. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're exploring ways to implement filler responses programmatically in a LiveKit agent without relying on LLMs! You can achieve this smoothly by using the
on_user_turn_completed
lifecycle hook. This handy hook triggers right after the user's turn ends and just before the agent starts crafting its full response. It’s a great spot to insert some friendly, pre-scripted verbal acknowledgments that can really help improve conversational flow and make the experience feel more natural. Here’s a simple way to get started: 1. Create a list of predefined filler phrases like "Let me think about that" or "One moment please." 2. Use the
session.say()
method to immediately send these filler responses. To keep things tidy, set
add_to_chat_ctx=False
so these fillers don’t get added to the conversation history. 3. Mix it up by randomizing which filler phrase gets picked each time for a more dynamic feel. Here’s a quick example to illustrate:
Copy code
import random

class NonLLMFillerAgent(Agent):
    def __init__(self):
        super().__init__(instructions="You are a helpful assistant")
        self._filler_phrases = [
            "Let me think about that",
            "One moment please",
            "That's a good question",
            "Hmm, let me see",
            "Just a second",
            "Got it",
            "Okay"
        ]

    async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage):
        filler = random.choice(self._filler_phrases)
        self.session.say(filler, add_to_chat_ctx=False)
If you want to add filler responses before tool calls, you can tap into tool execution callbacks like
_tool_execution_started_cb
and
_tool_execution_completed_cb
. While there isn’t a built-in feature that automatically generates filler responses before each tool call, you can certainly add your own custom logic inside your tool functions to emit filler responses using
session.say()
. Please don’t hesitate to reach out if you’d like me to walk you through any part of this or help with anything else. I’m here to support you! Sources: Pipeline nodes and hooks | LiveKit Docs | livekit-agents/livekit/agents/beta/workflows/email_address.py
l
But if i use on_user_turn_completed then will it invoke after every user response? I don't really want that right, I only what to add filler on those our agent will invoke a function call, or we can configure agent.say to be called before func call? please do teach me if I am wrong
t
You're absolutely right that
on_user_turn_completed
gets called after every user response, which might not be exactly what you want if you're aiming to add filler responses only when a function call is triggered. To help you achieve this smoothly, you can set up filler responses to activate specifically just before function calls. Here's a friendly approach you can try: Triggering Filler Responses Before Function Calls 1. Make use of the
_tool_execution_started_cb
callback or incorporate some custom logic within your tool functions to send out filler responses right before execution starts. 2. Use
session.say()
with a ready-made filler phrase like "Let me check that for you," and set
add_to_chat_ctx=False
so it doesn’t get added to the conversation context. Here’s a simple example to illustrate this:
Copy code
class FunctionCallFillerAgent(Agent):
    def __init__(self):
        super().__init__(instructions="You are a helpful assistant")
        self._filler_phrases = [
            "Let me check that for you",
            "One moment, please",
            "I'll look into that right away"
        ]

    async def _tool_execution_started_cb(self, tool_name, tool_input):
        # Emit a filler response before the tool execution starts
        filler = random.choice(self._filler_phrases)
        await self.session.say(filler, add_to_chat_ctx=False)
This way, your filler responses will only pop up when a tool is about to run, which fits perfectly with what you’re aiming for. If anything is unclear or you’d like a hand setting this up, please don’t hesitate to ask—I’m here to help! Sources: Pipeline nodes and hooks | LiveKit Docs | Agent speech and audio | LiveKit Docs | examples/warm-transfer/warm_transfer.py | delay-handling/README.mdoc
l
And will it block the tool call? like will the tool call start immeditately after firing the cb or it will wait until tts stops speaking the filler?
t
When using
session.say
, the tool execution doesn’t wait for the TTS to finish speaking the filler. Instead, the tool call starts right after the TTS playout begins and once the text generation is fully completed. This helps keep the message and execution in the right order. Here’s a simple breakdown of how it works: • TTS Playout Initiation: When you call
session.say
, it kicks off speech generation asynchronously. • Tool Execution Timing: The tool starts running after the very first audio frame of the TTS playout is processed. This means the audio playback has begun, but it doesn’t wait for the entire TTS to finish. • No Blocking on Full Playout: The tool call moves forward independently from the full TTS playback, so your agent stays responsive. This setup ensures that filler responses play smoothly while keeping everything responsive and in the right order. If you’d like me to explain anything further or have any questions, just let me know—I’m here to help! Sources: livekit-agents/livekit/agents/voice/agent_session.py
c
Does this rule hold good even for llm call? I.e, will the LLM call also start only after the first frame has started?
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!