I'm trying to record e2e_latency which works fine ...
# ask-ai
b
I'm trying to record e2e_latency which works fine on normal turns. However, I have some function calls which use session.say() - is there any way that these can trigger the call for e2e_latency from the livekit sdk?
✅ 1
t
Thanks for reaching out, Amir. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about whether
session.say()
calls inside function tools can trigger the
e2e_latency
metric the same way normal assistant turns do. Short answer:
e2e_latency
is recorded on assistant
ChatMessage
items (per-turn metrics).
session.say()
does create speech and emits speech events (it returns a
SpeechHandle
and fires
speech_created
), but it does not automatically attach the same
e2e_latency
metric that appears on assistant turns. In other words,
e2e_latency
is not recorded for
session.say()
in the same way as a normal assistant turn. If you want latency for speech generated inside a function/tool, you can: • Measure timings around the function call yourself (record start time before invoking the tool and end time when the
SpeechHandle
reports audio ready or on the
speech_created
event). • Use the
SpeechHandle
lifecycle events to capture TTS timing (time to first byte / ready) and combine with your own measure of upstream LLM time if needed. Would you like a short code example for measuring those timings with
SpeechHandle
or guidance on where to hook the
speech_created
event? Sources: Understand and Improve Agent Latency | LiveKit | Agent speech and audio | LiveKit Documentation | Build Your First AI Voice Agent in Python: Complete Tutorial | LiveKit | Audio customization | LiveKit Documentation | The ReAct Pattern for Voice Agents and How AI Agents Think, Act, and Respon..., with interactive elements