Writing ASTRA Programs

Before we launch into some examples of ASTRA programs, the last thing we need to do is to introduce the overall structure of an ASTRA program.  ASTRA is different form AgentSpeak(L) in the following ways:

  • agent programs are organised into agent classes that can be extended based on a multiple inheritance model
  • the primitive actions used must be explicitly declared in the agent program
  • ASTRA programs can reference java classes, so support needs to be provided for providing fully qualified class names
  • in addition to plan rules, ASTRA programs include partial plans (named plan bodies) in order to improve code/class resuability.
  • ASTRA aims to be familiar to developers who know mainstream programming languages, and in particular Java.

The result is that ASTRA programs are a little more structured than AgentSpeak(L) programs. An illustration of the basic structure is given below:

package path.to.folder;

import java.lang.Object;

agent MyAgent {
    // code goes here

As can be seen here, ASTRA has adopted the package nomenclature that is used in Java.  The package is the path from the root (src) folder to the folder containing the ASTRA class. As with Java, if the program is declared in the root folder, no package statement is required.

Import statements can be used to resolve Java class names to their fully qualified canonical class names.

The agent keyword is used to denote the start of the agent program and curly braces identify the body of that program (known here as an agent class).  Currently only one class program is permitted per file and each file must have the same name as the agent class and the .astra file extension must be used. For example, the above program must be in a file called MyAgent.astra.

The body of an agent program is made up of 4 components are identified by unique keyword as is shown in the table below:

moduleLinks an agent class to a Java module.module Console console;
typesDeclares valid formulaetypes eg {
formula isa(string,string);
initialDeclares initial state of the agentinitial state("alive");
initial is("rem", "happy"), !init();
ruleDeclares a plan rulerule +!init() {
planDeclares a partial planplan myplan() {
functionDeclares a teleo-reactive functionfunction myfunction() {
true -> console.println("function")

The module keyword is used to enable Java code to be directly executed from ASTRA code.  Specifically, Java methods can be annotated as one of the following: an action, a term, a formula or a sensor. How the method is invoked depends on the annotation. For example, code that is annotated as an action can be executed as primitive actions. Methods that are annotated as a term can be used wherever a term can be used. Methods that are annotated as a formula can be used in any logical formula. Finally, methods that are annotated as sensors are invoked once at the start of each cycle of the agent interpreter.