Bridgeside AI
← All posts

Asterisk AI Agent Architectures Compared, AGI, ARI, AudioSocket and RTP

Four ways to connect an AI voice agent to Asterisk, what each one costs you in latency, barge-in, scaling and day to day operations, and which one Bridgeside uses.

There is more than one way to build an Asterisk AI agent, and the choice you make early decides how fast the agent answers, whether callers can interrupt it, how it scales and who gets paged when it breaks. Asterisk offers at least four places to attach a voice AI: AGI scripts, the Asterisk REST Interface with external media, AudioSocket, and plain RTP from the dialplan. This post compares them on the things that matter in a call center, then explains which one Bridgeside uses and why.

For the step by step setup on a PBX, see the FreePBX AI agent guide. For a short tour of the Bridgeside integration, see how to add AI voice agents to Asterisk and FreePBX.

What any Asterisk AI agent has to do

Whatever the architecture, an Asterisk AI voice agent needs four things:

  1. Audio in: the caller's voice, as it is spoken, delivered to speech recognition.
  2. Audio out: the agent's speech played to the caller, and stopped at once when the caller talks over it.
  3. Call control: a way to transfer the caller to a person and to hang up.
  4. Results: the outcome of the call written somewhere useful, such as a lead record or a CRM.

The architectures differ mainly in the first three. Results are usually handled after the call, by an API or a webhook, and look much the same in every design.

Option 1. AGI and FastAGI scripts

AGI is the oldest way to put logic on a call. The dialplan runs a script with AGI(), and the script talks to Asterisk over standard input and output, one command at a time. FastAGI does the same over TCP, so the script runs as a network service instead of a process per call.

An AI agent built on AGI is usually turn based. The script records what the caller says until it hears silence, sends the file to speech recognition, asks the language model for a reply, turns the reply into an audio file and plays it. Then it records again.

What you give up:

  • Latency. Each turn waits for the silence timeout, then for every step to finish one after another. Callers notice the pause.
  • Barge-in. Playback commands can stop on a DTMF key, not on speech. Interrupting the agent by talking is hard to do well.
  • Streaming. EAGI hands the script the caller's audio on an extra file descriptor, which helps on the listening side, but the speaking side is still file playback.

AGI is easy to start with and fine for short, structured flows such as a voice menu that understands a few words. For an open conversation it feels slow.

Option 2. ARI with external media

The Asterisk REST Interface lets an external application control calls through HTTP requests and a WebSocket of events. A call enters your application with the Stasis() dialplan application. To get audio out, the application asks Asterisk to create an external media channel, which sends and receives the call's audio to a host and port you choose, then puts that channel in a bridge with the caller.

What you get is full control. The application decides everything: bridging, playback, recording, transfers, conference legs. Audio streams in real time both ways, so barge-in and low latency are possible.

What you give up:

  • Ownership of the call. While the call is in Stasis, your application runs it, not the dialplan. On a system where a dialer or a carefully tuned dialplan already owns call flow, that is a large change.
  • Operations. The ARI application must be running and connected all the time, handle reconnects, and keep its own state for every call. If it falls over, calls in Stasis are stuck until it returns.
  • Complexity. Bridges, channel lifecycles and event ordering all become your code.

ARI is the right tool when you are building a new telephony application on Asterisk. It is a heavy tool for adding an agent to a system that already works.

Option 3. AudioSocket

AudioSocket is a small Asterisk module that streams a call's audio over a plain TCP connection. The dialplan calls AudioSocket() with a UUID and a host and port; Asterisk connects, sends 16-bit signed linear audio at 8 kHz in small framed messages, and plays whatever audio comes back. It appeared in the Asterisk 16 series and is part of later versions.

What you get: real-time audio both ways over one TCP socket, a simple protocol, and the call stays in the dialplan.

What you give up: the module must be compiled into your Asterisk build, and not every packaged build has it, including some dialer distributions. Like RTP, it carries audio only, so transfers and hangups still need AMI. Bridgeside can run AudioSocket on request; ask through contact if it suits your setup better.

Option 4. UnicastRTP from the dialplan

Since Asterisk 15, chan_rtp provides a UnicastRTP channel. Dial(UnicastRTP/host:port/c(ulaw)) makes Asterisk send the call's audio as RTP to that address and play the RTP that comes back. It is a normal channel, so it works inside a normal Dial() and needs no extra module on most builds.

