enough-match-43171
12/18/2025, 10:33 AMtall-airline-16756
12/18/2025, 10:33 AMtall-airline-16756
12/18/2025, 10:33 AMtext_input=True in AgentSession (default).
• Node: textEnabled: true in voice.AgentSession (default).
1. Send the chat message from the client on topic lk.chat.
• JavaScript:
await room.localParticipant.sendText('Hello', { topic: 'lk.chat' });
• Swift:
try await room.localParticipant.sendText("Hello", for: "lk.chat")
1. (Optional) Customize handling with a text input callback to filter or intercept messages before the agent replies.
• Example Python flow: implement text_input_cb that inspects event.text, call session.interrupt() then session.generate_reply(user_input=message) for default reply behavior.
1. (Optional) Manually trigger a reply from code:
• Python: session.generate_reply(user_input="How's the weather?")
• Node: session.generateReply({ userInput: 'How is the weather?' })
If you want, tell me:
• Which SDK/language you’re using (Python, Node, JS, Swift), and
• Whether you want the agent to auto-reply or run custom logic — I’ll give exact code for that setup. Sources: Text and transcriptions | LiveKit docs | Agent speech and audio | LiveKit docsenough-match-43171
12/18/2025, 10:34 AMtall-airline-16756
12/18/2025, 10:34 AMenough-match-43171
12/18/2025, 10:35 AMtall-airline-16756
12/18/2025, 10:35 AMlk.chat messages, or
• only react to messages that mention the agent or use a special prefix/topic.
Answer those two points and I’ll provide concise Python and Next.js snippets and the recommended Room/options configuration.enough-match-43171
12/18/2025, 10:35 AMtall-airline-16756
12/18/2025, 10:36 AMlk.chat
// wherever you have the room client
await room.localParticipant.sendText('Hello everyone', { topic: 'lk.chat' });
2) Python agent: ensure text input is enabled (default) and start the session so it listens to lk.chat. Example with an optional custom handler that simply interrupts and generates a reply for every incoming message:
from livekit.agents import AgentSession
from livekit.agents.voice import room_io
from livekit.plugins import deepgram, openai, elevenlabs, silero
# create session (text_input is True by default)
session = AgentSession(
stt=deepgram.STT(),
llm=openai.LLM(),
tts=elevenlabs.TTS(),
vad=silero.VAD.load(),
)
# optional: custom handler (called for every text input on lk.chat)
def text_input_cb(session: AgentSession, event: room_io.TextInputEvent):
msg = event.text
# interrupt any speech and ask the agent to generate a reply using the message
session.interrupt()
session.generate_reply(user_input=msg)
# start the agent in the room with text input options
await session.start(
agent=MyAgent(), # your Agent implementation
room=ctx.room, # room context / connection
room_options=room_io.RoomOptions(
text_input=room_io.TextInputOptions(text_input_cb=text_input_cb)
),
)
Notes:
• You do not need extra subscriptions: AgentSession listens to lk.chat by default when text input is enabled.
• If you omit text_input_cb, the agent will still auto-handle lk.chat messages (interrupt and generate a reply).
• Ensure the agent is joined to the same LiveKit Room as meeting participants.
Would you like a version tailored to your existing agent class or the exact Next.js file where you call sendText?
Sources: Text and transcriptions | LiveKit docs | Agent speech and audio | LiveKit docs