able-jackal-84140
07/11/2025, 5:56 AMtall-airline-16756
07/11/2025, 5:56 AMtall-airline-16756
07/11/2025, 5:56 AMthinking
for more than 3 seconds by listening for the agent_state_changed
event and starting a timeout when the state becomes thinking
. If the state is still thinking
after 3 seconds, use session.generate_reply()
to send a brief update message to the user. Cancel the timeout when the agent leaves the thinking
state to prevent duplicate notifications.
This method ensures your users get a natural, reassuring update during any long processing period. For example:
async def on_agent_state_changed(event):
if event.new_state == "thinking":
# Start your timeout here (3 seconds)
...
elif event.old_state == "thinking":
# Cancel the timeout if agent stops thinking
...
Then, in your timeout handler, call:
await session.generate_reply(instructions=
"You are taking a little while to process the request. Give the user a very brief update that you're still working on their request. Keep it short and natural."
)
This pattern is fully described in the LiveKit agent documentation and code examples.
Sources: livekit-agents/livekit/agents/llm/utils.py | Events and error handling | LiveKit Docs | External data and RAG | LiveKit Docs | Handling RAG Delays in Voice Agents | LiveKit Docs