is there a way to check from my react frontend if ...
# ask-ai
h
is there a way to check from my react frontend if the agent is thinking? or just to check which state the agent is in currently
t
Thanks for reaching out, Ahmed. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! You can easily check the agent's state—including whether it’s in the “thinking” phase—right from your React frontend using the
useVoiceAssistant
hook from LiveKit. This handy hook gives you the agent’s current state, which could be one of these:
disconnected
,
connecting
,
initializing
,
listening
,
thinking
, or
speaking
. Here’s a simple example to get you started:
Copy code
import { useVoiceAssistant } from '@livekit/components-react';

function MyComponent() {
  const { state } = useVoiceAssistant();

  return (
    <div>
      <p>Agent State: {state}</p>
      {state === 'thinking' && (
        <p>Agent is processing your request...</p>
      )}
    </div>
  );
}
So, by checking if
state === 'thinking'
, you can easily let your users know when the agent is busy processing their request, making the experience smoother and more friendly.