AMD: opt-in to process carrier early-media audio (183 Session Progress + SDP) instead of always deferring to sip.callStatus == "active"
Feature Type
Would make my life easier
Feature Description
AMD (livekit.agents.AMD) deliberately defers all audio processing — the no-speech timer (#5848) and, as of 1.6.9, the detection timeout too (#6187 / #6580) — until sip.callStatus == "active". Both fixes treat all pre-answer audio uniformly as "ringback / carrier early media / dialtone" noise that should never influence classification, which is correct when early media is just a ringback tone.
We run outbound voice AI calls through several Latin American mobile carriers, and we've confirmed that at least a couple of them (seen so far in Peru) send the ringing tone, system announcements, or the voicemail greeting itself via early media — SIP 183 Session Progress with an SDP body — rather than only after a final 200 OK. For calls that reach voicemail on these carriers, the 200 OK either arrives well after the greeting has already played, or the leg never produces a clean "answered" transition the way AMD expects. Deferring to active in that situation doesn't protect the classifier from noise — it discards the only audio that was ever going to be available, so the call falls through as uncertain/no-answer instead of being correctly classified as machine-vm.
This is different from what #6187 fixed: that issue was about timer accounting (a detection_timeout armed at track-subscription burning down during a long ring before a late active answer arrives — the useful audio there was always post-answer). In our case the useful audio is the pre-answer early media itself.
We're not asking to change the default behavior — the ringback-only case #5848/#6187 fixed is the common case and shouldn't regress. We'd like an opt-in, e.g. a process_early_media: bool (default False) on AMD.__init__ or DetectionOptions, that — when set — starts start_listening() (timers + transcript processing) from track subscription instead of gating behind sip.callStatus == "active" via _wait_for_sip_answer. This can't be auto-detected safely (no way to tell "informative early media" from generic ringback without listening to it), so it needs to be an integrator-set flag per call/trunk rather than a new default heuristic — trunk/carrier knowledge of which ones do this lives on our side, not the SDK's.
Workarounds / Alternatives
Checked whether upgrading fixes this: it doesn't. Confirmed the same defer-to-active behavior is present through 1.6.9 (latest with release notes as of this report) — #6580 actually reinforces it further (anchors the detection timeout to active too, on top of the no-speech timer from #5848).
The only workaround we can see today is bypassing AMD entirely and reimplementing the classifier/timer orchestration ourselves outside the SDK so we can start listening from track subscription for specific trunks — a much larger lift than an opt-in flag, and it means losing the SDK's built-in AMD maintenance/improvements going forward.
Additional Context
- SIP mechanism: RFC 3261
183 Session Progressresponses can include an SDP body and start early media before the call is answered — see LiveKit's own SIP handshake reference, step 2.2. livekit-agentsversion: 1.6.4 in production; confirmed same behavior through 1.6.9.- Setup: outbound SIP calls via a self-hosted LiveKit server with a SIP proxy in front of direct carrier SBCs.
- Confirmed so far in Peru; we suspect the pattern isn't unique to one country/carrier given how common early-media announcements are across LATAM mobile networks, but we don't have hard confirmation elsewhere yet.
- Happy to provide a redacted SIP trace (signaling only, no RTP/audio) showing the
183+SDP → late/absent200 OKtiming if useful.
Follow-up with broader confirmation: I ran a live SIP capture across our other outbound trunks (not just the one where we first noticed this) during normal production traffic, ~13 minutes, 311 call attempts. Early media (183 Session Progress with an SDP body) before the final response shows up in effectively all of them, not just the original one:
┌───────┬──────────────────────────────────────────┬─────────────────────────────┐ │ Trunk │ Calls with 183+SDP before final response │ Avg gap 183(SDP) → 200(SDP) │ ├───────┼──────────────────────────────────────────┼─────────────────────────────┤ │ A │ 84/84 (100%) │ 23.8s (max 47.0s) │ ├───────┼──────────────────────────────────────────┼─────────────────────────────┤ │ B │ 79/79 (100%) │ 22.8s (max 47.0s) │ ├───────┼──────────────────────────────────────────┼─────────────────────────────┤ │ C │ 81/87 (93%) │ 17.6s (max 31.0s) │ ├───────┼──────────────────────────────────────────┼─────────────────────────────┤ │ D │ 22/24 (92%) │ 20.4s (max 31.5s) │ └───────┴──────────────────────────────────────────┴─────────────────────────────┘
So this isn't isolated to one carrier — the early-media mechanism (and therefore the risk of AMD missing informative pre-answer audio) shows up across every trunk we checked, with an average 17-24s window (up to ~47s) that's currently discarded entirely.
One caveat so I'm not overclaiming: SDP being present in the 183 confirms the mechanism is active, not that every one of these is carrying spoken content rather than a higher-quality ringback tone over early media (which is also common and harmless) — telling those apart is exactly what we can't do today without the opt-in to listen during this window.
Hi, I would be happy to work on this. I confirmed that current main still defers SIP AMD audio and transcript processing until sip.callStatus is active.
My proposed scope is:
- add an opt-in process_early_media: bool = False parameter to AMD.init rather than DetectionOptions, since this controls the listening lifecycle rather than classifier thresholds;
- when enabled for a SIP participant, start listening from track subscription;
- preserve the existing active-state gate by default; and
- add regression coverage for both the default and opt-in paths, including timer and cleanup behavior.
Would this API placement and scope be welcome?
@swayamg20 thanks for volunteering. A PR is welcome. We can borrow the wait_until_answered name too.
I opened #8375 for this. It is @swayamg20's commit from #6940, cherry-picked onto current main with their authorship kept, plus 4 tests in TestAMDWaitUntilAnswered. #6940 conflicts with main and has had no activity since Aug 21. The parameter is wait_until_answered, as @chenghao-mou suggested above. The default (True) keeps today's behaviour.

On main, the opt-in tests fail because the parameter does not exist. On #8375 all 4 pass. With the new gate removed, the early-media test fails again. The evidence is unit-level only: @SFGMorales, if you can try AMD(session, ..., wait_until_answered=False) on one of the Peru carriers, that would be the real check.
flowchart TD
A[Track subscribed] --> B{Publisher kind == SIP?}
B -- No --> E[_start_listening at subscription:<br/>arm both timers, open listening gate]
B -- Yes --> C{wait_until_answered?}
C -- "True (default)" --> D[Create _sip_answer_task:<br/>wait for sip.callStatus == active]
D --> F[On active: _start_listening]
F --> G[Timers armed, audio/transcript accepted]
C -- False --> E
E --> G
sequenceDiagram
participant Room
participant AMD
participant Classifier
Room->>AMD: track subscribed (SIP participant)
alt wait_until_answered = True (default, unchanged)
AMD->>AMD: _wait_for_sip_answer()
Room-->>AMD: early-media frames / ringback greeting
AMD--xClassifier: dropped (not listening yet)
Room->>AMD: sip.callStatus = active
AMD->>Classifier: start_detection_timer() + start_listening()
Room->>AMD: post-answer audio / transcript
AMD->>Classifier: push_audio() / push_text()
else wait_until_answered = False (new opt-in)
AMD->>Classifier: start_detection_timer() + start_listening()
Room->>AMD: early-media frames / greeting transcript (pre-active)
AMD->>Classifier: push_audio() / push_text()
Classifier->>Classifier: classify (e.g. machine-vm) from early media
end
Proof of concept added to #8375. I ran a simulated early-media call through the real AMD with default timers. The greeting plays from 0.5 s, the 200 OK arrives at 12 s, and Silero VAD runs on the real audio. The STT text and the LLM verdict are scripted.

| Run | AMD listens from | Verdict |
|---|---|---|
| main | 12.0 s | uncertain at 22.0 s (no_speech_timeout): the greeting was never heard |
| #8375, default | 12.0 s | the same as main |
#8375, wait_until_answered=False |
0.0 s | machine-vm at 9.3 s, before the answer |