<#C088ZNU7QQ5|ask-ai> Using my (TypeScript) Agent ...
# ask-ai
f
#ask-ai Using my (TypeScript) Agent with a LK Playground... what's needed to make the agent respond to typed messages?
t
Thanks for reaching out, Steve. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you get your TypeScript agent responding to typed messages in the LiveKit Playground! Here’s a simple step-by-step guide to walk you through it: 1. Start by defining your agent using
defineAgent
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:
Copy code
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.ts
f
pipeline agent?
t
I'd love to help you understand how a pipeline agent in LiveKit works to manage real-time voice interactions! It essentially coordinates a series of audio processing components, including: 1. Speech-to-Text (STT): This captures what the user says and turns it into text using providers like Deepgram. 2. Language Understanding (LLM): Then, it processes that transcribed text with a powerful LLM (like OpenAI’s GPT-4) to create a thoughtful response. 3. Turn Detection: It listens carefully using voice activity detection (VAD) and end-of-utterance (EOU) detection to know exactly when the user has finished speaking. 4. Text-to-Speech (TTS): Finally, it converts the response from the LLM back into spoken audio, using TTS services such as Deepgram or Rime. These pipeline agents are built with LiveKit's Agents Framework and are quite flexible—they can manage complex conversational flows, switch dynamically between TTS providers, or even hand off control to other agents. Plus, they’re highly customizable, so you can tailor STT, LLM, or TTS nodes to fit your unique needs. If you'd like, I’m here to guide you through setting up or customizing a pipeline agent. Just let me know what you’re aiming for, and we can take it from there! Sources: Workflows | LiveKit Docs | agent-examples/Makefile | avatars/hedra/README.md | Pipeline nodes and hooks | LiveKit docs | README.md
f
what's needed for a pipeline agent to respond to typed text messages? The answer above only applies to 1 provider of the realtime option.
t
I'd be happy to guide you through configuring a pipeline agent to respond to typed text messages. Here’s a simple step-by-step approach: 1. First, make sure your agent is set up to listen for text input on the
lk.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:
Copy code
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