Example 00 – Hello World


This first example is the classic hello world. It is composed by a single agent executing a println action to print on the console the message. The Jason MAS configuration file hello-world is the following:

MAS hello_world {
  environment:
  c4jason.CartagoEnvironment

  agents:
  hello_agent agentArchClass c4jason.CAgentArch;

  classpath: "../../../../lib/cartago.jar";
             "../../../../lib/c4jason.jar";
}

The declarations environment: c4jason.CartagoEnvironment and agentArchClass c4jason.CAgentArch are fixed, and specify that the MAS will exploit CArtAgO environments and that agents need to have a proper predefined architecture to work within such environment. The classpath declaration is needed to include CArtAgO library (cartago.jar) and the specific Jason bridge (c4jason.jar) in the classpath. The program spawns a single agent (hello_agent) whose task is to print on standard output the classic hello message. For that purpose it exploits the println operation provided by the console artifact.

Source code of the hello_agent (in hello_agent.asl):

!hello.

+!hello : true
  <- .my_name(Name);
     println("Hello, world! by ",Name).

Highlights:

  • By default an agent, when booting, joins the default workspace on current node – this can be avoided or controlled by specifying further parameters to the environment: c4jason.CartagoEnvironment declaration (see later).
  • println is an operation provided by the console artifact, which is available by default in the default workspace: so the agent external action println is mapped onto the operation of this artifact. This is the case of operation execution without specifying the specific target artifact.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>