AI Phone Agents: Voicemail Detection, DTMF, SIP REFER Transfers and Caller ID
AI Phone Agents: Voicemail Detection, DTMF, SIP REFER Transfers and Caller ID
The problem
An inbound AI phone agent has an easy start: someone called you, so a person is almost always on the line. Outbound turns that around. Your agent dials a number, the carrier sends back 200 OK, and your code assumes a human picked up. Then the agent says "Hi, is this Priya?" to a voicemail greeting, to a phone's call screening assistant, or to an IVR (interactive voice response, the "press 1 for..." menu).
Three more problems show up as soon as the agent does real work:
- A key gets pressed, by the caller or by your agent working through a menu, and the digit never arrives.
- The caller asks for a person and the transfer drops the call or connects to nothing.
- Your numbers start getting rejected or labelled as spam, and your retry loop makes it worse.
This post goes through each one from the protocol up: what the standards say, what LiveKit, Twilio, Telnyx and Asterisk document, and what India's regulator TRAI says about caller ID for automated calls. Keep the SIP response code chart open for individual codes, and the Asterisk reference chart for config.
This is part 9 of the Voice AI over SIP series. If a term is new to you, the glossary defines it in plain language and links to the part that covers it.
Why 200 OK does not mean a human answered
In SIP, 200 OK to an INVITE means the far end accepted the session. It says nothing about who or what is there. A voicemail system, an IVR and a person all answer the same way in signalling. Part 4 covers the basics: how a phone call reaches an AI voice agent.
Telnyx's docs make the order explicit. You first get a call.answered webhook, which fires whether a human or a machine answered, and only later a call.machine.detection.ended webhook with the verdict. Answer first, classification after. So answering machine detection (AMD) is a separate step that listens to the first seconds of audio and makes a guess.
sequenceDiagram autonumber participant App as Your app participant T as Telnyx participant X as Called line App->>T: dial with AMD on T->>X: INVITE X-->>T: 200 OK (human, voicemail or IVR) T-->>App: webhook call.answered Note over T,X: AMD listens to the first seconds of audio T-->>App: call.machine.detection.ended Note over App,T: Verdict: human, machine or not_sure Note over App,T: Docs: treat not_sure as human
Diagram: Answer first, classify after: call.answered fires before the AMD verdict arrives.
How answering machine detection works
The docs I read use two approaches: timing based and transcript based.
Timing based: Twilio and Asterisk
Twilio describes its AMD as isolating human speech and measuring the periods of speech and silence in the greeting. These are the tuning parameters and defaults as listed on Twilio's AMD page on 26 Nov 2026:
| Parameter | Range | Default | What it controls |
|---|---|---|---|
MachineDetectionTimeout | 3 to 59 s | 30 s | How long to try before giving up |
MachineDetectionSpeechThreshold | 1000 to 6000 ms | 2400 ms | Speech longer than this leans machine |
MachineDetectionSpeechEndThreshold | 500 to 5000 ms | 1200 ms | Silence that marks the end of speech |
MachineDetectionSilenceTimeout | 2000 to 10000 ms | 5000 ms | Initial silence before returning unknown |
Twilio is open about the failure mode: a short voicemail greeting of about 2 seconds can be classified as human. Its docs describe short greetings as roughly 1000 to 2000 ms of audio followed by 1200 to 2400 ms of silence, and suggest raising MachineDetectionSpeechEndThreshold to about 2500 ms for that case. The cost, by Twilio's own math: 2500 minus the 1200 ms default means human detection takes 1300 ms longer. That trade is the core of all timing-based AMD. Every millisecond spent being sure is dead air for a real person.
MachineDetection=Enable returns a verdict as early as possible (machine_start, human, fax, unknown). DetectMessageEnd waits for the end of the greeting and returns machine_end_beep, machine_end_silence or machine_end_other for machines, which is what you want if the agent should leave a message. By default the call is blocked until AMD finishes; AsyncAmd=true lets it run in the background, and Twilio notes async AMD uses 1 of the 4 forked streams allowed per call.
Asterisk has the same idea as a dialplan application, AMD(), available since 1.4.0. Its docs say it is for outbound calls and runs after the call is answered. The documented syntax, with all durations in milliseconds and defaults read from amd.conf:
textAMD([initialSilence,[greeting,[afterGreetingSilence,[totalAnalysisTime,[minimumWordLength,[betweenWordsSilence,[maximumNumberOfWords,[silenceThreshold,[maximumWordLength,[audioFile]]]]]]]]]])
It sets AMDSTATUS to MACHINE, HUMAN, NOTSURE or HANGUP, and AMDCAUSE to the rule that fired, such as LONGGREETING or MAXWORDS. I would log AMDCAUSE with every call outcome; it is the quickest way to see which threshold is wrong for your audience.
Telnyx: several modes and a "not sure" answer
Telnyx's answering_machine_detection modes include detect, detect_beep, detect_words, greeting_end, premium and premium_ios_call_screening_detection. Standard detection returns human, machine or not_sure, and the docs recommend treating not_sure as if a human answered. Premium returns human_residence, human_business, machine, silence, fax_detected or not_sure, with a default analysis time of 30 seconds.
The iOS call screening mode waits for the screening prompt to end (default 30000 ms, range 1000 to 120000) and reports prompt_ended, so your agent can say who it is.
Transcript based: LiveKit
LiveKit's AMD for its Agents framework works on transcripts only. Its docs say it does not detect beeps, tones or hold music. A classifier labels each turn as machine-screening, machine-ivr, machine-vm, wait, uncertain, human or machine-unavailable.
It does more than say "machine". In the IVR stage the agent can press keys through a DTMF tool; for voicemail it leaves at most one message; for screening it answers the screener. Documented defaults include waiting for 1.5 seconds of silence before speaking in a machine stage, stopping after 3 uncertain turns, a 10 second idle timeout and a 60 second overall timeout. For SIP calls, start AMD before creating the SIP participant. AMD does not hang up for you: the docs say to end the call yourself on machine-unavailable or an error.
My view: reading the words handles screening and IVRs better than silence timing, but it adds speech-to-text and classifier time to early turns. Measure that delay on real calls before using it on a dialer.
DTMF: three ways to send a keypress
DTMF (dual-tone multi-frequency) is the pair of tones a phone makes when you press a key. An AI agent needs it both ways: reading digits a caller types, and sending digits to someone else's IVR. Over SIP there are three ways to carry it.
sequenceDiagram autonumber participant S as Sender participant R as Receiver S->>R: INVITE, SDP: telephone-event/8000 R-->>S: 200 OK, SDP: telephone-event/8000 Note over S,R: Both SDPs list it, so RFC 4733 is agreed alt RFC 4733 events inside RTP (use this) S->>R: RTP event: digit 5, marker bit set S->>R: RTP event: digit 5, duration grows S->>R: RTP event: end bit set S->>R: end packet, copy 2 S->>R: end packet, copy 3 Note over S,R: Final packet sent 3 times against loss else SIP INFO on the signalling path (legacy) S->>R: INFO carrying digit 5 R-->>S: 200 OK Note over S,R: Proprietary formats, not standardized end
Diagram: RFC 4733 sends the key as events inside RTP, end packet three times; SIP INFO sends it on the signalling path.
RFC 4733 telephone-events (use this)
RFC 4733 sends keypresses as small RTP packets that describe the digit, its duration and volume, instead of the sound. It is agreed in SDP, the session description inside the INVITE and its answer. This example is from RFC 4733:
textm=audio 12344 RTP/AVP 99 a=rtpmap:99 telephone-event/8000 a=fmtp:99 0-15 a=ptime:50
0-15 lists the events the receiver accepts. In the RFC's table, digits 0 to 9 are codes 0 to 9, * is 10, # is 11 and A to D are 12 to 15. If telephone-event is missing from either side's SDP, RFC 4733 DTMF was not agreed for that call. That is the first thing I would check in a trace.
Reliability is built in. The first packet of an event sets the marker bit, the last sets the end bit, and the final packet should be sent three times so one lost packet does not cut a digit short. The RFC also recommends gateways play out only the telephone-event payload, because compressed audio may contain spurious tones.
LiveKit's DTMF docs say its stack uses telephone-event/8000, and publishDtmf takes a numeric code plus a digit. Asterisk's res_pjsip option dtmf_mode defaults to rfc4733.
SIP INFO
Some systems send each keypress as a SIP INFO request on the signalling path. RFC 6086, the INFO framework, says companies have used INFO for DTMF but that "All mechanisms are proprietary and have not been standardized", and that this legacy use caused interoperability problems. Use it only when a provider requires it.
In-band audio, and why codecs break it
In-band means the tones are plain sound in the audio stream. RFC 4733 explains why that is fragile: "low-rate voice codecs cannot be guaranteed to reproduce these tone signals accurately enough for automatic recognition", and it names G.723.1 as a codec that can make DTMF unintelligible.
The Asterisk res_pjsip reference lists the choices clearly (values as documented for Certified Asterisk 20.7):
ini; rfc4733 - out of band of the main audio stream (default) ; inband - part of the audio stream ; info - SIP INFO packets ; auto - RFC 4733 if the other side supports it, else INBAND ; auto_info - RFC 4733 if the other side supports it, else SIP INFO dtmf_mode=rfc4733
I would set rfc4733 explicitly on a trunk serving an AI agent rather than auto, so a missing telephone-event fails loudly in testing instead of silently falling back to tones.
Transferring to a human with SIP REFER
The standard SIP way to hand a call to someone else is REFER, from RFC 3515. Its example: Alice is talking to Bob and wants Bob to talk to Carol, so Alice sends Bob a REFER with Carol's address and Bob calls Carol. In voice AI terms, your agent is Alice, the carrier side of the call is Bob, and the human is Carol.
sequenceDiagram autonumber participant A as AI agent (transferor) participant B as Carrier side (caller) participant H as Human (target) A->>B: REFER, Refer-To: human B-->>A: 202 Accepted B->>A: NOTIFY sipfrag: 100 Trying A-->>B: 200 OK B->>H: INVITE to human (Referred-By copied) alt Human answers H-->>B: 200 OK B->>A: NOTIFY sipfrag: 200 OK, terminated A-->>B: 200 OK A->>B: BYE (REFER does not end the call) else Human busy H-->>B: 486 Busy Here B->>A: NOTIFY sipfrag: 486 Busy Here A-->>B: 200 OK Note over A,B: Agent takes caller off hold, call resumes end
Diagram: A REFER transfer: 202 Accepted, NOTIFY progress in sipfrag, and on 486 the caller comes back to the agent.
The rules that matter:
- A REFER must carry exactly one
Refer-Toheader; zero or more than one gets400. - If accepted, the recipient answers
202 Acceptedand creates a subscription to thereferevent. - Progress comes back in NOTIFY requests with a
message/sipfragbody, a fragment of a SIP message that starts with a status line. - The last NOTIFY carries
Subscription-State: terminated;reason=noresource, and NOTIFYs should not be sent more than once per second.
This success path is trimmed from the RFC 5589 examples (RFC 5589 is the SIP call transfer best practice):
textREFER sips:3ld812adkjw@biloxi.example.com;gr=3413kj2ha SIP/2.0 CSeq: 314159 REFER Refer-To: <sips:transfertarget@chicago.example.com> NOTIFY sips:4889445d8kjtk3@atlanta.example.com;gr=723jd2d SIP/2.0 Event: refer Subscription-State: active;expires=60 Content-Type: message/sipfrag SIP/2.0 100 Trying NOTIFY sips:4889445d8kjtk3@atlanta.example.com;gr=723jd2d SIP/2.0 Event: refer Subscription-State: terminated;reason=noresource Content-Type: message/sipfrag SIP/2.0 200 OK
If the human is busy, RFC 5589's failed-transfer example shows a NOTIFY carrying 486 Busy Here, after which the transferor takes the caller off hold and resumes the call. That is what an agent should do: a failed transfer brings the caller back, it does not drop them. RFC 5589 also notes a successful REFER does not end the original session by itself, so a BYE still has to be sent.
Referred-By. RFC 3892 adds a Referred-By header so the transfer target can see who sent the call. The referee must copy it unchanged into the new INVITE. Because the middle party could alter it, a target showing unsigned Referred-By information to its user must mark it as suspect.
Blind vs warm. RFC 5589 covers basic (blind), consultative and attended transfer; attended transfer uses the Replaces header from RFC 3891. Blind means send REFER and leave: fast, but the human starts with no context. Warm means hold the caller, brief the human, then connect.
LiveKit documents both. Cold transfer uses TransferSIPParticipant, which sends a SIP REFER through your trunk; the caller leaves the room and LiveKit has no visibility after that. Points from its call forwarding docs worth knowing before launch:
- The call must be answered first, or the transfer fails with
failed_precondition. ringing_timeoutdefaults to 30 seconds, the media timeout to 15 seconds, and the docs say to setmedia_timeoutaboveringing_timeout.- Failure reasons include
STR_REJECTED(with the SIP status code),STR_RINGING_TIMEOUT,STR_CALL_ENDEDandSTR_SUBSCRIPTION_TERMINATED. - A voicemail box, IVR or conference answering counts as success. A human's mobile rolling to voicemail looks like a good transfer to your code.
- The trunk must allow it. For Twilio that means enabling Call Transfer (SIP REFER) and PSTN transfer; Plivo supports REFER by default but blocks external SIP domains and private IPs.
- The caller ID the transfer target sees is set on the trunk, not per transfer.
LiveKit's warm transfer does not use REFER. It holds the caller, dials the human into a private consultation room with CreateSIPParticipant, has the agent summarise the call, then moves the human into the caller's room with MoveParticipant. Setup details are in part 12, LiveKit SIP trunk voice agent setup. In Asterisk, allow_transfer (default yes) controls whether REFER transfers are allowed on an endpoint.
Caller ID rules for automated calls in India
CLI (calling line identification) is the number the called person sees. For outbound AI calls in India, the key text right now is TRAI's Telecom Commercial Communications Customer Preference (Third Amendment) Regulations, 2026 (05 of 2026), dated 18 September 2026. I am stating only what that PDF says; consent, DLT and the wider picture are in part 8, India rules for AI phone calls.
- AI calls count as A2P calls. The amendment defines an A2P call as one "initiated by an application, software system, or automated platform without direct human dialling", including autodialling, robo-calls and pre-recorded or artificial voice. An AI agent placing calls fits that wording.
- Declare your CLIs. Substituted regulation 4 says every sender shall declare its use of A2P calls to the Originating Access Provider in advance, with details such as the CLI ranges it will use, recorded on the DLT platform. A call made without that declaration is treated as unsolicited commercial communication.
- Operator AI flags numbers. New regulation 21A has the terminating operator's AI/ML system flag a "Suspected high probability UCC CLI" and share it with originating operators within two hours. Five or more flagged CLIs of one sender within ten days triggers action by the operator.
- Some series are protected. CLIs from the 140xx, 1600xx and 1601xx series are not to be flagged as suspected spam, and operators must offer a way to contest a flag.
- Timing. Most of the amendment applies 30 days after Gazette publication, and regulation 4 after 60 days. Confirm the dates with your provider.
The engineering takeaway: in India the From number on your outbound trunk is a declared resource, not a config string.
Retries: read the code before you redial
Retry by the SIP final response, not by a fixed timer. RFC 3261 gives two signals. Retry-After, in seconds, can come with 500 and 503 (how long the service is down) and with 404, 413, 480, 486, 600 and 603 (when the called party may be free). And 6xx codes mean the server has definitive information about the user, not just this one attempt.
Two newer 6xx codes matter most:
- 607 Unwanted (RFC 8197): the called party marked the call unwanted, and future attempts are likely to be rejected too. Providers may add the caller to a blocklist, feed the signal into crowd-sourced scoring, or start a traceback.
- 608 Rejected (RFC 8688): an intermediary, such as an analytics engine, rejected the call, not a person. It can carry a
Call-Infoheader with signed contact details so a legitimate caller can ask for a review.
The default policy I would start with: 607 and 608 mean stop calling that number from that CLI and alert a person (for 608, read the redress contact). 603 means no retry in that campaign. 486 and 480 mean retry later, honouring Retry-After. 503 with Retry-After means back off at the trunk level, not per number. Code-by-code first checks are in the SIP response code chart.
Number reputation and spam labels
Two layers decide whether your call shows a name, shows "spam", or never rings.
Signalling feedback. A 607 is a direct reputation signal. RFC 8197 also warns that spoofed numbers could get the real owner blocked, so 607 should not drive global filters unless the caller identity is authenticated.
Caller ID authentication in the US. The FCC's 2020 rule (effective May 21, 2020) required providers to implement STIR/SHAKEN in the IP parts of their networks by June 30, 2021. The originating provider adds a signed Identity header to the SIP INVITE and the terminating provider verifies it. Attestation has three levels: A (full), B (partial) and C (gateway). The FCC notes the header is lost when a call crosses a non-SIP network. STIR/SHAKEN shows a number is not spoofed; it does not show the call is wanted.
Sources
- RFC 4733: RTP Payload for DTMF Digits, Telephony Tones, and Telephony Signals
- RFC 6086: SIP INFO Method and Package Framework
- RFC 3515: The SIP Refer Method
- RFC 3892: The SIP Referred-By Mechanism
- RFC 5589: SIP Call Control, Transfer
- RFC 3261: SIP, Session Initiation Protocol
- RFC 8197: A SIP Response Code for Unwanted Calls
- RFC 8688: A SIP Response Code for Rejected Calls
- LiveKit docs: Answering machine detection
- LiveKit docs: Handling DTMF
- LiveKit docs: Call forwarding
- LiveKit docs: Warm transfer
- Twilio docs: Answering Machine Detection
- Telnyx docs: Answering Machine Detection
- Asterisk docs: AMD dialplan application
- Asterisk docs: res_pjsip (Certified Asterisk 20.7)
- TRAI: TCCCPR (Third Amendment) Regulations, 2026
- Federal Register: FCC Call Authentication Trust Anchor rule, April 2020
