AgentSpeak(L) Example: Hello World

As a first example of AgentSpeak(L) we present the basic hello world program.  This program consists of two statements: an initial goal (line 01) and a plan rule (lines 03-04). As can be seen, statements are terminated by a period (,).  The first statement declares a goal, !init().  This goal results in a goal adoption event being added to the agents event queue.  This is only done once before the first iteration of the interpreter.  The second statement is a plan rule.  This rule is designed to handle the goal adoption event generated by the first statement.  To specify a goal adoption event, the goal is simply prefixed by a + operator.  The arrow (<-) operator is used to separate the triggering event from the behaviour implementation (which is on line 04).  The behaviour contains a single plan operator – a private action that prints out the argument to the console.

01 !init().
02 
03 +!init() <-
04     println(hello world).

In terms of execution: on the first iteration, the interpreter selects the +!init() event; matches this event to the rule; and creates an intention to execute the behaviour associated with the rule.  Next, the interpreter selects this newly created intention and executes the next step, which in this case involves “hello world” being printed out (this is an example of a private action). Upon completion of the step, the intention is marked as completed, and dropped.  The agent continues to execute, but it never generates another event. This means that it never adopts another intention, which in turn means that the program does nothing more.