How can I create an agent in Node.js that accepts ...
# ask-ai
c
How can I create an agent in Node.js that accepts transcription texts instead of audio (where stt option is passed)?
t
Thanks for reaching out, Rin. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to create a Node.js LiveKit agent that accepts pre-transcribed text (instead of audio/STT). Below are the concise steps and example code to do that. Key idea: do NOT configure
stt
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)
Copy code
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:
Copy code
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:
Copy code
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