What you get: real-time G.711 audio both ways, no new software on the PBX, and the call stays in the dialplan under your control.

What you give up: RTP has no signalling. Nothing in the stream says "the caller hung up" or "transfer this call". So the design needs a side channel for control (AMI), and the receiving end must treat a stream that stops sending packets as a finished call. It also needs one UDP port per call to be reachable, so the firewall matters.

How the options compare

AGI / FastAGIARI external mediaAudioSocketUnicastRTP
AudioFiles per turn (EAGI streams in only)Real-time both waysReal-time both waysReal-time both ways
Barge-in by voiceHardYesYesYes
Who runs the callDialplan plus scriptYour ARI applicationDialplanDialplan
Extra software on the PBXScript or FastAGI serverAlways-on ARI applicationModule in the buildNone on most builds
Transfer and hangupAGI commandsARIAMIAMI
NetworkLocal or TCPHTTP, WebSocket and RTPOne TCP socket per callOne UDP port per call

Latency in all the streaming options is dominated by speech recognition, the language model and voice synthesis, not by the transport. The big difference is between turn based (AGI) and streaming (the other three).

Which one Bridgeside uses, and why

Bridgeside connects to Asterisk, FreePBX, Issabel and VICIdial with UnicastRTP plus AMI. One generated dialplan entry matches _85XXX. It uses CURL to request a free UDP port for this call from /api/asterisk/rtp, passing the channel name and caller ID, then dials UnicastRTP to that port in ulaw:

exten => _85XXX,1,Answer()
  same => n,Set(PORT=${CURL(https://app.bridgeside.ai/api/asterisk/rtp?token=YOUR_TOKEN&agent=${EXTEN:2}&channel=${URIENCODE(${CHANNEL})})})
  same => n,GotoIf($["${PORT}" = ""]?fail)
  same => n,Dial(UnicastRTP/162.35.111.14:${PORT}/c(ulaw),,b(voicebot-jb^s^1))

(Shortened. The entry the portal generates also passes the caller ID and includes the failure branch and the jitter buffer routine.)

The reasons:

  • It works on what call centers already run. VICIdial's Asterisk 16 and 18 builds have chan_rtp but not always AudioSocket. FreePBX and Issabel have it too. Nothing has to be compiled.
  • The dialplan stays in charge. A transfer is an AMI Redirect of the caller's channel into your own context, so the call lands in an in-group, queue or ring group exactly as any other call would.
  • One entry for every campaign. The digits after 85 pick the campaign, so new campaigns never touch the PBX.
  • The per-call port solves the signalling gap. Because the port request carries the channel name, the agent knows which channel to redirect or hang up over AMI. The AMI hangup event ends the session when the caller hangs up, and a stream that goes quiet for a few seconds is treated as ended.

Barge-in works because audio streams continuously in both directions: Bridgeside sends silence when the agent is quiet, and when speech recognition hears the caller start talking, the agent's playback is cut. Hangup and transfer need only three AMI permissions: the hangup event, Hangup and Redirect. The one dialplan entry post walks through every line.

FAQ

What is an Asterisk AI agent?

An Asterisk AI agent is a voice agent that answers or places calls through an Asterisk PBX. Asterisk handles the phone side; speech recognition, a language model and voice synthesis handle the conversation. The two are joined by one of the architectures above.

Which Asterisk AI architecture has the lowest latency?

Any streaming design (ARI external media, AudioSocket or UnicastRTP) beats turn based AGI, because the agent hears speech as it is spoken and does not wait for a recording to finish. Between the streaming options the transport is a small part of the total.

Can I add Asterisk AI without ARI?

Yes. UnicastRTP and AudioSocket both keep the call in the dialplan and use AMI for control, so no ARI application is needed.

Does an Asterisk AI voice agent need a new SIP trunk?

Not with a dialplan bridge. Calls arrive on your existing trunks; only the audio between the PBX and the agent travels separately, as RTP or a TCP stream.

What Asterisk version do I need?

UnicastRTP needs Asterisk 15 or newer. AudioSocket needs a build that includes the module, which first appeared in the 16 series.

See it on your own PBX

The Asterisk integration page has the short version, and pricing starts with pay as you go and no monthly fee. Try it with 60 free minutes and no card at app.bridgeside.ai.

Put an AI agent on your dialer

60 free minutes, no card, one dialplan entry.