Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion livekit-agents/livekit/agents/voice/agent_activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1728,7 +1728,9 @@ def _on_input_speech_stopped(self, ev: llm.InputSpeechStoppedEvent) -> None:

def _on_input_audio_transcription_completed(self, ev: llm.InputTranscriptionCompleted) -> None:
self._session._user_input_transcribed(
UserInputTranscribedEvent(transcript=ev.transcript, is_final=ev.is_final)
UserInputTranscribedEvent(
transcript=ev.transcript, is_final=ev.is_final, item_id=ev.item_id
)
)

if ev.is_final:
Expand Down
6 changes: 6 additions & 0 deletions livekit-agents/livekit/agents/voice/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ class UserInputTranscribedEvent(BaseModel):
type: Literal["user_input_transcribed"] = "user_input_transcribed"
transcript: str
is_final: bool
item_id: str | None = None
"""Stable id correlating all interim transcripts belonging to the same utterance.

Mirrors ``llm.InputTranscriptionCompleted.item_id``. Useful for deduplicating
repeated interim events from realtime models (e.g. only reacting once per
utterance instead of once per streamed delta chunk)."""
speaker_id: str | None = None
language: LanguageCode | None = None
created_at: float = Field(default_factory=time.time)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_agent_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,21 @@ async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatM
SESSION_TIMEOUT = 60.0


def test_user_input_transcribed_event_item_id():
"""UserInputTranscribedEvent should accept and expose item_id (#6110).

item_id is the stable correlation key from llm.InputTranscriptionCompleted,
forwarded by AgentActivity._on_input_audio_transcription_completed so realtime
consumers can dedup repeated interim transcripts belonging to the same utterance.
"""
ev = UserInputTranscribedEvent(transcript="hello", is_final=False, item_id="item_abc123")
assert ev.item_id == "item_abc123"

# item_id remains optional for non-realtime (STT-pipeline) transcripts
ev_no_id = UserInputTranscribedEvent(transcript="hello", is_final=True)
assert ev_no_id.item_id is None


async def test_events_and_metrics() -> None:
speed = 1
actions = FakeActions()
Expand Down