
The Asterisk Gateway Interface (AGI) is a powerful tool that allows developers to create custom applications for Asterisk, a popular open-source PBX. It's essentially a bridge between your application and Asterisk.
AGI scripts are written in a language like PHP, Perl, or Python, and are executed by the Asterisk server. This means you can use your programming skills to create custom interfaces and automate tasks.
To get started with AGI, you'll need to have Asterisk installed on your system, along with a suitable development environment. The AGI protocol is based on a simple request-response model, where your script sends a command to Asterisk and receives a response.
None of the provided subheadings are relevant to the topic "Asterisk Gateway Interface." Therefore, no suitable subheading can be selected from the list
The Asterisk Gateway Interface (AGI) is a language-independent API for processing calls, making it a game-changer for programmers and telephony enthusiasts. It allows for simple programs to manipulate and route calls on Asterisk servers.
AGI provides a way to add functionality to Asterisk PBX systems, and its intended audience includes programmers, telephony enthusiasts, and IT people. The AGI interface consists of a number of action classes that are sent to Asterisk to effect actions on active channels.
There are two different means of getting access to a channel: AGI and FastAGI. AGI runs as a child process of Asterisk, while FastAGI runs over a TCP/IP socket, allowing for faster startup times and lower overhead.
FastAGI is the recommended protocol for large applications because it allows for all AGI functionality except EAGI, and provides a solution to developers who need to run resource-intensive AGI programs. This way, the Asterisk server itself can process calls without handling complex computation for other services.
The EAGI is rarely used but gives developers a way to access the audio channel directly for the calls being processed, providing a way to analyze raw audio data.
AGI Configuration
To start your AGI application, you'll use the AGI() dialplan application from your own dialplan. For example, in extensions.conf, you can tell Asterisk to start an AGI application when a call is made to the '1' extension with the line: exten => 1,1,AGI(myApplication.php).
The AGI configuration in Asterisk is controlled by several environment variables. These variables can be found in the asterisk.conf file, specifically in the astetcdir, astmoddir, and astvarlibdir keys. These keys point to directories where Asterisk looks for configuration files and other resources.
Here are the environment variables that are relevant to AGI configuration:
- AST_CONFIG_DIR: the directory where Asterisk configuration files are stored (astetcdir key from asterisk.conf)
- AST_CONFIG_FILE: the absolute path to the asterisk.conf file used
- AST_MODULE_DIR: the directory where Asterisk modules are stored (astmoddir key from asterisk.conf)
- AST_SPOOL_DIR: the directory where Asterisk stores spool files (astspooldir key from asterisk.conf)
- AST_MONITOR_DIR: the directory where Asterisk stores monitor files (usually AST_SPOOL_DIR/monitor)
- AST_VAR_DIR: the directory where Asterisk stores variable files (astvarlibdir key from asterisk.conf)
- AST_DATA_DIR: the directory where Asterisk stores database files (astdbdir key from asterisk.conf)
- AST_LOG_DIR: the directory where Asterisk stores log files (astlogdir key from asterisk.conf)
- AST_AGI_DIR: the directory where Asterisk stores AGI files (astagidir key from asterisk.conf)
- AST_KEY_DIR: the directory where Asterisk stores key files (astkeydir key from asterisk.conf)
- AST_RUN_DIR: the directory where Asterisk stores run files (astrundir key from asterisk.conf)
PBX Configuration for AGI Telephony
To start your AGI application, you'll use the AGI() dialplan application from your own dialplan. For example, in extensions.conf, you can use the following code to tell Asterisk to start an AGI application when a call is made to the '1' extension:
exten => 1,1,AGI(myApplication.php)
This is a simple way to get started with AGI telephony.
To make AGI applications work, you'll need to configure Asterisk properly. There are several directories that need to be set up, including:
- AST_CONFIG_DIR: This is the directory where Asterisk stores its configuration files.
- AST_CONFIG_FILE: This is the absolute path to the Asterisk configuration file used.
- AST_MODULE_DIR: This is the directory where Asterisk stores its modules.
- AST_SPOOL_DIR: This is the directory where Asterisk stores its spool files.
- AST_MONITOR_DIR: This is the directory where Asterisk stores its monitor files.
- AST_VAR_DIR: This is the directory where Asterisk stores its variable files.
- AST_DATA_DIR: This is the directory where Asterisk stores its data files.
- AST_LOG_DIR: This is the directory where Asterisk stores its log files.
- AST_AGI_DIR: This is the directory where Asterisk stores its AGI files.
- AST_KEY_DIR: This is the directory where Asterisk stores its key files.
- AST_RUN_DIR: This is the directory where Asterisk stores its run files.
To configure Asterisk to run an example, you can use the following code in your dialplan:
exten => 1,1,AGI(/tmp/agi.sh,arg1,arg2,arg3)
This will run an AGI application that creates a file called /tmp/dump.txt with the output from the channel variables.
Configure Example Run
To configure an example run in Asterisk, you need to create an extension that calls an AGI application. This can be done by adding a line like "exten => 1,1,AGI(/tmp/agi.sh,arg1,arg2,arg3)" to your dialplan.
The AGI application should be a shell script that creates a file, in this case /tmp/dump.txt, with the output from the channel variables. This application does nothing at all, it will end when Asterisk sends an empty line, which marks the end of the channel variables block.
To make a call to the '1' extension, you simply dial the number associated with this extension, and your AGI application should run.
Asterisk responds to AGI commands with a specific format, which includes an error code, result data, and additional data. Here are the possible error codes:
- 200: Operation was completed successfully.
- 510: Invalid or unknown command.
- 511: The command can't be executed on a dead (closed, terminated, hung up) channel.
- 520: End of proper usage, when the command returns its syntax.
As an AGI script, you should always set the AGI variable AGISTATUS to one of the following values: SUCCESS, FAILURE, or HANGUP.
Send AGI Commands and Receive Responses for Basic IVR
Sending AGI commands and receiving responses is a fundamental aspect of creating a basic IVR (Interactive Voice Response) system using the Asterisk Gateway Interface (AGI).
To send an AGI command, you need to use a specific syntax, such as "VERBOSE "message" 3", where "verbose" is the command, and "message" and "3" are the arguments.
Asterisk responds to AGI commands with a format that includes an error code, result data, and optional additional data. For example, a response might look like this: "200 result=1", where "200" is the error code, "result" is the result data, and "1" is the value of the result.
A unique perspective: Azure on Premise Data Gateway
The error code can be one of several values, including 200 for a successful operation, 510 for an invalid or unknown command, 511 for a command that can't be executed on a dead channel, or 520 for the end of proper usage.
To indicate the result of an AGI command, you should set the AGISTATUS variable to one of three values: SUCCESS, FAILURE, or HANGUP.
Broaden your view: How to Store Values in Interface Golang
AGI Requirements and Versions
To get started with AGI, your application must meet certain requirements. It must be executable, which means it can run on its own without any issues.
The application must also be located in /usr/share/asterisk/agi-bin, as specified in the astagidir variable in asterisk.conf.
You'll also need to specify the application in the dialplan, complete with an extension.
Here are the specific requirements in a concise list:
- Must be executable
- Must be located in /usr/share/asterisk/agi-bin
- Must be specified in the dialplan complete with an extension
Requirements for Applications
To develop an application that utilizes AGI, you must ensure it meets the following requirements.
First and foremost, your application must be executable. This is a fundamental requirement for any AGI application.

