How do I receive messages from a text-only agent o...
# ask-ai
h
How do I receive messages from a text-only agent on the frontend in Next.JS?
t
Thanks for reaching out, Lachlan. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To receive messages from a text-only agent on the frontend in Next.js, you can use the registerTextStreamHandler method to listen for incoming text on the lk.transcription topic. Here's an example implementation:
Copy code
room.registerTextStreamHandler('lk.transcription', async (reader, participantInfo) => {
  const message = await reader.readAll();
  if (reader.info.attributes['lk.transcribed_track_id']) {
    console.log(`New transcription from ${participantInfo.identity}: ${message}`);
  } else {
    console.log(`New message from ${participantInfo.identity}: ${message}`);
  }
});
On the backend, you can configure a text-only agent by setting audio_enabled=False in the RoomOutputOptions. The agent will then publish text responses to the lk.transcription text stream topic:
Copy code
session = AgentSession(
    ..., # STT, LLM, etc.
    room_output_options=RoomOutputOptions(
        audio_enabled=False # disable audio output
    )
)
Let me know if you need further assistance! Sources: Text and transcriptions | LiveKit Docs