calm-gpu-73162
12/17/2025, 4:34 PMtall-airline-16756
12/17/2025, 4:34 PMtall-airline-16756
12/17/2025, 4:34 PMstt or enable audio input. Let the agent receive text via the lk.chat topic (default) or a custom text callback.
1) Agent/session setup (text-only)
import { defineAgent, voice } from '@livekit/agents';
import { openai } from '@openai/sdk'; // your LLM setup
export default defineAgent({
entry: async (ctx) => {
const agent = new voice.Agent({
instructions: 'You are a helpful assistant.',
});
const session = new voice.AgentSession({
llm: new openai.LLM(/*...*/),
// Do NOT include `stt`, `vad`, or turn detection
});
await session.start({
room: ctx.room,
agent,
inputOptions: {
audioEnabled: false, // disable audio input
textEnabled: true, // ensure text input is allowed (default)
},
outputOptions: {
audioEnabled: false, // optional: disable TTS if you want text-only replies
},
});
},
});
2) Sending transcription text from the client
• Send messages to lk.chat. Example:
await localParticipant.sendText('This is the pre-transcribed text', { topic: 'lk.chat' });
The agent will process that text as user input.
3) Optional: custom text handler
• If you want custom behavior (e.g., command filtering, immediate generation), provide a textInputCallback when starting the session:
const onText = (session: voice.AgentSession, event: voice.TextInputEvent) => {
const text = event.text;
// custom logic
session.generateReply({ userInput: text });
};
await session.start({
room: ctx.room,
agent,
inputOptions: { textInputCallback: onText, audioEnabled: false },
});
4) Optional: enable TTS for spoken agent replies
• If you want the agent to speak responses, set outputOptions.audioEnabled: true and configure TTS. Otherwise keep it false for text-only output.
If you want, tell me:
• whether you need the agent to also handle live audio sometimes,
• which LLM/ TTS provider you plan to use,
and I’ll provide a tailored code sample for that setup.
Sources: Text and transcriptions | LiveKit docs | Agent session | LiveKit docs