-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat(voice): expose item_id on UserInputTranscribedEvent (closes #6109) #6127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tsushanth
wants to merge
1
commit into
livekit:main
Choose a base branch
from
tsushanth:fix/user-input-transcribed-event-item-id
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+86
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """Unit tests for the `item_id` field on ``UserInputTranscribedEvent``. | ||
|
|
||
| Pins the contract that the realtime-path transcription event surface exposes | ||
| the upstream ``InputTranscriptionCompleted.item_id`` so consumers can dedup | ||
| interim transcripts of a single utterance without dropping into | ||
| provider-specific raw events. | ||
|
|
||
| Regression target: https://github.com/livekit/agents/issues/6109 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
|
|
||
| from livekit.agents.llm.realtime import InputTranscriptionCompleted | ||
| from livekit.agents.voice.events import UserInputTranscribedEvent | ||
|
|
||
| pytestmark = pytest.mark.unit | ||
|
|
||
|
|
||
| def test_user_input_transcribed_event_carries_item_id() -> None: | ||
| """The public event schema accepts ``item_id`` and round-trips it.""" | ||
| ev = UserInputTranscribedEvent( | ||
| transcript="hello world", | ||
| is_final=False, | ||
| item_id="item_abc123", | ||
| ) | ||
| assert ev.item_id == "item_abc123" | ||
|
|
||
|
|
||
| def test_user_input_transcribed_event_item_id_defaults_to_none() -> None: | ||
| """``item_id`` is optional — STT paths that have no upstream item id can | ||
| omit the field and consumers reading ``ev.item_id`` see ``None``.""" | ||
| ev = UserInputTranscribedEvent(transcript="hello world", is_final=True) | ||
| assert ev.item_id is None | ||
|
|
||
|
|
||
| def test_user_input_transcribed_event_serialises_item_id() -> None: | ||
| """``model_dump`` includes the ``item_id`` field — important because | ||
| downstream consumers (e.g. the host transport in ``test_session_host.py``) | ||
| may serialise this event for cross-process delivery.""" | ||
| ev = UserInputTranscribedEvent( | ||
| transcript="hi", is_final=True, item_id="item_xyz" | ||
| ) | ||
| dumped = ev.model_dump() | ||
| assert dumped["item_id"] == "item_xyz" | ||
|
|
||
|
|
||
| def test_input_transcription_completed_item_id_can_thread_to_event() -> None: | ||
| """Realtime path: every interim/final ``UserInputTranscribedEvent`` for a | ||
| single utterance shares the upstream ``InputTranscriptionCompleted.item_id``. | ||
|
|
||
| Mirrors the data flow inside | ||
| ``AgentActivity._on_input_audio_transcription_completed`` without | ||
| instantiating the full activity — the contract under test is | ||
| "the field exists and can carry the value", not the activity's plumbing. | ||
| """ | ||
| upstream = InputTranscriptionCompleted( | ||
| item_id="item_realtime_42", | ||
| transcript="hello world", | ||
| is_final=True, | ||
| ) | ||
|
|
||
| emitted = UserInputTranscribedEvent( | ||
| transcript=upstream.transcript, | ||
| is_final=upstream.is_final, | ||
| item_id=upstream.item_id, | ||
| ) | ||
|
|
||
| assert emitted.item_id == upstream.item_id == "item_realtime_42" |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚩 Remote session transport does not forward item_id
The
_on_user_input_transcribedhandler inlivekit-agents/livekit/agents/voice/remote_session.py:466-474constructs the protobufUserInputTranscribedmessage with onlytranscriptandis_final— the newitem_idfield is not forwarded. This means remote session consumers won't receive theitem_idfor dedup purposes. This is not a regression (the protobuf schema would need a separate update), but it limits the utility of the feature for remote/distributed deployments.Was this helpful? React with 👍 or 👎 to provide feedback.