feat(turn-detector): LLM-based turn completion detector#5431
Draft
piyush-gambhir wants to merge 14 commits intolivekit:mainfrom
Draft
feat(turn-detector): LLM-based turn completion detector#5431piyush-gambhir wants to merge 14 commits intolivekit:mainfrom
piyush-gambhir wants to merge 14 commits intolivekit:mainfrom
Conversation
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
LLMTurnDetectortolivekit-plugins-turn-detectoras an additional turn-detection option alongside the existing ONNX EOU models. It implements the existing_TurnDetectorProtocol and plugs into the sameturn_detection=slot — zero changes to voice core.Inspired by Pipecat's Filter Incomplete Turns feature. Single-token
1/0classifier today; richer multi-state prediction can follow if there's interest.Why
Today
livekit-plugins-turn-detectorships the ONNX EOU model (English + multilingual). Some users want to drive turn classification through their own LLM instead — already paying for inference in the same loop, want semantic reasoning over full conversation context, or want language coverage that matches their LLM rather than a fixed threshold table. This PR adds that as another option in the family, not a replacement.Usage
Design highlights
_TurnDetectorProtocol (livekit-agents/livekit/agents/voice/turn.py) — no core changes.1/0classifier prompt; parser only reads the first non-whitespace char so provider-specific formatting differences are tolerated.1.5sdefault timeout viaasyncio.wait_for; on timeout returns a neutral0.5probability so endpointing falls back to default delay.0.5. Empty chat context short-circuits to1.0.instructionskwarg lets users replace the default prompt (e.g. for non-English or domain-specific deployments).livekit.agents.llmis already a peer dep of the plugin.Configuration
llmlivekit.agents.llm.LLMinstanceinstructionsNoneunlikely_threshold0.5timeout1.5max_history_turns6Test plan
livekit-plugins/livekit-plugins-turn-detector/tests/test_llm_turn_detector.py— all passing:"1"/"0"-> 0.95 / 0.05).max_history_turnsslicing.instructionsoverride.make lint,make type-check,make formatall clean.examples/voice_agents/llm_turn_detector.py.Non-goals (future work, separate PR)
_TurnDetectorProtocol with short/long incomplete signals).Happy to iterate on defaults (timeout, threshold, prompt wording) or placement if maintainers have a different preference.