How can I run my agent in text/chat only mode
# ask-ai
q
How can I run my agent in text/chat only mode
t
Thanks for reaching out, Niket. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To run your agent in text/chat-only mode, you can configure it to disable audio input and output while enabling text-based interactions. Here's how you can do it: 1. Configure the AgentSession with Text-Only Options:
Copy code
session = AgentSession(
    llm=openai.LLM(model="gpt-4"),
    # No TTS or STT are needed for text-only mode
)
await session.start(
    agent=MyAgent(),
    room=ctx.room,
    room_input_options=RoomInputOptions(
        text_enabled=True,
        audio_enabled=False
    ),
    room_output_options=RoomOutputOptions(
        transcription_enabled=True,
        audio_enabled=False
    ),
)
2. Run the Agent in Text Mode: You can run the agent in terminal mode for text-only interactions using:
python myagent.py console
In this mode, the agent will monitor the
lk.chat
text stream topic for incoming messages and publish responses to the
lk.transcription
topic. Audio capabilities will be completely disabled, and the agent will operate entirely through text interactions. Let me know if you need further assistance! Sources: examples/voice_agents/llamaindex-rag/chat_engine.py
q
generate_reply needs the TTS part. How can that be done for text only?
t
To handle
generate_reply
with TTS in text-only mode, you can set up the agent to include a TTS plugin—even though it won’t actually play any audio. This little trick helps the agent work smoothly while sticking to text-only. Here’s a simple way to do it: 1. Set Up the LLM with Text-Only Modality:
Copy code
session = AgentSession(
    llm=openai.realtime.RealtimeModel(modalities=["text"]),
    tts=openai.TTS(voice="ash")
)
2. Just Use
generate_reply
Like Usual:
The
generate_reply
method will create text responses, which get sent through the transcription stream. For example:
await session.generate_reply(instructions="Please provide your response.")
With this setup, your agent’s replies come through as text on the
lk.transcription
topic, and the TTS plugin quietly keeps things compatible—even without any audio output. If anything’s unclear or you want to dive deeper, just let me know—I’m here to help!
q
How do I display the lk.transcription then
t
To show
lk.transcription
in LiveKit, here’s a simple way to get you started: 1. Listen for Transcription Events: You can use the LiveKit SDK to subscribe to the
lk.transcription
text stream topic. For example: `room.registerTextStreamHandler('lk.transcription', async (reader, participantInfo) => { const message = await reader.readAll(); console.log(
New transcription from ${participantInfo.identity}: ${message}
); });` 2. Show Transcriptions in Your UI: Create a UI component to display the transcriptions. Here’s a quick example:
Copy code
function Transcript() {
  const { displayTranscriptions } = useAgent();

  return (
    
      {displayTranscriptions.length === 0 ? (
        
          Get talking to start the conversation!
        
      ) : (
        
          {displayTranscriptions.map(({ segment }) => (
            
              {segment.text.trim()}
            
          ))}
        
      )}
    
  );
}
3. Make It Even Better: Think about adding features like auto-scrolling to the newest transcription or some cool typing effects to make the experience smoother and more engaging. 4. Set Up on the Server Side: Make sure transcription output is turned on in your server setup. For example:
Copy code
await session.start(
  agent=Agent(
    instructions="You are a helpful assistant that transcribes user speech to text.",
    stt=deepgram.STT()
  ),
  room=ctx.room,
  transcription_enabled=True
);
If you hit any bumps or want to chat more about this, just let me know—I’m here to help! Sources: Text and transcriptions | LiveKit Docs | web/src/components/transcript.tsx | components/typewriter.tsx | hardware/pi-zero-transcriber/README.md