8/2/2019 Jade Slides
1/35
Mehdi Dastani
Multi-Agent Systems
8/2/2019 Jade Slides
2/35
What is JADE?JADE (Java Agent DEvelopment framework) is a FIPA compliantagent platform and a Java framework for the development of MAS.
The Jade platform is based on a middleware that facilitates thedevelopment of distributed multi-agent applications based on a peer-to-peer communication architecture.
The environment can evolve dynamically with agents that appear
and disappear in the system according to the needs and therequirements of the context.
JADE Project started in July 1998 as joint development of TelecomItalia Lab and Parma University. JADE is the Leading Open SourceFIPA compliant agent platform.
Currently JADE development is driven by a board composed of fiveindustrial partners:TILAB, Motorola, Whitestein Technologies AG,
Profactor GmbH, and France Telecom R&D.
8/2/2019 Jade Slides
3/35
JADEAn agent platform that implements the basic services and infrastructureof a distributed multi-agent application:
agent life-cycle, agent mobility, and agent securitywhite & yellow-page services
peer-to-peer message transport & parsing ; also multi-partycommunicationscheduling of multiple agent tasksset of graphical tools to support monitoring, logging, and debugging
Some relevant features:Distributed Agent Platform
seen as a whole from the outside world
spanning multiple machinesenables interoperability through FIPA complianceTwo levels concurrency model
Inter-agent (pre-emptive, Java threads)
Intra-agent (co-operative, Behaviour classes)
8/2/2019 Jade Slides
4/35
The architectural modelA JADE-based application is composed of a collection of active componentscalled Agents. Each agent has a unique name .
Each agent is a peer since he can communicate in a bidirectional way with allother agents
Each agent lives in a container (that provides its run time) and can migratewithin the platform
One container plays the role of main (where AMS, DF live)
8/2/2019 Jade Slides
5/35
Agent class and namesA type of agent is created by extending the jade.core.Agent classand redefining the setup() method.
Each Agent instance is identified by an AID (jade.core.AID),composed of a unique name plus some addresses; the getAID()method of the Agent class
Agent names are of the form @ .The complete name of an agent must be globally unique. Thedefault platform name is :/JADE . Theplatform name can be set using the name option
Within a single JADE platform agents are referred through their
names only.Given the name of an agent its AID can be created as
AID id = new AID(localname, AID.ISLOCALNAME);
AID id = new AID(name, AID.ISGUID);
8/2/2019 Jade Slides
6/35
import jade.core.Agent ;
public class HelloAgent extends Agent{
protected void setup (){
System.out.println("Hello World. ");System.out.println("My name is "+ getLocalName ());
}}
$> javac HelloAgent.java $> java jade.Boot fred:HelloAgent
This is JADE 3.0b1 .Hello World.
My name is fred
Hello World: A Simple Example
8/2/2019 Jade Slides
7/35
Starting Agent ExecutionBirth of a new agent
The agent is given an identifier
It is registered with the AMSIt is put in the AP_ACTIVE stateIts setup() method is executed
The setup() method is therefore the point where anyapplication-defined agent activity starts
Initialise the agentAdd tasks using the method addBehaviour()
Scheduled as soon as the setup() method ends
8/2/2019 Jade Slides
8/35
The Behaviour classThe actual job that an agent does is typically carried out withinbehavioursBehaviours are created by extending jade.core.behaviours.BehaviourclassTo make an agent execute a task it is sufficient to create an instance ofthe corresponding Behaviour subclass and call the addBehaviour ()method of the Agent class.
Each Behaviour subclass must implementpublic void action (): what the behaviour actually doespublic boolean done (): Whether the behaviour is finished
An agent can execute several behaviours in parallel, however,behaviour scheduling is not preemptive , but cooperative andeverything occurs within a single Java ThreadBehaviour switch occurs only when the action() method of the currentlyscheduled behaviour returns.
8/2/2019 Jade Slides
9/35
8/2/2019 Jade Slides
10/35
import jade.core. Agent ;import jade.core. behaviours.* ;
public class myAgent extends Agent {
protected void setup () { addBehaviour ( new myBehaviour ( this ) ); }
class myBehaviour extends SimpleBehaviour {public void action () { //... the real programming !! }private boolean finished = false;public boolean done () { return finished; }} // ----------- End myBehaviour
} //end class myAgent
Hello World! My name is fred Hello World! My name is fred Hello World! My name is fred Hello World! My name is fred ..... loops until stopped with CTL-C.... !
Hello World: A Simple Example
8/2/2019 Jade Slides
11/35
import jade.core. Agent ;import jade.core. behaviours.* ;
public class myAgent extends Agent {
protected void setup () { addBehaviour ( new myBehaviour ( this ) ); }
class myBehaviour extends SimpleBehaviour {int n=0;public void action () { ; n++; }public boolean done () { return n>=3; }
} // ----------- End myBehaviour
} //end class myAgent
Hello World! My name is fred Hello World! My name is fred
Hello World! My name is fred
Hello World: A Simple Example
8/2/2019 Jade Slides
12/35
8/2/2019 Jade Slides
13/35
public class MyAgent extends Agent {protected void setup() {
System.out.println(Adding waker behaviour);addBehaviour(new WakerBehaviour(this, 10000) {
protected void handleElapsedTimeout() { // perform operation X
}
} );}
}
Operation X is performed 10 seconds after the Adding waker behaviour printout appears.
WakerBehaviour: A Simple Example
8/2/2019 Jade Slides
14/35
public class tickeragent extends Agent { Behaviour loop;
protected void setup() { loop = new TickerBehaviour( this, 10000 ) {
protected void onTick() { // perform operation X
} }; addBehaviour( loop );
}
}
Operation X is performed periodically every 10 seconds.
TickerBehaviour: A Simple Example
8/2/2019 Jade Slides
15/35
8/2/2019 Jade Slides
16/35
8/2/2019 Jade Slides
17/35
More about behavioursThe onStart () method of the Behaviour class isinvoked only once before the first execution of theaction() method.
The onEnd () method of the Behaviour class is invokedonly once after the done() method returns true.
The removeBehaviour () method of the Agent class canbe used to remove a behaviour from the agent pool ofbehaviours. The onEnd() method is not called.
When the pool of active behaviours of an agent isempty, the agent enters the IDLE state and its thread
goes to sleep
8/2/2019 Jade Slides
18/35
8/2/2019 Jade Slides
19/35
Blocking or selecting
The block () method of the Behaviour class removes a behaviourfrom the agent pool of behaviours and puts it in a blocked state.
Each time a message is received all blocked behaviours areinserted back in the agent pool and have a chance to read andprocess the message.
It is possible to read only messages with certain characteristicsspecifying a jade.lang.acl.MessageTemplate parameter in thereceive () method.
The Agent class also provides the blockingReceive () method;there are overloaded versions that accept a MessageTemplateand/or a timeout.
8/2/2019 Jade Slides
20/35
Blocking or selecting
public void action() {ACLMessage msg = myAgent.receive();if (msg != null) {
// Message received. Process it...
}else {
block();}}
8/2/2019 Jade Slides
21/35
FIPA ACL Message Elements
p e r f o r m a t i v e What action the message performss e n d e r Initiator of the message
r e c e i v e r Recipient of the messager e p l y - t o Recipient of the message replyc o n t e n t Content of the messagel a n g u a g e Language used to express contente n c o d i n g Encoding used for contento n t o l o g y Ontology context for contentp r o t o c o l Protocol message belongs toc o n v e r s a t i o n - i d Conversation message belongs tor e p l y - w i t h Reply with this expressioni n - r e p l y - t o Action to which this is a replyr e p l y - b y Time to receive reply by
8/2/2019 Jade Slides
22/35
ACL Message Example(request:sender (:name [email protected]:8080):receiver (:name rexhotel@tcp://hotelrex.com:6600)
:ontology personal-travel-assistant:language FIPA-SL:protocol fipa-request:content
(action movenpickhotel@tcp://movenpick.com:6600(book-hotel (:arrival 25/11/2000) (:departure 05/12/2000) ...)))
Any language can be used as a Content Language, e.g.:KIF, Prolog, SQL, Serialized Objects, Binary Large ObjectsFIPA-SL, FIPA-CCL, FIPA-RDF, FIPA-KIF
8/2/2019 Jade Slides
23/35
Sending/receiving MessageACLMessage msg = receive(); ACLMessage reply = new ACLMessage( ACLMessage.INFORM ); reply.setContent( "Pong" ); reply.addReceiver( msg.getSender() );
send(reply);
public void action() { ACLMessage msg = receive();
if (msg!=null) { ...; ACLMessage reply = msg.createReply(); reply.setPerformative(ACLMessage.INFORM ); reply.setContent(" Pong" ); reply.send();
}block(); }
8/2/2019 Jade Slides
24/35
DF (Directory Facilitator)
8/2/2019 Jade Slides
25/35
Interacting with the DF Agent
The DF is an agent, it communicates using ACLThe ontology and language that the DF understandsare specified by FIPAThe jade.domain.DFService class provides static utility
methods that facilitate the interactions with the DFregister();modify();
deregister();search();
The JADE DF also supports a subscription mechanism
8/2/2019 Jade Slides
26/35
DFDescription
formatWhen an agent registers with the DF it must providea description
The agent AIDA collection of service descriptions (class
ServiceDescription):The service type (e.g. Weather forecast)The service name (e.g. Meteo-1)The languages, ontologies and interaction protocols that mustbe known to exploit the serviceA collection of service-specific properties in the form key-valuepair
When an agent searches/subscribes to the DF itmust specify another DFAgentDescription that isused as a template
8/2/2019 Jade Slides
27/35
Interacting with the DF Agentprotected void setup() {
...DFAgentDescription dfd = new DFAgentDescription();dfd.setName(getAID());
ServiceDescription sd = new ServiceDescription();sd.setType(book-selling);sd.setName(JADE-book-trading);dfd.addServices(sd);DFService.register(this, dfd);...
}
protected void takeDown() {DFService.deregister(this);
}
8/2/2019 Jade Slides
28/35
Agent Management System
The authority in a JADE platform; all platformmanagement actions (creating/killing agents,
killing containers...)Other agents can request the AMS to performthese actions by using
The fipa-request interaction protocolThe SL languageThe JADE-Management ontology and relatedactions
getAMS () => the AID of the AMS
8/2/2019 Jade Slides
29/35
8/2/2019 Jade Slides
30/35
The main graphical tools of JADE
Management, control, monitoring, and
debugging of a multi-agent platformRMA (Remote Monitoring Agent)Dummy AgentSniffer AgentIntrospector Agent
Log Manager AgentDF (Directory Facilitator) GUI
8/2/2019 Jade Slides
31/35
8/2/2019 Jade Slides
32/35
8/2/2019 Jade Slides
33/35
8/2/2019 Jade Slides
34/35
8/2/2019 Jade Slides
35/35
AdvantagesNo need to implement the Agent Platform
AMS, DF executed at start-upNo need to implement agent-management ontology and
functionalitiesAn agent is registered with the Agent Platform within itsconstructor, it is given a name and an addressThe DFService class provides a simplified interface to access theservices of the DF (registration, searching, lease-renewal, )
No need to implement Message Transport and ParsingAutomatically (and possibly efficiently) done by the framework
when sending/receiving messagesInteraction Protocols must only be extended via handle methodsStandard FIPA !