Repository navigation
Conversation
🦋 Changeset detectedLatest commit: eb2661b The changes in this PR will be included in the next version bump. This PR includes changesets to release 41 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
JustinScitech
approved these changes
Oct 23, 2026
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.
Description
AgentActivity.onPreemptiveGenerationcancels the in-flight preemptive reply and starts a new LLM request on every call.AudioRecognitioncalls it on everyPREFLIGHT_TRANSCRIPT, and on aFINAL_TRANSCRIPTthat is not an exact string match of the last preflight.STTs revise punctuation within a turn. Deepgram Flux through LiveKit Inference (
deepgram/flux-general-en, default settings) often sends a secondEagerEndOfTurnthat only adds a question mark:Across 42 synthesized Flux turns, 8 had a second preflight that differed only in punctuation. Each one threw away the running LLM request and started over, so the head start shrank by the gap between the two preflights (about 120 to 280 ms) and the LLM was called twice. The restart never changes what the agent says: at end of turn the reply is already reused when the transcripts are
transcriptsEquivalent.Same fix in Python: livekit/agents#7991 (the demo there replays the captured Flux turn: main sends 2 LLM requests, the fix sends 1 and reuses it with a longer
preemptive_lead_time).Changes Made
onPreemptiveGenerationreturns early, before cancelling or counting a retry, when the in-flight attempt's transcript istranscriptsEquivalentto the new one. That covers a formatting-only second preflight and a final that only reformats the preflight. A transcript with new words still cancels and restarts, and the end-of-turn check still compares transcript, chat context, tools and tool choice before reusing the reply.onPreemptiveGenerationguard tests now give each call distinct words, so the retry-counter tests still exercise restarts.@livekit/agents.Pre-Review Checklist
Testing
restarts for the revised transcriptkeeps the first attempt when only punctuation or case changes (fails on main) and restarts when words change.pnpm test agents/src/voice(1440 passed),pnpm build:agents,tsc --noEmit, eslint and prettier.restaurant_agent.tsandrealtime_agent.tswork properly (for major changes): not a major change