able-jackal-84140
07/13/2025, 8:22 PMtall-airline-16756
07/13/2025, 8:22 PMtall-airline-16756
07/13/2025, 8:23 PMon_user_turn_completed
last changed. You’ll need to capture this timing yourself by storing a timestamp each time on_user_turn_completed
is called, and then calculate the difference using the current time:
import time
from livekit.agents import Agent
from livekit.agents.llm.chat_context import ChatContext, ChatMessage
class MyAgent(Agent):
def __init__(self):
super().__init__()
self.last_user_turn_completed_time = None
async def on_user_turn_completed(self, turn_ctx: ChatContext, new_message: ChatMessage) -> None:
self.last_user_turn_completed_time = time.time()
# Your logic here
def get_time_since_last_turn_completed(self) -> float | None:
if self.last_user_turn_completed_time is None:
return None
return time.time() - self.last_user_turn_completed_time
Alternatively, you can use LiveKit’s End-of-Utterance (EOU) metrics for more detailed event timing. Listen for EOU metric events, save the timestamp
, and use that for your calculations. The EOUMetrics
object also provides fields like on_user_turn_completed_delay
and end_of_utterance_delay
for further insight.
This approach requires maintaining state within your agent, as there’s no built-in query for this exact information.
More detail on these methods and available EOU metrics can be found in the LiveKit documentation.
Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime... | Capturing metrics | LiveKit Docsable-jackal-84140
07/13/2025, 8:28 PMtall-airline-16756
07/13/2025, 8:29 PMeou_metrics_collected
event on your speech-to-text component. Think of it like getting a behind-the-scenes peek at how conversations flow!
class MyAgent(Agent):
def __init__(self):
super().__init__()
def eou_wrapper(metrics):
asyncio.create_task(self.on_eou_metrics_collected(metrics))
self.stt.on("eou_metrics_collected", eou_wrapper)
async def on_eou_metrics_collected(self, metrics):
print(f"EOU timestamp: {metrics.timestamp}")
print(f"End of utterance delay: {metrics.end_of_utterance_delay}")
print(f"Transcription delay: {metrics.transcription_delay}")
print(f"on_user_turn_completed_delay: {metrics.on_user_turn_completed_delay}")
In the on_eou_metrics_collected
method, you'll get access to some really cool timing data that can help you understand conversation dynamics.
• `timestamp`: When the EOU event happened
• `end_of_utterance_delay`: How long after someone stops speaking
• transcription_delay
and `on_user_turn_completed_delay`: Handy latency details
Just a heads up – this works with voice activity detection (VAD) or LiveKit's turn detector, but not with server-side turn detection. It's a fantastic way to get more insight into how conversations are unfolding.
Check out the example above to see how you can customize your own handler and play around with these metrics!
Sources: Capturing metrics | LiveKit Docs | livekit-agents/livekit/agents/metrics/base.py | complex-agents/turn-taking/agent.py | Capturing metrics | LiveKit Docs