• No results found

Multi-Agent Systems. Mehdi Dastani

N/A
N/A
Protected

Academic year: 2021

Share "Multi-Agent Systems. Mehdi Dastani"

Copied!
35
0
0

Loading.... (view fulltext now)

Full text

(1)

Mehdi Dastani

(2)

What is JADE?

„ JADE (Java Agent DEvelopment framework) is a FIPA compliant

agent platform and a Java framework for the development of MAS.

„ The Jade platform is based on a middleware that facilitates the

development 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 the requirements of the context.

„ JADE Project started in July 1998 as joint development of Telecom

Italia Lab and Parma University. JADE is the Leading Open Source

FIPA compliant agent platform.

„ Currently JADE development is driven by a board composed of five

industrial partners:TILAB, Motorola, Whitestein Technologies AG, Profactor GmbH, and France Telecom R&D.

(3)

JADE

„ An agent platform that implements the basic services and infrastructure

of a distributed multi-agent application:

‰ agent life-cycle, agent mobility, and agent security ‰ white & yellow-page services

‰ peer-to-peer message transport & parsing; also multi-party

communication

‰ scheduling of multiple agent tasks

‰ set 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 machines

‰ enables interoperability through FIPA compliance

‰

Two levels concurrency model

„ Inter-agent (pre-emptive, Java threads)

(4)

The architectural model

„ A JADE-based application is composed of a collection of active components

called Agents. Each agent has a unique name.

„ Each agent is a peer since he can communicate in a bidirectional way with all

other agents

„ Each agent lives in a container (that provides its run time) and can migrate

within the platform

(5)

Agent class and names

„ A type of agent is created by extending the jade.core.Agent class

and 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 <local-name>@<platform-name>.

The complete name of an agent must be globally unique. The default platform name is <main-host>:<main-port>/JADE. The platform 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);

(6)

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

(7)

Starting Agent Execution

„

Birth of a new agent

‰

The agent is given an identifier

‰

It is registered with the AMS

‰

It is put in the AP_ACTIVE state

‰

Its setup() method is executed

„

The setup() method is therefore the point where any

‰

application-defined agent activity starts

‰

Initialise the agent

‰

Add tasks using the method addBehaviour()

(8)

The Behaviour

class

„ The actual job that an agent does is typically carried out within

“behaviours”

„ Behaviours are created by extending jade.core.behaviours.Behaviour

class

„ To make an agent execute a task it is sufficient to create an instance of

the corresponding Behaviour subclass and call the addBehaviour() method of the Agent class.

„ Each Behaviour subclass must implement

‰

public void

action

(): what the behaviour actually does

‰

public boolean

done

(): Whether the behaviour is finished

„ An agent can execute several behaviours in parallel, however,

behaviour scheduling is not preemptive, but cooperative and everything occurs within a single Java Thread

„ Behaviour switch occurs only when the action() method of the currently

(9)
(10)

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.... !

(11)

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

(12)

Behaviour

types

„

“One shot” behaviours.

„

“Cyclic” behaviours.

„

“Complex” behaviours.

„

WakerBehaviour

‰ The action() and done() method are already implemented so that

the

handleElapsedTimeout

() method (to be implemented by subclasses) is executed after a given timeout

‰ After that execution the behaviour completes.

„

TickerBehaviour

‰ The action() and done() method are already implemented so that

the onTick() (to be implemented by subclasses) method is executed periodically with a given period

(13)

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.

(14)

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.

(15)

Stopping Agent Execution

„

Any behaviour can call the Agent.doDelete() method

in order to stop agent execution.

‰

The Agent.takeDown() method is executed when the agent

is going to be destroyed

„ The agent is still registered with the AMS and can therefore

send messages to other agents

„ The takeDown() method can be overridden to implement any

necessary cleanup.

„

Just after the takeDown() method is completed, the

agent will be de-registered and its thread destroyed

(16)
(17)

More about behaviours

„

The

onStart

() method of the Behaviour class is

invoked only once before the first execution of the

action() method.

„

The

onEnd

() method of the Behaviour class is invoked

only once after the done() method returns true.

„

The

removeBehaviour

() method of the Agent class can

be used to remove a behaviour from the agent pool of

