Asterisk FastAGI


Implements the Asterisk Gateway Interface (AGI) over TCP sockets. This can help alleviate CPU load on your telephony server by relocating resource hungry scripts to another networked server. In order to instruct Asterisk to attempt a network connection, you must supply the hostname or IP address of the server where your FastAGI service is hosted and preface it with agi://:

exten => 5551212,1,AGI(agi://

Note that the agi:// syntax can be used with both the AGI and DeadAGI dialplan commands, while EAGI is currently not supported. The previous example instructs Asterisk to make a network connection to a host running on a local network server when the 5551212 extension is matched. By default, Asterisk attempts to connect to the specified server over port 4573. The port can also be specified should you choose to host the AGI service on another port:

exten => 5551212,1,AGI(agi://

A request may also be specified in the FastAGI call, so that you can host multiple AGIs in a single network location. This request allows the FastAGI service to differentiate between different locations in the dialplan. For example:

exten => 5551212,1,AGI(agi://


exten => 5551212,1,AGI(agi://

The request portion of these calls will be received by the FastAGI service as the agi_network_script AGI variable. Asterisk will also include the agi_network AGI variable. For example, the FastAGI in the previous example would receive something like this when called by Asterisk:

agi_network: yes
agi_network_script: CallerWantsCustomerService

Passing Arguments to FastAGI

Asterisk 1.6.x

In Asterisk 1.6.x, arguments passed to the AGI command are passed through to the FastAGI as AGI variables. For example, calling a FastAGI with the following:

exten => 5551212,1,AGI(agi://,${EXTEN},${UNIQUEID},${CALLERID(name)})

will result in the following AGI variables being passed to the FastAGI service:

agi_network: yes
agi_network_script: CallerWantsCustomerService
agi_arg_1: 5551212
agi_arg_2: 1171048538.5875
agi_arg_3: Mark Spencer

The method described below for both Asterisk 1.2 and 1.4 is also still supported.

Asterisk 1.2 & 1.4

With Asterisk 1.2 through 1.4, when using standard AGI, you can pass variables on the command line to your local scripts. While this is not possible with FastAGI, it can be simulated using agi_network_script and a query syntax similar to that used by HTTP. For example:

exten => 5551212,1,AGI(agi://${EXTEN})

In this case, the following AGI variables will be passed to the FastAGI service:

agi_network: yes
agi_network_script: /GetCallerRecord?extension=5551212

It is the responsibility of your FastAGI framework to parse this information out of the agi_network_script variable. Some FastAGI implementations already do this for you, so be sure to check the documentation for your particular framework.

Error Handling

Asterisk 1.4 & 1.6.x

As of Asterisk 1.4 a new channel variable, AGISTATUS, is set to SUCCESS upon successful execution of an AGI. If there was a problem connecting to the FastAGI service, the channel variable is set to FAILURE, allowing the dialplan to perform alternate steps as not to interrupt the call flow. If the calling channel hangs up during execution of
Created by: JustRumours, Last modification: Wed 16 of May, 2012 (18:24 UTC) by admin
Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - Find us on Google+