Can we add multi/parallel language model, i.e for ...
# ask-ai
a
Can we add multi/parallel language model, i.e for fast and quick reply, we want to use nano model, and we do longer or complex task on large reasoning model? How to do that? I want to reduce the STT-LLM-TTS pipeline latency on generating reply, doing task, and etc...
đź‘€ 1
t
Thanks for reaching out, Gamal. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It sounds like you want fast turn-taking with a “nano” LLM, while offloading heavy reasoning to a larger model. You can do this in three supported ways: • Simple session switching ◦ Start your AgentSession with a nano model for low-latency replies, and switch to a larger model only when needed. You can change models during a session by updating the session’s LLM (Models). • Per-turn routing via an llm_node (recommended) ◦ Define two LLMs (e.g.,
openai/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 Docs
a
Yes
🙌 1
t
Great—here’s a concise Node-style sketch showing per-turn routing between nano and large models via an llm_node override, plus where to collect TTFT/TTFB. Adapt names to your SDK. Code sketch:
Copy code
import { 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