flaky-scooter-85113
11/11/2025, 5:41 PMtall-airline-16756
11/11/2025, 5:41 PMtall-airline-16756
11/11/2025, 5:42 PMdefineAgent from @livekit/agents. Make sure your agent is set up to handle text input by enabling text stream handling.
2. In your RealtimeModel or AgentSession configuration, include TEXT in the modalities field—for example, [Modality.TEXT].
3. Run your agent in development mode with pnpm dev so it connects to your LiveKit room.
4. Then, open the LiveKit Playground and connect to that same room. You’ll be able to send typed messages and see your agent respond in real time!
Here’s an example to help you set up your agent configuration:
import { defineAgent, voice } from '@livekit/agents';
import * as google from '@livekit/agents-plugin-google';
import { Modality } from '@google/genai';
export default defineAgent({
entry: async (ctx) => {
await ctx.connect();
const session = new voice.AgentSession({
llm: new google.beta.realtime.RealtimeModel({
modalities: [Modality.TEXT],
}),
});
await session.start({ room: ctx.room });
await session.generateReply({
instructions: "Greet the user after receiving their message."
});
},
});
Also, please double-check that your environment variables (LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET) are set up correctly. If anything doesn’t seem to work, it’s a good idea to confirm your agent is connected to the right room and has the permissions it needs.
Sources: web/src/components/code-viewer.tsx | Voice AI quickstart | LiveKit docs | README.md | How to Set Up Speech-to-Text Input with Text-Only Output in LiveKit Agents | agents/src/voice/agent_activity.tsflaky-scooter-85113
11/11/2025, 5:43 PMtall-airline-16756
11/11/2025, 5:45 PMflaky-scooter-85113
11/11/2025, 5:45 PMtall-airline-16756
11/11/2025, 5:46 PMlk.chat text stream topic. This is actually the default setup for LiveKit agents, so you’re likely already covered here.
2. Next, you can tailor the agent’s behavior by defining a textInputCallback function. This function will handle incoming text messages and create responses. Here’s a quick example to illustrate:
const session = new voice.AgentSession({
textInputCallback: async (sess, event) => {
console.log("Received text:", event.text);
sess.interrupt();
await sess.generateReply({ userInput: event.text });
}
});
1. When starting the session, be sure to pass your textInputCallback within the inputOptions.
2. If your goal is to have a text-only agent, you can disable audio in both RoomInputOptions and RoomOutputOptions, while keeping text enabled.
3. From the frontend, send text input using the sendText method on a TextStream, targeting the lk.chat topic.
4. The agent’s replies will be published to the lk.transcription text stream topic, which you can then display in your frontend interface.
Please feel free to reach out if you’d like me to walk you through any part of this or if you need more details. I’m here to help!
Sources: agents/src/voice/room_io/room_io.ts | examples/other/chat-stream-receiver.py | How to Set Up Speech-to-Text Input with Text-Only Output in LiveKit Agents | Agents v0.x migration guide - Node.js | LiveKit Docs | Text and transcriptions | LiveKit docs