The application must also be located in the /usr/share/asterisk/agi-bin directory, as specified in the astagidir variable in asterisk.conf.
To utilize the application in the dialplan, you must specify it with an extension.
Here are the requirements in a concise list:
- Must be executable
- Must be located in /usr/share/asterisk/agi-bin
- Must be specified in the dialplan complete with an extension
1.4.x
In the 1.4.x version, we see a significant milestone in the development of AGI. This version is characterized by the integration of multiple AI models, which enables more efficient and effective decision-making.
The 1.4.x version is notable for its ability to learn from both structured and unstructured data, making it a more versatile tool for various applications. This is a crucial advancement in AGI development, allowing for more accurate and comprehensive knowledge representation.
One key feature of the 1.4.x version is its enhanced explainability, which provides users with a clearer understanding of the AI's thought process and decision-making. This transparency is essential for building trust in AGI systems.
The 1.4.x version also introduces a more robust and scalable architecture, enabling it to handle complex tasks and large datasets with ease. This scalability is critical for widespread adoption of AGI in various industries.
Check this out: Azure Application Gateway Tls Version
Running AGI
To run an AGI application, you'll need to use the AGI() dialplan application from your own dialplan. For example, in extensions.conf, you can add a line like this: exten => 1,1,AGI(myApplication.php) to start the application when a call is made to the '1' extension.
The AGI() application takes the name of the application as an argument, which can be a PHP script, a Python script, or any other type of script that Asterisk can execute.
You can use the AST_CONFIG_DIR environment variable to specify the directory where Asterisk configuration files are stored. This variable is set to the value of the astetcdir key in asterisk.conf.
Asterisk also provides several other environment variables that can be used to customize the behavior of the AGI application. These variables include AST_CONFIG_FILE, AST_MODULE_DIR, AST_SPOOL_DIR, AST_MONITOR_DIR, AST_VAR_DIR, AST_DATA_DIR, AST_LOG_DIR, AST_AGI_DIR, AST_KEY_DIR, and AST_RUN_DIR.
Here's a list of the environment variables provided by Asterisk:
- AST_CONFIG_DIR: astetcdir key from asterisk.conf.
- AST_CONFIG_FILE: absolute path to the asterisk.conf file used.
- AST_MODULE_DIR: astmoddir key from asterisk.conf.
- AST_SPOOL_DIR: astspooldir key from asterisk.conf.
- AST_MONITOR_DIR: usually AST_SPOOL_DIR/monitor
- AST_VAR_DIR: astvarlibdir key from asterisk.conf.
- AST_DATA_DIR: astdbdir key from asterisk.conf.
- AST_LOG_DIR: astlogdir key from asterisk.conf.
- AST_AGI_DIR: astagidir key from asterisk.conf.
- AST_KEY_DIR: astkeydir key from asterisk.conf.
- AST_RUN_DIR: astrundir key from asterisk.conf.
To start an AGI application, you can use the command: exten => 1,1,AGI(/tmp/agi.sh,arg1,arg2,arg3) which will run the application and create a file /tmp/dump.txt with the output from the channel variables.
The AGI application will end when Asterisk sends an empty line, which marks the end of the channel variables block.
Gateway Interface
The Asterisk Gateway Interface (AGI) is a software interface and communications protocol for application level control of selected features of the Asterisk PBX.
AGI allows an external program to control telephony operations on its associated control and voice channels. This is done via pipes launched from the Asterisk dial plan.
The initial feature set of AGI included only procedural control of Asterisk operations via commands and response handshake. This was later enhanced by EAGI, which provided out-of-band access to the incoming audio stream.
FastAGI is an extension to AGI that allows the external program to run at a separate network host. This avoids the overhead of creating a new process for every call on the Asterisk server.
The default TCP port for FastAGI is 4573, and it employs a URI format of agi://hostname[:port][/program/path]. This is similar to the client-server model used in HTTP.
Featured Images: pexels.com

