melodic-arm-17634
03/25/2025, 3:19 PMtall-airline-16756
03/25/2025, 3:20 PMtall-airline-16756
03/25/2025, 3:20 PMthinking_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:
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 Docsmelodic-arm-17634
03/25/2025, 3:21 PMtall-airline-16756
03/25/2025, 3:21 PMimport 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