how do i set up filler messages for agents?
# ask-ai
m
how do i set up filler messages for agents?
t
Thanks for reaching out, Jackson. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To set up filler messages (also known as "thinking messages") for agents, you can use one of the following approaches: • Using a predefined list of messages: Create a list of predefined messages and randomly select one to display while the agent processes information. For example:
Copy code
thinking_messages = [
    "Let me look that up...",
    "One moment while I check...",
    "I'll find that information for you...",
    "Just a second while I search...",
    "Looking into that now..."
]

async def enrich_with_rag(code):
    await agent.say(random.choice(thinking_messages))
    # Perform RAG lookup...
Using dynamic LLM-generated messages: Generate messages dynamically using a language model (LLM) to indicate that the agent is looking up information. For example:
Copy code
async def enrich_with_rag(code):
    async with _chat_ctx_lock:
        thinking_ctx = llm.ChatContext().append(
            role="system",
            text="Generate a very short message to indicate that we're looking up the answer in the docs"
        )
        thinking_stream = agent._llm.chat(chat_ctx=thinking_ctx)
        await agent.say(thinking_stream, add_to_chat_ctx=False)
Both methods allow you to display interim messages while your agent processes information. Let me know if you need further assistance! Sources: Handling RAG Delays in Voice Agents | LiveKit Docs
m
if the user hasn't said anything in a while, does livekit provide a way to force the agent to say something? i.e. "are you still on the line?"
t
LiveKit provides a way to handle user inactivity by implementing silence detection. You can use a timer to monitor user interaction and take specific actions when silence is detected. For example, instead of disconnecting a call after a period of silence, you could modify the logic to send a message like "Are you still on the line?" Here’s a general approach: • Set a silence threshold (e.g., 5 seconds). • Track when the user last interacted or spoke. • Monitor the time elapsed since the last interaction. • When silence exceeds the threshold, trigger the agent to send a message. Here’s an example of how silence detection can be implemented:
Copy code
import asyncio
import time

SILENCE_THRESHOLD = 5  # seconds

async def entrypoint(ctx: JobContext):
    user_last_spoke_time = time.time()
    monitor_task = None

    async def monitor_interaction():
        while True:
            if time.time() - user_last_spoke_time > SILENCE_THRESHOLD:
                await agent.say("Are you still on the line?")
            await asyncio.sleep(1)

    @agent.on("user_started_speaking")
    def on_user_started_speaking(_msg: llm.ChatMessage):
        user_last_spoke_time = time.time()

    monitor_task = asyncio.create_task(monitor_interaction())
This approach allows you to send a message after detecting a period of user inactivity. Let me know if you need further assistance! Sources: How to detect and handle silence during calls