adorable-engine-68435
11/04/2025, 3:51 AMtall-airline-16756
11/04/2025, 3:51 AMtall-airline-16756
11/04/2025, 3:53 AMopenai/gpt-5-nano and a larger model) and route each turn inside an llm_node based on your heuristic (message length, tools required, intent). This avoids session-wide swaps and enables parallel/background work (Pipeline nodes, LLMs, OpenAI LLM models).
• Hybrid “instant reply + async escalation”
â—¦ Stream a quick nano response immediately; in parallel, call the larger model and use its result for the next turn or an update message. This keeps TTFT low while still handling complex tasks (Pipeline nodes, LLMs).
For STT/TTS latency:
• Use streaming, low-latency STT and TTS models; swap models if you need higher accuracy or different voices per phase (STT, TTS).
• LiveKit Inference lets you set models via simple strings and benefits from global routing and unified limits (Inference overview).
Measure improvements:
• Track LLM TTFT and TTS TTFB to verify reduced end-to-end latency (Metrics).
Would you like a short code sketch showing an llm_node that routes between nano and large models and where to emit TTFT/TTFB?
Sources: Building voice agents | LiveKit Docs | Models | LiveKit Docs | Introducing LiveKit Inference: A unified model interface for voice AI | OpenAI LLM models | LiveKit Docs | Kimi LLM | LiveKit Docsadorable-engine-68435
11/04/2025, 3:54 AMtall-airline-16756
11/04/2025, 3:55 AMimport { Agent, AgentSession } from "@livekit/agents";
// If you need provider control, import LLM from inference/plugin libs.
class MultiModelAgent extends Agent {
// Override llm_node to route per turn
async *llm_node(ctx) {
const latest = ctx.messages?.[ctx.messages.length - 1]?.content ?? "";
const useNano = latest.length < 300; // your heuristic
const nanoModel = "openai/gpt-5-nano"; // Inference model string
const largeModel = "openai/gpt-5"; // Inference model string
if (useNano) {
// Call default LLM node but pin nano for this turn
yield* Agent.default.llm_node.call(this, { ...ctx, llm: nanoModel });
} else {
// Route to larger model for complex tasks
yield* Agent.default.llm_node.call(this, { ...ctx, llm: largeModel });
}
}
}
// Create session with STT/TTS; LLM can be a default (overridden per turn)
const agent = new MultiModelAgent({ /* instructions, tools */ });
const session = new AgentSession({
agent,
stt: "your/streaming-stt",
tts: "your/streaming-tts",
llm: "openai/gpt-5-nano", // default fast model; per-turn override above
});
// Metrics: subscribe and aggregate LLMMetrics, TTSMetrics, EOUMetrics
session.on("metrics_collected", (ev) => {
const m = ev.metrics;
if (m.type === "LLMMetrics") {
// ttft (time to first token), duration, etc.
// e.g., console.log("LLM ttft:", m.ttft, "duration:", m.duration);
} else if (m.type === "TTSMetrics") {
// ttfb (time to first byte), duration
} else if (m.type === "EOUMetrics") {
// end_of_utterance_delay, transcription_delay (STT/endpointing)
}
});
References:
• Models and changing per-session/per-turn: Models
• Override and route in pipeline: Pipeline nodes and hooks
• Metrics (LLM TTFT, TTS TTFB, EOU delays): Logs, metrics, and telemetry
Want the same in Python, or an example that runs the large model in parallel while nano streams the quick reply?
Sources: Models | LiveKit Docs | Pipeline nodes and hooks | LiveKit docs | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | Logs, metrics, and telemetry | LiveKit Docs | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki