late-glass-71191
12/14/2025, 5:19 PMtall-airline-16756
12/14/2025, 5:19 PMtall-airline-16756
12/14/2025, 5:20 PMinstructions field when constructing voice.Agent.
import { voice } from '@livekit/agents';
class SupportAgent extends voice.Agent {
constructor() {
super({
instructions: 'You are a helpful support agent. Assist users with account, billing, and troubleshooting.',
});
}
}
2) Small/static knowledge base — preload into chat context
• Good for short, fixed policies or FAQs. Add messages to ChatContext before starting the session.
import { voice, llm } from '@livekit/agents';
const initialCtx = llm.ChatContext.empty();
initialCtx.addMessage({
role: 'assistant',
content: 'Refund policy: refunds issued within 5 business days. Support hours: 24/7.',
});
const agent = new voice.Agent({ chatCtx: initialCtx });
3) Dynamic/large knowledge base — expose a tool that queries your KB
• Define an llm.tool() that performs search (vector DB, API, etc.). The agent calls it during the conversation.
import { voice, llm } from '@livekit/agents';
import { z } from 'zod';
const searchKB = llm.tool({
description: 'Search company knowledge base',
parameters: z.object({ query: z.string() }),
execute: async ({ query }) => {
// replace with your search (Pinecone, Supabase, HTTP API, etc.)
const res = await fetch('<https://your-kb-api/search>', {
method: 'POST',
body: JSON.stringify({ query }),
}).then(r => r.json());
return JSON.stringify(res);
},
});
const agent = new voice.Agent({
instructions: 'You are a support agent. Use tools to retrieve factual info.',
tools: { searchKB },
});
4) Retrieval-augmented generation (RAG) — inject relevant docs per user turn
• Use a hook like onUserTurnCompleted to run a vector search and append relevant context to the turn before the agent replies.
import { voice, llm } from '@livekit/agents';
class RagAgent extends voice.Agent {
async onUserTurnCompleted(turnCtx: llm.ChatContext, newMessage: llm.ChatMessage) {
const docs = await myVectorSearch(newMessage.textContent); // implement your search
turnCtx.addMessage({
role: 'assistant',
content: `Relevant docs:\n${docs.join('\n\n')}`,
});
}
}
Which option fits you best?
• If your KB is small/static: use option 2.
• If your KB is large or updated frequently: use option 3 or 4.
If you tell me which knowledge store you plan to use (e.g., Pinecone, Supabase, LlamaIndex, custom HTTP API) and whether you need realtime tool calls or preloaded context, I’ll provide a tailored code example and integration steps.
Sources: Agents (Node.js) | livekit/livekit_composite | DeepWiki | External data and RAG | LiveKit Docs | OpenAI Realtime API plugin guide | LiveKit docs | Tool definition and use | LiveKit docs | Pipeline nodes and hooks | LiveKit docs