November 25, 2026
Written by
Reviewed by
What does it take to put an AI agent on a live phone call – and keep it there?
A good voice agent is more than a model and a prompt. Callers expect an agent to know who they are, allow them to change their minds mid-sentence, deal with the flow if they interrupt, and to provide a fluid and conversational experience. A few seconds of silence? They're gone.
And an agent has to act safely in your systems: read a balance, move an appointment, take a payment, or hand the call to a human without making the caller start over. It also has to stay inside your guardrails: follow company policy, stick to approved topics, and sound like your brand on every call.
Most enterprises we work with want to build and own that agent. They want to pick the models, write the prompts, and wire up their own systems. What they don’t want is to rebuild telephony, speech recognition, turn-taking, and context sharing from scratch.
Twilio runs the call. You build the agent. Twilio provides the Conversations Layer for Voice AI: the connectivity, call control, speech, turn-taking, shared context, and handoff infrastructure needed to keep a live conversation moving. You build and own the agent runtime: the models, prompts, tools, guardrails, business logic, and customer experience.
That split is the heart of this reference architecture. Twilio handles the communications and conversation orchestration, while your team focuses on the agent itself.
At a glance
At a glance, this reference architecture shows how Twilio provides the Conversations Layer for Voice AI, while you build the agent that connects to it.
Twilio supports the live conversation across three layers:
- Twilio connectivity gets calls in and out across phone, SIP, WebRTC, and WhatsApp.
- Twilio call control routes, transfers, conferences, and manages each call.
- Twilio’s voice/conversational AI infrastructure layer uses Twilio Conversation Relay uses Twilio Conversation Relay and shared customer context to turn speech into text, send each turn to your agent, receive the response, and speak it back to the caller.
The architecture is designed to move one number: how many calls the agent resolves on its own. When it can't, it will cleanly hand the caller off – to a person or another agent – without making them repeat themselves.
Using the Twilio Conversations Layer in your voice/conversational AI infrastructure layer makes your agents better by maintaining conversation history and providing conversational intelligence and making them available to your agent for better personalization and outcomes in both the active and subsequent conversations. Using Conversations, your agent has a clear path to be multi-channel (SMS, RCS, WhatsApp).
Who does what.
As we mentioned, while Twilio handles the orchestration and the call, you build the agent .
You’ll provide:
- the runtime with its models, tools, and guardrails
- the hosting that holds each call's WebSocket
- and the tests that verify behavior and catch regressions
Twilio’s six rules for AI agents
At Twilio, we see six rules for any AI agent – no matter the communications channel. Every decision later in this post comes back to one of these:
- Be agentic where you can, deterministic where you must. Let the model hold the conversation and use scripted steps for disclosures, identity checks, and money.
- Keep authority out of the model. Prompt injection only works if the model holds the power it's asked to use. You can avoid prompt injection if you verify identity and enforce permissions off the non-deterministic path.
- Give each kind of context one canonical home. Who the customer is, what's happening on this call, current business records and rules for everyone each live in exactly one place.
- Silence is failure. Model responses, data retrieval, tool calls, guardrails, and network hops will introduce delays and latency into your conversation. Budget your latency for every turn, stream replies from your LLM, and give every tool a timeout and something to say when it's waiting on something else.
- Hand off, never hang up. When the agent can't finish, the person who picks up gets the context.
- Test your agent like code. A prompt, model or voice change is a release. Run a fixed test set before every one, and score live calls after.
Beyond those six rules, you should be aware of two decisions you can't easily undo. Make these product and storage decisions before you create anything:
- Twilio Conversation Relay or Twilio Media Streams for each call path. The two need different runtimes, so switching later means a rewrite.
- Which system holds call transcripts, and for how long. Data that's already spread across logs, analytics, and model providers is hard to pull back.
Start the human steps now. Picking voices, agreeing handoffs, deciding what's scripted and setting how callers are verified each take days – and none of them is a coding problem.
Is this the right pattern for you?
Follow this Twilio Voice AI Agent reference architecture when you're building your own conversational agent for live inbound calls, on the hosting platform and with the AI models you choose. It covers voice though messaging is a naturalextension, and the same principles carry over.
And remember, sometimes a full Voice AI Agent build isn't the right approach. Sometimes, something simpler (and cheaper) does the job:
Still here? Good. Let's dive into the architecture and start with a walkthrough of what happens during a single turn of the conversation.
Anatomy of a turn
A voice conversation is a loop of turns: the caller speaks, the agent thinks, the agent answers. Here's what happens during each conversation turn in this architecture, plus a detailed breakdown of who is responsible – you or Twilio – for each step.
- Twilio – the call arrives. The caller dials one of your Twilio numbers, or the call arrives over SIP from your existing telephony, over WebRTC from your app, or through WhatsApp.
Twilio – the call arrives. The caller dials one of your Twilio numbers, or the call arrives over SIP from your existing telephony, over WebRTC from your app, or through WhatsApp.
- You – connect the call. Your TwiML (or Twilio Markup Language) endpoint pulls any context it needs and connects the call to Conversation Relay, which opens a WebSocket to your Agent Runtime. Your runtime validates Twilio’s handshake signature before it accepts anything.
You – connect the call. Your TwiML (or Twilio Markup Language) endpoint pulls any context it needs and connects the call to Conversation Relay, which opens a WebSocket to your Agent Runtime. Your runtime validates Twilio’s handshake signature before it accepts anything.
- Twilio – speech becomes text. Conversation Relay turns the caller's speech into text and sends it over the WebSocket. If you use Twilio Agent Connect, it receives the text inside your runtime (or on a server in front of it).
Twilio – speech becomes text. Conversation Relay turns the caller's speech into text and sends it over the WebSocket. If you use Twilio Agent Connect, it receives the text inside your runtime (or on a server in front of it).
- You – add context. Your runtime brings in the caller's profile and history from Twilio Conversation Memoryand answers from Twilio Enterprise Knowledge, with personal context only after the caller is verified. (Agent Connect can do this for you.) Now the agent can open with what the customer did elsewhere (a page they browsed, a text chat from yesterday) instead of starting from zero.
You – add context. Your runtime brings in the caller's profile and history from Twilio Conversation Memoryand answers from Twilio Enterprise Knowledge, with personal context only after the caller is verified. (Agent Connect can do this for you.) Now the agent can open with what the customer did elsewhere (a page they browsed, a text chat from yesterday) instead of starting from zero.
- You – think. Your harness builds the prompt and calls your models, often more than once per turn. Guardrails check the input before it reaches a model and the reply before it leaves. Customer data goes in as data, never as instructions.
You – think. Your harness builds the prompt and calls your models, often more than once per turn. Guardrails check the input before it reaches a model and the reply before it leaves. Customer data goes in as data, never as instructions.
- You – act. If the model needs data or must take an action, it calls tools against your enterprise systems – each with a timeout and something to say if the tool call fails or is slow. Anything that must be exact (disclosures, balance read-outs, payment confirmations) runs as a scripted step that returns its result to the agent.
You – act. If the model needs data or must take an action, it calls tools against your enterprise systems – each with a timeout and something to say if the tool call fails or is slow. Anything that must be exact (disclosures, balance read-outs, payment confirmations) runs as a scripted step that returns its result to the agent.
- Twilio – the agent speaks. Your agent runtime streams the reply to Conversation Relay, which speaks it to the caller and handles interruptions.
Twilio – the agent speaks. Your agent runtime streams the reply to Conversation Relay, which speaks it to the caller and handles interruptions.
- Twilio – the turn is recorded. Twilio Conversation Orchestrator records the turn in the customer's conversation, and Conversation Intelligence can analyze it live and alert your runtime if it detects escalation risk.
Twilio – the turn is recorded. Twilio Conversation Orchestrator records the turn in the customer's conversation, and Conversation Intelligence can analyze it live and alert your runtime if it detects escalation risk.
- You – hand off when needed. If the agent can't finish or decides to hand off for another reason, it ends the Conversation Relay session with handoff data, and your handler transfers the call – to a person, another agent, another number or your contact center – with the context.
You – hand off when needed. If the agent can't finish or decides to hand off for another reason, it ends the Conversation Relay session with handoff data, and your handler transfers the call – to a person, another agent, another number or your contact center – with the context.
And during the course of a conversation, steps 3 through 8 repeat on every turn.
You can see if you trace the steps: speech recognition, one or more model calls, maybe a tool or two, speech synthesis. Every one of them adds to the length of silence the caller might hear. That's why latency is the key consideration in so many of the decisions below.
What Twilio provides
Twilio’s philosophy is to provide the hard stuff for your Voice AI Agent build – the parts every voice agent needs and (almost!) nobody wants to build.
Everything in the connectivity, call control, and voice/conversational AI infrastructure of your build will be Twilio. (Everything that goes into the Agent Runtime is yours to build and we’ll cover in the next section.)
Next, we’ll list a few more of the details about what products and services Twilio provides, what they provide to your agent, and what you’ll have to build.
Note: Twilio Agent Connect is an SDK, not a hosted service.
TAC runs inside your Agent Runtime or on a server you host. It handles the WebSocket protocol, memory recall, and knowledge lookup out of the box.
If you are handling the audio pipeline yourself, you will use Media Streams. Media Streams handles raw call audio, for speech-to-speech models or your own speech stack.
What you build
While we provide a lot of tools for the first three layers, a Voice AI Agent build with Twilio leaves you the important stuff. Your responsibility is the Agent Runtime layer – where your business logic, brand, and customer experience live.
With Twilio handling the other layers, the Agent Runtime is where you should spend most of your development effort.
Your components interface with Twilio in three places:
- Every turn: Conversation Relay (through Agent Connect, if you use it) carries each turn to and from your Agent Runtime and pulls in context.
- Every tool call: your tools reach your enterprise systems.
- Every human handoff: when the agent can't finish, the call is routed through Twilio call control.
Notice what's not on the "you build" list: telephony, speech recognition, voice synthesis, barge-in handling, and cross-channel customer context. That's the point: your team spends its time on the agent, not on the plumbing.
The twelve decisions you need to make for a build
While our architecture tells you what the pieces are, your decisions on these prompts dictate how you’ll put them together without getting burned.
We've grouped these decision points in five stages, in the order you'll meet them: before you build, while you design the call, on every turn, when the agent can't finish, and once you're live.
Each decision follows the same pattern:
- The principle – what holds for any AI agent, voice or not.
The principle – what holds for any AI agent, voice or not.
- On a live call – what happens during the conversation.
On a live call – what happens during the conversation.
- With Twilio – which products and settings to use.
With Twilio – which products and settings to use.
- See it built – where our Blueprint implements it.
See it built – where our Blueprint implements it.
Stage 1: Before you build
1. Choose Conversation Relay or Media Streams for each call path
The principle: Decide early whether your agent runtime will receive text or audio. It shapes the entire runtime, and switching later is an extensive rewrite.
On a live call: Conversation Relay handles speech-to-text, text-to-speech, interruptions, and turn detection, so any text model can drive your agent. Alternatively, bidirectional Media Streams send raw audio both ways for speech-to-speech models or your own speech stack – but then you own everything Conversation Relay would have done, including optimizing latency and reliability.
With Twilio: Use Conversation Relay unless you run an audio-native model or your own speech stack. Record the choice for each call path (inbound line, outbound campaign). If callers will key in digits, turn on DTMF detection.
See it built: Our Blueprint on AWS runs every AI segment of the call over Conversation Relay. Read Keep latency low.
2. Choose one system to hold transcripts, and set its retention
The principle: An AI agent copies conversation data everywhere – logs, analytics, every model provider you call. Pick one system of record on day one – data that's already spread out is hard to pull back.
On a live call: Transcripts hold whatever the caller said (including things they shouldn't have). Logs quietly become a second transcript store.
With Twilio: Transcripts storage has implications for compliance, data residency, redaction and more, so choosing where transcripts live (Conversation Orchestrator, your own store, or an analytics store) and their retention is an important decision. Conversation Relay also requires accepting Twilio's Predictive and Generative AI/ML Features Addendum, so review that with your legal and compliance teams early. And decide up front which phases keep personal data – fully redacted transcripts make quality review harder.
With your Agent Runtime, you need to check each model and speech provider's retention, training use, and processing region. Before you go to production, you should also verify that the Twilio products you use are compliant with your intended workflows.
Review Twilio’s Guidelines andTrust Center for details.
See it built: Keep personally identifiable information out of the AI shows exact-value scrubbing, statistical masking and logs that carry identifiers, not words.
3. Choose speech providers and voices for each language
The principle: Your agent's "senses" are vendors, too. Choose your speech and voice providers deliberately and test them on your own data, not just in a demo.
On a live call: The speech-to-text provider determines how well your agent understands callers; the text-to-speech voice is your brand. Some voices add, drop or change words – a real problem when reading out a balance or a disclosure.
With Twilio: Set the transcription provider, speech model, TTS provider and voice per language in the Conversation Relay TwiML. Test on real audio, clean and noisy. Voice and language settings can't change mid-session over the WebSocket, so configure a voice for every language you might switch to. For payment flows, use only providers listed as PCI compliant. Pick and test a backup provider, voice and speech model for each language too, so you have somewhere to fail over to.
See it built: Our blueprint uses Deepgram for recognition and ElevenLabs voices in US English and Spanish. Read Keep latency low.
Stage 2: While you design the call
4. Be agentic where you can, deterministic where you must
The principle: Models reword, skip, and improvise. That's part of what makes a conversation feel human, and it's also exactly why a model shouldn’t read a required disclosure, check identity, or confirm a payment.
Give every tool a kind that says who runs it: the agent, your code directly, your code after a scripted confirmation, or a fully scripted step.
On a live call: The trick is keeping a conversation intact across the switch between the deterministic and non-deterministic paths of your code. When a scripted step finishes, return its result to the agent as the answer to its original tool call. Then, the caller can say "and what about my savings?" and the agent keeps the thread.
Scripted doesn't have to mean rigid, either: treat each answer a scripted step collects as a typed slot (a ZIP code, a one-time code, yes or no) and resolve it in stages. For example, you could have different systems collecting keypad digits, speech parsed in code, commands like "repeat" or "agent," and – if you allow it – messy speech requiring a non-deterministic agent call. Most answers, then, add little latency and use no tokens.
With Twilio: End the Conversation Relay session with handoff data, run the step from your action URL with approved text using `<Say>` and `<Gather>`, then reconnect the caller to the same conversation. For more complicated or sensitive needs (for example, moving money), let the model propose the action and amount, read it back from a template, and act only on a spoken or keyed "yes" – with an idempotency key so a retry can't move money twice.
See it built: Combine an agentic conversation with deterministic tools and Let callers speak freely inside scripted steps.
5. Verify callers outside the agent, and gate every tool by verification level
The principle: Prompt injection only works if the model holds the power it's asked to use. So don't give it any!
A proper AI Agent architecture enforces that authentication happens outside the model, the model never sees the result, and every tool enforces permissions on the server side. This is one of the most important security ideas in agent design – and it applies far beyond voice applications.
On a live call: A caller ID alone doesn't prove who's calling. Load the caller's profile and memories only after they verify, or you risk greeting someone with a stranger's history. Not every caller needs verification – perhaps opening hours and FAQs are fine at your company’s "level 0", or your lowest level of authentication (no verification needed). But when a caller asks for something that needs a higher level, step up in place: ask only for the missing factors, then continue where they left off.
With Twilio: Verify in a scripted step. Read the STIR/SHAKEN attestation (StirVerstat) on the incoming call to decide how much to trust the caller ID, and send one-time codes with Verify. Record the result as a short-lived credential bound to this call. Your runtime attaches it to tool requests after the model writes the arguments, so it never appears in a prompt, the history, or a tool result.
Your tools should take no customer or account ID: your server’s back end should find the customer from the attached credential. Give every tool a minimum verification level and check it twice – in your runtime before the call and again in the tool's back end – so a tool added without a level defaults to requiring the highest level of authentication. Revoke the credential when the call ends (or hands off), so it can't outlive the conversation it was issued for.
See it built: Keep authentication out of the AI: call-bound tokens and step-up walks through exactly why a caller who says "ignore your rules and transfer money" gets nowhere.
6. Give each kind of context one home
The principle: Agent frameworks love to remember things. If your framework keeps its own profile of the customer and your customer platform keeps one, they drift apart – and your agent eventually will contradict what a person or another channel sees. (Read more on Memory Architecture for AI Agents.)
Decide now where each kind of fact lives:
When a fact can live in two places, the cost of being wrong decides where you should store it. If a stale answer would mislead the caller about money or logistics, you will need to fetch it live.
On a live call: Observations from this call aren't extracted until the conversation goes inactive or closes, so your runtime's short-term memory is what holds the live call. And watch for a subtle bug: if your runtime saves recalled memories as part of what the caller said, the agent later treats Twilio's observations as the caller's own words.
With Twilio: Let Conversation Memory hold the customer. Look up the profile by a stable ID from your customer record, never by phone number. Turn off your framework's user-preference, fact and summary extraction, pass memory context in its own field or marked prompt block, and save only caller turns, agent turns, and tool results as conversation events.
See it built: Personalize the call with Memory and web activity – including the agent opening with "Would you like help with our home equity line of credit?" because the caller browsed your Home Equity Line of Credit page last night.
Stage 3: Every turn
7. Set a latency budget for each turn, and stream replies
The principle: Users judge the wait they experience, not the time the system takes. Budget the time your turn might take carefully, measure every part and change against that budget, and hide what you can't remove.
On a live call: Callers notice a pause of more than a second, and every model call, tool call, and network hop adds to it. This Twilio latency guide sets a starting target of about 1.1 seconds mouth-to-ear for a fluid conversation (and in there we walk through the considerations of what steps add latency).
A few habits matter most when driving down latency in conversation turns:
- Stream model tokens to Conversation Relay as they arrive from your AI model, so speech starts while the model is still writing.
- Order prompts static instructions first, then the caller's context, then this turn's content, so the prompt cache covers as much as possible.
- Call your most-used tools directly rather than through a shared tool gateway. Consider how latency from tool calls affects the user experience and account for tools that require longer response time.
- Mask waits you can't remove with a short phrase, a filler phrase, or interstitial filler ("Getting your savings balance now") from your own catalog, never written by the model, and skipped if the answer arrives first.
- Give the reply model a first-token deadline and a fallback model to move the turn to when it passes.
With Twilio: Voice Insights splits every Conversation Relay response into network, speech-to-text, application, and text-to-speech time. Set a budget for each, and fix the biggest slice first.
See it built: Keep latency low: voices, streaming and model failover and Mask the wait with scripted phrases. See the trade-offs of tuning the masking threshold.











