Using the ASTRA IDE to write an Agent Program

Step 1: Creating an ASTRA Project

To write an ASTRA program, you need to install the ASTRA Eclipse Plugin. Once you have the plugin installed, you should select “File→New→ASTRA Project…” and enter a name for the project (here enter “HelloWorld”) and click “Finish” to create the project.

NewProject

Step 2: Writing an ASTRA Program

To write a program, you need to first create an ASTRA file by selecting “File→New→ASTRA Class” and then entering a name for the class (here, enter “HelloWorld” as the agent class name) and click “Finish” to create the ASTRA file.

NewClass

Now, copy the program below into the editor:

agent HelloWorld {
    module Console console;
    
    // Adopt an intial goal to trigger the rule
    initial !init();
    
    // A rule that is triggered whenever an !init() goal is adopted
    rule +!init() {
        // This line invokes the println(...) action in the console API.
        console.println("Hello World");
    }
}

This program prints the text “Hello World” to the console once. Notice that the agent keyword declares that the file contains an agent program and that the name of the agent program is “helloworld”. ASTRA uses this line to check that the program is written in a file named “HelloWorld.astra”. If it is not, then an error is reported.

When you have copied the file in to the editor, save it. When you save the file, Eclipse will automatically compile the code and report any errors.

Program

Step 3: Running an ASTRA Agent Program

To run an ASTRA program, all you need to do is right-click over the program, select “Run As…” and then click on “ASTRA Agent”

The name of the agent created when you run it is “main”. This agent can itself be used to create other additional agents as is required.