Agent Oriented Programming

Practical work using the Jason Language within JaCaMo

Introduction

The Jason (Java-based interpreter for an extended version of AgentSpeak) can be dowloaded from: http://jason.sourceforge.net/. It is part of the JaCaMo Platform that you installed in the previous step (cf. Introduction). In this part of the practical work, we will use the Eclipse IDE with the JaCaMo plugin.

Note

  • Let's note that you can also use the JEDIT IDE which is distributed with Jason with a dedicated plugin (see http://jason.sourceforge.net).

First steps in Jason

In this section we will create a new and simple example where two agents, bob and tom, exchange greeting messages.

a. Create a first two agents system

  • Create a new JaCaMo project titled greeting, where the agent execution environment is Centralised and the Environment is Centralised.
  • Rename the sample_agent in the greeting.jcm and in the src/asl directory into bob
  • Create a new agent tom in the project. As you can see, there is a skeleton for the agent's code: the agent has no beliefs, but an initial goal and one plan to achieve this goal. The plan simply prints something when triggered.
  • Add tom to the project greeting.
  • In bob's code, remove the start goal (and its related plan), leaving its program empty.
  • Change tom's code so that it sends a ``hello'' message to bob. To send messages, an internal action called .send is used:
// Agent tom in project greeting
{ include("common_cartago.asl") }
{ include("common_moise.asl") }

/* Initial beliefs and rules */

/* Initial goals */
!start.

/* Plans */
+!start : true <- .send(bob,tell,hello).
// Agent bob in project greeting

{ include("common-cartago.asl") }
{ include("common-moise.asl") }

/* Initial beliefs and rules */

/* Initial goals */

/* Plans */
  • You can now run the project. There is no output!
  • However, in the MAS Console, click on the debug button and then select, in a new windows named ``Mind Inspector'', the agent bob (if the agent's list is empty, click once in the run button).
  • Note that bob has a belief hello[source(tom)], which means that it received tom's message.

b. Make bob reacting to the message

  • Since the received message implies a belief addition, an event like +hello[source(tom)] is produced and may trigger the execution of the plan below.
  • Note that, in the plan, A is a variable that contains the name of the sender. In AgentSpeak, as in Prolog, identifiers that start with uppercase letters are variables.
// Agent bob in project greeting

+hello[source(A)] <- .print("I received a 'hello' from ",A).

c. Make bob being polite by replying to the message

  • Since bob is a polite agent, it replies and send a hello back to tom
  • Tom does the same
  • Before running the system, think what you would expect to happen. Perhaps the agents will enter a kind of greeting loop? Explain why you get this kind of behaviour.
// Agent bob in project greeting

+hello[source(A)] <- .print("I received a 'hello' from ",A);
                     .send(A,tell,hello).

// Agent tom in project greeting
...
+hello[source(A)] <- .print("I received a 'hello' from ",A);
                     .send(A,tell,hello).

d. Add other extensions

  • Create another agent called "alice" who sends "bonjour" to bob ;
  • Change "bob"'s code so that as soon as he receives a message, he replies to the sender with the same content ;
  • Change the code of the agents "bob" and "alice" so that they fall into an infinite loop of message exchanges.

Gold Miners Tutorial

Do Part I and II & V of the tutorial

  • Realise the tutorial which is available here

Note

The list of all available standard actions are described in the jason.stdlib package described in the standard documentation (available here)


Olivier Boissier, November 2014