Is there anyway I can get the agent state 'is thin...
# agents
p
Is there anyway I can get the agent state 'is thinking' from Livekit? Both
RoomEvent.ActiveSpeakersChanged
and
ParticipantEvent.IsSpeakingChanged
give me a binary
isSpeaking
and I had to workaround it to set the UI state.
My current workaround with
RoomEvent.ActiveSpeakersChanged
is to check if the
localParticipant
is not speaking anything to put the agent in a thinking state. But the
localParticipant
isSpeaking
fires a lot of false negatives, and that causes the state to change constantly.
f
i implement using attribute, in the worker, subscribe to
agent_state_changed
and publish it, then frontend can subscribe the the attribute change
Copy code
@session.on(Events.agent_state_changed)
  def change_agent_attribute(event: AgentStateChangedEvent):
    """Update room metadata when agent state changes"""
    old_state = event.old_state
    new_state = event.new_state
    task = asyncio.create_task(
      ctx.room.local_participant.set_attributes(
        {
          'agent_state': new_state,
        }
      )
    )
    task.add_done_callback(
      lambda t: main_logger.debug(
        'set agent state from %s to %s',
        old_state,
        new_state,
      )
    )
🙌 1
p
Thank you. I'll try that out