brief-vase-33757
07/11/2025, 6:36 AMtall-airline-16756
07/11/2025, 6:36 AMtall-airline-16756
07/11/2025, 6:36 AMthinking
) and updating your interface accordingly
These methods ensure users are kept informed before and during the execution of long-running operations, improving user experience.
For implementation details, use the agent's RunContext
to send feedback immediately prior to execution, or monitor state changes in your frontend to trigger feedback automatically.
Let me know if you need code examples or more details on any specific approach.
Sources: External data and RAG | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_activity.py | Tool definition and use | LiveKit Docs | Web and mobile frontends | LiveKit Docsbrief-vase-33757
07/11/2025, 6:38 AMtall-airline-16756
07/11/2025, 6:38 AMRunContext
, you can give your participants a friendly heads-up about what's happening behind the scenes. Think of it like sending a quick text to a friend saying, "Hey, working on that thing you asked about!"
• Pattern example:
import asyncio
from livekit.agents import function_tool, RunContext
@function_tool()
async def search_knowledge_base(self, context: RunContext, query: str) -> str:
async def _status_update(delay: float = 0.5):
await asyncio.sleep(delay)
await context.session.generate_reply(instructions=f"You are searching the knowledge base for '{query}' but it is taking a little while. Update the user briefly.")
status_task = asyncio.create_task(_status_update())
result = await _perform_search(query)
status_task.cancel()
return result
Pro tip: If you want to be even more direct, you can just use context.session.say("Your message")
before diving into your main task. It's like giving your users a quick wave and saying, "I'm on it!" This way, they know something's happening and won't wonder if their request got lost in the digital void. Super helpful for those tasks that might take a bit longer than a blink!
Sources: External data and RAG | LiveKit Docs | rpc/rpc_agent.py | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti...brief-vase-33757
07/11/2025, 6:40 AMtall-airline-16756
07/11/2025, 6:41 AMimport asyncio
async def _status_update(context, query, delay=0.5):
await asyncio.sleep(delay)
await context.session.generate_reply(instructions=f"You are searching the knowledge base for '{query}', but it is taking a little while. Update the user briefly.")
status_task = asyncio.create_task(_status_update(context, query))
result = await _perform_search(query)
status_task.cancel()
Pretty cool, right? This approach lets you run your main task without interruption while still keeping the user in the loop. If the search takes a bit longer than expected, they'll get a friendly update. And if it's quick, no worries – the status task gets cancelled. It's all about creating a smooth, responsive experience!
Sources: External data and RAG | LiveKit Docsbrief-vase-33757
07/11/2025, 6:45 AMtall-airline-16756
07/11/2025, 6:45 AM