I want to integrate my custom LLM, STT, and TTS co...
# ask-ai
a
I want to integrate my custom LLM, STT, and TTS components using LiveKit agents' pipeline without using the built-in plugins. Can you provide some useful resources to help me integrate it?
t
Thanks for reaching out, Anushkaa. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're exploring how to integrate your custom LLM, STT, and TTS components into LiveKit agents' pipeline! You can do this smoothly by overriding the default pipeline nodes. This way, you get to implement your own logic directly within the agent class, without depending on built-in plugins. Here’s a quick rundown of the steps to guide you: • Custom STT Integration: You’ll want to override the
stt_node()
method. This lets you process raw audio into text using your STT engine, returning a stream of transcription events. • Custom LLM Integration: Next, override the
llm_node()
method to send prompts to your LLM backend. Just make sure the output matches the expected stream format. • Custom TTS Integration: Finally, override the
tts_node()
method to create speech from text with your TTS engine, producing an audio frame stream. To give you a clearer picture, here’s an example in Python showing how you might define these methods in your custom agent class:
Copy code
class CustomAgent(Agent):
    async def stt_node(self, audio, model_settings):
        async for transcript in my_stt_engine(audio):
            yield transcript

    async def llm_node(self, chat_ctx, tool_ctx, model_settings):
        response = await my_llm_api(chat_ctx.messages)
        yield llm.ChatChunk(text=response)

    async def tts_node(self, text, model_settings):
        full_text = ''.join([t async for t in text])
        async for frame in my_tts_engine(full_text):
            yield frame
This approach works wonderfully in both JavaScript and Python SDKs. If you have any questions or need a hand with anything else, please don’t hesitate to reach out—I’m here to help! Sources: Pipeline nodes and hooks | LiveKit docs | Agents v0.x migration guide - Node.js | LiveKit Docs | plugins/test/src/index.ts | livekit-agents/livekit/agents/voice/agent.py