dry-car-90162
03/11/2026, 9:24 AMtall-airline-16756
03/11/2026, 9:24 AMtall-airline-16756
03/11/2026, 9:25 AMdry-car-90162
03/11/2026, 9:27 AMtall-airline-16756
03/11/2026, 9:27 AMsip.callID, sip.phoneNumber, sip.trunkID).
• RTP → STT latency: time between SIP media arrival (RTP ingress or the conversion point) and STT processing start / end‑of‑utterance detection.
• Model and response latency: LLM Time To First Token (TTFT) and TTS Time To First Byte (TTFB).
• End‑to‑end latency: combine the above to see how much latency is introduced by the SIP transport vs. processing.
Practical steps (self‑hosted Python)
1) Use the correct SDK
• Run LiveKit Python Agents SDK v1.3.0 or later.
2) Ensure observability is generated
• Observability (traces, transcript, metrics, logs) is generated by the agent by default unless disabled.
• In self‑hosted mode you must persist or forward these artifacts yourself; they are not presented in LiveKit Cloud automatically.
3) Attach listeners for metrics and EOU
• Hook into STT, LLM, and TTS metric events to capture TTFT, TTFB, and EOU durations programmatically.
Example pattern
from livekit.agents.metrics import LLMMetrics, TTSMetrics, EOUMetrics
class MyAgent(Agent):
async def on_enter(self):
self.session.llm.on("metrics_collected", self.on_llm_metrics)
self.session.tts.on("metrics_collected", self.on_tts_metrics)
self.session.stt.on("eou_metrics_collected", self.on_eou_metrics)
async def on_llm_metrics(self, metrics: LLMMetrics):
# TTFT indicates LLM responsiveness after utterance
print(f"LLM TTFT: {metrics.ttft:.3f}s")
async def on_tts_metrics(self, metrics: TTSMetrics):
# TTFB indicates TTS audio generation delay
print(f"TTS TTFB: {metrics.ttfb:.3f}s")
async def on_eou_metrics(self, metrics: EOUMetrics):
print(f"EOU detection duration: {metrics.duration:.3f}s")
4) Track SIP participant lifecycle and timestamps
• Record time at SIP call start, and log when the SIP participant joins the room.
• Use participant events to get the join/connect timestamp and SIP attributes.
Example pattern
import time
call_start = time.time()
def on_participant_connected(participant):
elapsed = time.time() - call_start
print(f"Participant {participant.identity} connected in {elapsed:.3f}s")
# inspect SIP attributes if present
print("SIP attrs:", participant.attributes.get("sip.callID"))
ctx.room.on("participant_connected", on_participant_connected)
5) Correlate timestamps to isolate SIP latency
• Correlate:
◦ SIP-side timestamps (from your SIP infrastructure/SBC or CDRs)
◦ Agent session timestamps (RTP ingress, STT start, EOU, LLM start, TTS audio send)
• The gap between SIP media arrival and STT start (or EOU detection) is the SIP‑transport + conversion latency.
• TTFT/TTFB measure model/TTS processing latency.
6) Persist and analyze observability data
• Save metrics, traces, transcripts, and logs to local storage, a database, or forward to monitoring services (Datadog, CloudWatch, Sentry, etc.).
• Build queries/dashboards for trends: average SIP connect time, median RTP→STT latency, 95th percentile TTFT, etc.
Practical tips to reduce noise
• Pin agents to the same region as your SIP endpoint to cut network hops and re-measure.
• Ensure clocks are synchronized (NTP) across SIP infrastructure and agents to make timestamp correlation reliable.
• Capture multiple calls and compute percentiles (p50/p90/p95) rather than relying on single samples.
Limitations to be aware of
• Self‑hosted deployments generate observability data locally — you must implement storage/forwarding and an analysis UI if you want a dashboard similar to Agent Insights in LiveKit Cloud.
• If you need long‑term retention, export session reports to your chosen storage.
If you’d like, I can:
• Provide a complete Python agent template that logs and exports the observability artifacts (metrics, traces, transcripts) for SIP latency analysis.
• Help map the exact SIP timestamps available from your SBC/IMS to the agent events you have so we can pinpoint measurement points.
Which would you prefer, and do you have SIP-side timestamps or a preferred logging/monitoring backend to export metrics to?
Sources: Where to find your Agent Logs | LiveKit | examples/bank-ivr | livekit/livekit_composite | DeepWiki | STT Metrics | LiveKit Documentation | SIP Lifecycle Management Agent | LiveKit Documentation | Agents (Python) | livekit/livekit_composite | DeepWikidry-car-90162
03/11/2026, 9:33 AMtall-airline-16756
03/11/2026, 9:33 AMcallstatus (without exact SIP timestamps) to estimate telephony latency.
Short answer
• Yes, you can use callstatus to get a rough estimate of telephony latency, but it has important limitations. callstatus events can indicate lifecycle milestones (e.g., ringing, answered, connected, ended) that let you measure coarse delays (call setup and connect time). They won’t give precise media‑path timing (RTP arrival → STT start). Use callstatus together with agent-side events (participant connected, RTP/ingress timestamps, STT/EOU, LLM/TTS metrics) to approximate SIP-induced latency.
How to estimate latency with callstatus
1. Identify which callstatus values you receive and what they represent in your SIP flow (e.g., RINGING, ANSWERED, CONNECTED, COMPLETED).
2. Log the local timestamp each time you receive a callstatus update in your agent.
3. Correlate those timestamps with agent events you do have:
◦ Participant connected in room (room participant_connected event)
◦ RTP/media ingress moment (if your agent exposes when audio frames start arriving)
◦ STT EOU detection and STT start
◦ LLM metrics_collected (TTFT) and TTS metrics_collected (TTFB)
Example estimation approaches
• Call setup (coarse SIP latency): time from callstatus=RINGING (or call initiation) to callstatus=ANSWERED or to participant_connected. This measures how long it took for the call to be answered and for the SIP session to reach the agent.
• Media startup latency (approximate): time from callstatus=ANSWERED or participant_connected to the first STT activity or first EOU event recorded by the agent. This gap approximates how long until audio actually reached and was processed by the agent.
• End-to-end influence on response time: measure from participant_connected or first audio frame timestamp to LLM TTFT / TTS TTFB. Subtract model/TTS processing time (from metrics) to estimate transport/conversion portion that includes SIP.
What you cannot get reliably from callstatus
• Precise RTP transport delays (packet-level latency, jitter, packet loss).
• Exact timestamp of the first media RTP packet arrival unless your agent exposes an ingress timestamp.
• Per-packet or sub-second SIP signaling delays (callstatus updates can be delayed or batched).
Practical suggestions to improve accuracy
• Capture agent-side audio ingress time: instrument your agent to record a local timestamp when it receives the first audio frame for that participant. Correlate that with callstatus events.
• Ensure clock sync (NTP) across SIP infrastructure, SBC, and your agent hosts. Even coarse estimates need consistent clocks to be meaningful.
• Capture multiple calls and compute percentiles (p50/p90/p95). Single-call estimates can be noisy.
• Add small test calls where you generate a known tone or spoken phrase at known times so you can better correlate media arrival and STT events.
• If possible, request additional SIP attributes from your SIP gateway (e.g., callStartTime, answeredTime, or CDR timestamps) — even approximate fields improve accuracy.
Example logging flow (Python pseudocode)
1. On callstatus event:
◦ log: event name, callstatus value, local timestamp
1. On `participant_connected`:
◦ log: participant id, local timestamp
1. On first audio frame / RTP ingress:
◦ log: local timestamp (first_media_ts)
1. On STT EOU and LLM/TTS metrics:
◦ log: STT start/EOU time, LLM TTFT, TTS TTFB
Later analysis:
• setup_time = timestamp_answered - timestamp_call_initiated (from callstatus)
• media_start_delay = first_media_ts - timestamp_answered (or participant_connected)
• processing_delay = TTFT (from LLM metrics) + TTFB (from TTS metrics) — attribute rest to transport/conversion
Offer to help
• If you share the list of callstatus values you receive and a sample of the agent events you already log (participant_connected, STT/EOU, LLMMetrics/TTSMetrics), I can give a concrete mapping and a small script to compute those latency estimates and percentiles for your call logs.dry-car-90162
03/11/2026, 9:34 AMtall-airline-16756
03/11/2026, 9:35 AMfirst_rtp_ts = time.time().
• When STT receives first decoded audio (or when stt.on("eou_metrics_collected") or stt.on("start") fires): record stt_start_ts = time.time().
• Telephony_latency ≈ stt_start_ts - first_rtp_ts.
• Log these per call and compute percentiles across calls.
If you’d like, I can:
• Provide a small Python snippet that hooks into your agent to log RTP arrival and STT start timestamps.
• Help interpret a few sample logs to separate telephony vs. processing delays.
Which do you prefer, and do you currently have access to an event for “first RTP packet” or just the participant connection time?