what is the best way to know when the agent is tal...
# ask-ai
a
what is the best way to know when the agent is talking from the front end?
t
Thanks for reaching out, Anne. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! To figure out when an agent is talking from the frontend in LiveKit, you can keep an eye on the agent's state using these handy methods: • React Components: If you're working with React, the
useVoiceAssistant
hook is your friend for tracking the agent's state. Here's a quick example:
Copy code
import { useVoiceAssistant } from '@livekit/components-react';

function MyComponent() {
  const { state: agentState } = useVoiceAssistant();
  const isAgentSpeaking = agentState === 'speaking';
}
Participant Attributes: You can also watch the
lk.agent.state
attribute for any changes. Check this out:
Copy code
room.on('participant_attributes_changed', (changedAttributes, participant) => {
  if (participant.kind === ParticipantKind.AGENT) {
    const agentState = participant.attributes['lk.agent.state'];
    if (agentState === 'speaking') {
      console.log('Agent started speaking');
    }
  }
});
The agent's state can be one of these:
'initializing'
,
'listening'
,
'thinking'
, or
'speaking'
. If you want me to walk you through anything else or have questions, just give me a shout! Sources: avatars/hedra/education_avatar/education-frontend/components/session-view.t... | agents/src/multimodal/multimodal_agent.ts | Turn detection and interruptions | LiveKit Docs | agent/main.py | Web and mobile frontends | LiveKit Docs