prehistoric-alligator-43413
10/24/2025, 10:07 PMtall-airline-16756
10/24/2025, 10:08 PMtall-airline-16756
10/24/2025, 10:08 PMLLMStream interface. This lets you stream responses as they’re generated, so you can process tokens incrementally. When you call the chat() method on an LLM instance, it returns an LLMStream object that you can asynchronously iterate over to handle responses smoothly.
For instance, by using the LLMStream.__aiter__() method, you can process each token right as it becomes available. Plus, running tasks like tool calls concurrently with asyncio.gather() helps keep everything running without blocking.
To make things even better and reduce TTFT and latency, it’s a great idea to deploy your agent server close to the LLM, STT, and TTS services. Also, don’t forget to take advantage of the LiveKit Agents Metrics API to keep an eye on performance metrics like TTFT and end-to-end latency, so you can continuously optimize your setup.
Sources: livekit-plugins/livekit-plugins-lmnt/livekit/plugins/lmnt/tts.py | How can I reduce latency in voice agents using STT, TTS and LLM? | README.md | Operational Guidance & Best Practices | livekit/livekit_composite | DeepWik... | Troubleshooting & Common Issues | livekit/livekit_composite | DeepWikiprehistoric-alligator-43413
10/24/2025, 10:11 PMtall-airline-16756
10/24/2025, 10:12 PMllm_node, stt_node, or tts_node, or building your own pipeline logic, you’ll want to take care of async streams yourself. For instance, in a custom llm_node, you’d handle async iteration to process responses like this:
async def llm_node(self, chat_ctx, tools, model_settings):
async for chunk in custom_llm_stream:
yield chunk
And if you’re diving into advanced scenarios like integrating custom tools or managing speech tasks, you might also work with context variables or task creation utilities. Please feel free to reach out if you’d like me to walk you through any specific customizations — I’m here to help!
Sources: agents/src/voice/agent_activity.ts | Real-time AI Models & Streaming | livekit/livekit_composite | DeepWiki | livekit-agents/livekit/agents/voice/agent_session.pyprehistoric-alligator-43413
10/24/2025, 10:22 PMtall-airline-16756
10/24/2025, 10:23 PMif strings.HasSuffix(strings.TrimSpace(delta), ".") {
return sb.String(), nil
}
• System Prompt Optimization: Try structuring your prompts to encourage concise, chunk-friendly responses. Adding instructions like "Make concise/short answers" in the system prompt can really make a difference.
• Custom TTS Node: If you want more control, you can override the default TTS node to add your own chunking logic, like splitting beyond sentence boundaries or handling special content types.
• UTF-8 Aware Chunking: Don’t forget to use UTF-8 aware chunking tools to properly handle multilingual content or special characters—it ensures everything runs smoothly.
• Performance Monitoring: Keep an eye on how your chunking performs by using logging and metrics. This helps you fine-tune things and get the best latency possible.
If you’d like, I’m here to help you dive into any specific implementation details or customize the chunking logic to fit your particular needs. Just let me know!