fierce-answer-55580
08/27/2025, 5:28 PMtall-airline-16756
08/27/2025, 5:28 PMtall-airline-16756
08/27/2025, 5:29 PMuseVoiceAssistant hook from @livekit/components-react is your friend. This handy hook gives you the agent's current state through the state property, which could be one of these: disconnected, connecting, initializing, listening, thinking, or speaking.
Here’s a quick example to help you get started:
import { useVoiceAssistant } from '@livekit/components-react';
function MyComponent() {
const { state: agentState } = useVoiceAssistant();
if (agentState === 'speaking') {
console.log('Agent is currently speaking');
// You can update your UI here to show the speaking state
} else if (agentState === 'listening') {
console.log('Agent is currently listening');
// And here, update the UI to show the listening state
}
return (
<div>
<p>Agent State: {agentState}</p>
</div>
);
}
Also, just so you know, the agent's state is published as a participant attribute (lk.agent.state) on the agent participant. The useVoiceAssistant hook keeps this updated in real time, which means you can easily adjust your UI or trigger actions based on what the agent is doing. Hope this helps you out!
Sources: AI voice agents | LiveKit Docs | Web and mobile frontends | LiveKit Docs | components/session-view.tsx | complex-agents/drive-thru/frontend/components/session-view.tsx