behaviours. The onEnd() method is not called.

„

When the pool of active behaviours of an agent is

empty, the agent enters the

IDLE

state and its thread

goes to sleep

(18)

ACLMessage

„

Based on asynchronous

message passing

„

Message format defined by the ACL language (FIPA)

„

Messages exchanged by agents are instances of the

jade.lang.acl.ACLMessage

„

Sending a message = creating an ACLMessage object and

calling the

send

() method of the Agent class

„

Reading messages from the private message queue is

accomplished through the

receive

() method

„

Provide accessor methods to get and set all the fields defined

by the ACL language :

get/setPerformative(), get/setSender(),

add/getAllReceiver(), get/setLanguage(), get/setOntology(),

get/setContent()

(19)

Blocking or selecting

„

The

block

() method of the Behaviour class removes a behaviour

from the agent pool of behaviours and puts it in a blocked state.

Each time a message is received all blocked behaviours are

inserted back in the agent pool and have a chance to read and

process the message.

„

It is possible to read only messages with certain characteristics

specifying a jade.lang.acl.MessageTemplate parameter in the

receive

() method.

„

The Agent class also provides the

blockingReceive

() method;

there are overloaded versions that accept a MessageTemplate

and/or a timeout.

(20)

Blocking or selecting

public void action() {

ACLMessage msg = myAgent.receive(); if (msg != null) {

// Message received. Process it ... } else { block(); } }

(21)

FIPA ACL Message Elements

„

p e r f o r m a t i v e

What action the message performs

„

s e n d e r

Initiator of the message

„

r e c e i v e r

Recipient of the message

„

r e p l y - t o

Recipient of the message reply

„

c o n t e n t

Content of the message

„

l a n g u a g e

Language used to express content

„

e n c o d i n g

Encoding used for content

„

o n t o l o g y

Ontology context for content

„

p r o t o c o l

Protocol message belongs to

„

c o n v e r s a t i o n - i d

Conversation message belongs to

„

r e p l y - w i t h

Reply with this expression

„

i n - r e p l y - t o

Action to which this is a reply

„

r e p l y - b y

Time to receive reply by

(22)

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 Objects ‰ FIPA-SL, FIPA-CCL, FIPA-RDF, FIPA-KIF

(23)

Sending/receiving Message

ACLMessage 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(); }

(24)
(25)

Interacting with the DF Agent

„

The DF is an agent, it communicates using ACL

„

The ontology and language that the DF “understands”

are specified by FIPA

„

The jade.domain.DFService class provides static utility

methods that facilitate the interactions with the DF

‰

register();

‰

modify();

‰

deregister();

‰

search();

(26)

DFDescription

format

„

When an agent registers with the DF it must provide

a description

‰

The agent AID

‰

A 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 must

be known to exploit the service

„ A collection of service-specific properties in the form key-value

pair

„

When an agent searches/subscribes to the DF it

must specify another DFAgentDescription that is

used as a template

(27)

Interacting with the DF Agent

protected 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); …

(28)

Agent Management System

„

The

authority

in a JADE platform; all platform

management actions (creating/killing agents,

killing containers...)

„

Other agents can request the AMS to perform

these actions by using

‰

The

fipa-request

interaction protocol

‰

The

SL

language

‰

The

JADE-Management

ontology and related

actions

(29)
(30)

The main graphical tools of JADE

„

Management, control, monitoring, and

debugging of a multi-agent platform

‰

RMA (Remote Monitoring Agent)

‰

Dummy Agent

‰

Sniffer Agent

‰

Introspector Agent

‰

Log Manager Agent

(31)
(32)
(33)
(34)
(35)

Advantages

„

No need to implement the Agent Platform

‰ AMS, DF executed at start-up

„

No need to implement agent-management ontology and

functionalities

‰ An agent is registered with the Agent Platform within its

constructor, it is given a name and an address

‰ The DFService class provides a simplified interface to access the

services of the DF (registration, searching, lease-renewal, …)

„

No need to implement Message Transport and Parsing

‰ Automatically (and possibly efficiently) done by the framework

when sending/receiving messages

„

Interaction Protocols must only be extended via handle methods

„

Standard FIPA !

References

Related documents