+ All Categories
Home > Documents > Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial...

Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial...

Date post: 21-Dec-2015
Category:
View: 222 times
Download: 0 times
Share this document with a friend
118
Programming Agents with JADE for Multi- Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation
Transcript
Page 1: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Programming Agents with JADE for Multi-Agent Systems

Collected by Anton Naumenko

Industrial Ontologies Group

Based on Jade, Java and Eclipse documentation

Page 2: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Content

Briefly about components JADE overview Setting up the Development Environment

Installing JADE Running demo

Installing Eclipse Setting Eclipse to work with JADE

Book Trading example

Page 3: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Components, Java

Java technology is a portfolio of products that are based on the power of networks and the idea that the same software should run on many different kinds of systems and devices.

The Java programming language lets you write powerful, enterprise-worthy programs that run in the browser, from the desktop, on a server, or on a consumer device.

http://java.sun.com/

Page 4: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Components, Eclipse

Eclipse is an open source community whose projects are focused on providing an extensible development platform and application frameworks for building software

Eclipse provides extensible tools and frameworks that span the software development lifecycle, including support for modeling, language development environments for Java, C/C++ and others, testing and performance, business intelligence, rich client applications and embedded development

http://www.eclipse.org/

Page 5: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Components, JADE

JADE (Java Agent DEvelopment Framework) is a software framework fully implemented in Java language.

It simplifies the implementation of multi-agent systems through a middle-ware that claims to comply with the FIPA specifications and through a set of tools that supports the debugging and deployment phase.

http://jade.tilab.com/

Page 6: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

JADE overview

JADE is a middleware that facilitates the development of multi-agent systems. It includes

A runtime environment where JADE agents can “live” and that must be active on a given host before one or more agents can be executed on that host.

A library of classes that programmers have to/can use (directly or by specializing them) to develop their agents.

A suite of graphical tools that allows administrating and monitoring the activity of running agents.

Page 7: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Containers and Platforms

Each running instance of the JADE runtime environment is called a Container as it can contain several agents.

The set of active containers is called a Platform.

A single special Main container must always be active in a platform and all other containers register with it as soon as they start.

See JADE Administrative Tutorial

Page 8: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

AMS

The AMS (Agent Management System) that provides the naming service (i.e. ensures that each agent

in the platform has a unique name) represents the authority in the platform (for

instance it is possible to create/kill agents on remote containers by requesting that to the AMS).

Page 9: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

DF

The DF (Directory Facilitator) that provides a Yellow Pages service by means of which an agent can find other agents providing the services he requires in order to achieve his goals.

Page 10: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Sample architecture

Page 11: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

JADE Requirements

The only software requirement to execute the system is the Java Run Time Environment version 1.4

Page 12: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Getting JADE

All the software is distributed under the LGPL license limitations and it can be downloaded from the JADE web site http://jade.tilab.com/. Five compressed files are available:

The source code of JADE The source code of the examples The documentation, including the javadoc of the

JADE API and this programmer's guide The binary of JADE, i.e. the jar files with all the Java

classes A full distribution with all the previous files

Page 13: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Installing JADE

Download full distribution of JADE Extract JADE-all-3[1].2.zip

Result is

Extract JADE-bin-3.2.zip and JADE-doc-3.2.zip to a folder of your choice for the development

Page 14: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Test JADE. Run demo

Your folder\jade\demo

See MeetingSchedule.html for description Run runDemo.bat to check it out

Page 15: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo coverage

the registration of an agent with the default DF the registration of an agent with a remote DF

belonging to another platform or, different from the default DF

the search within the known DFs for a list of agents and their properties, in particular the list of MeetingScheduler agents and the name of the user that they represent

the usage of the FipaContractNet protocol, both the initiator and responder role

Page 16: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo

When the two agents start, two login windows appears.

Click OK button without passwords

Page 17: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. RMA agent

Remote Agent Management GUI

Page 18: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Appointment Scheduler

Page 19: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Fixing appointments of Tizio Then, use the calendar window of Tizio to fix

a couple of appointments in different dates with different descriptions.

Tizio has fixed two appointments for the 1st and the 2nd

Page 20: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Fixing appointments of Tizio 1st is meeting with

John

Page 21: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Fixing appointments of Tizio 2nd is meeting with

Jerry

Page 22: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Update known persons Switch then to the calendar

window of Caio. From the directory menu,

execute the item "Update known persons with the facilitator" such that Caio comes to know about Tizio existence.

Page 23: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Fix appointment of Caio and Tizio Use the calendar

window of Caio to fix an appointment with Tizio between 1st and 4th.

Page 24: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Result of negotiation The ContractNet protocol should be then

executed and both agents should converge to the date 3rd.

Page 25: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Sniffer agent

Page 26: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Update of known persons

Page 27: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Request and Inform

Page 28: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Demo. Sniffer’s tracks of communication

Page 29: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Eclipse Requirements

You will need a Java runtime environment (JRE) to use Eclipse.

Page 30: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Getting Eclipse

download the Eclipse SDK http://www.eclipse.org/downloads/index.php

Page 31: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Installing Eclipse

Extract eclipse-SDK-3.1-win32.zip to the folder of your choice

Page 32: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Running Eclipse

Run eclipse.exe

Page 33: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Running Eclipse. Workspace

Set arbitrary folder for the workspace

Page 34: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Running Eclipse. Close Welcome view Close the welcome view

Page 35: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Running Eclipse If you see this then you are ready

Page 36: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Creating a project in Eclipse

Page 37: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Creating a java project in Eclipse

Page 38: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Adding JADE libs to the project

Page 39: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Adding JADE libs to the project

Page 40: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Development Environment is ready

Page 41: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Testing Settings. Create TestAgent

Page 42: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Create TestAgent

Page 43: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

TestAgent is created

Page 44: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Method setup() to run TestAgent

The setup() method is intended to include agent initializations.

Page 45: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Override method setup()

Page 46: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Result of overriding

Page 47: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Print Hello message

Page 48: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Running JADE and TestAgent

Page 49: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Create JADE configuration to run

Page 50: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Create JADE configuration to run

Page 51: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Create JADE configuration to run

Page 52: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Create JADE configuration to run

Page 53: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Create JADE configuration to run

Page 54: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Result of Test

Page 55: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Book Trading Example

It shows how to create simple JADE agents and how to make them executing tasks and communicate between each other.

Some agents selling books and other agents buying books on behalf of their users.

Page 56: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Buyer Agent

Receives the title of the book to buy (the “target book”) as a command line argument

Periodically requests all known seller agents to provide an offer

As soon as an offer is received the buyer agent accepts it and issues a purchase order

If more than one seller agent provides an offer the buyer agent accepts the best one (lowest price)

Having bought the target book the buyer agent terminates

Page 57: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Seller Agent

Has a minimal GUI by means of which the user can insert new titles

Continuously wait for requests from buyer agents When asked to provide an offer for a book they

check if the requested book is in their catalogue and in this case reply with the price. Otherwise they refuse.

When they receive a purchase order they serve it and remove the requested book from their catalogue

Page 58: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

setup() method

The setup() method is intended to include agent initializations.

Page 59: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Agent identifiers

Each agent is identified by an “agent identifier” represented as an instance of the jade.core.AID class.

The getAID() method of the Agent class allows retrieving the agent identifier.

An AID object includes a globally unique name plus a number of addresses.

<nickname>@<platform-name>

Page 60: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Assigning name

String nickname = “Peter”;AID id = new AID(nickname, AID.ISLOCALNAME);

The ISLOCALNAME constant indicates that the first parameter represents the nickname (local to the platform) and not the globally unique name of the agent.

Page 61: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Running JADE

The first part of the above output is the JADE disclaimer

The indication that a container called “Main-Container” is ready completes the JADE runtime startup.

When the JADE runtime is up our agent is started and prints its welcome message

The platform name “arman:1099/JADE” is automatically assigned on the basis of the host and port we are running JADE on

Page 62: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Agent termination

Even if it does not have anything else to do after printing the welcome message, our agent is still running.

In order to make it terminate its doDelete() method must be called.

The takeDown() method is invoked just before an agent terminates and is intended to include agent clean-up operations.

Page 63: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

doDelete() and takeDown()

Page 64: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Passing arguments to an agent Agents may get start-up arguments specified

on the command line. These arguments can be retrieved, as an

array of Object, by means of the getArguments() method of the Agent class.

We want our BookBuyerAgent to get the title of the book to buy as a command line argument.

Page 65: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Taking target book as argument

Page 66: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Passing book title

Page 67: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Trying to buy …

Page 68: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Agent Tasks

The actual job an agent has to do is typically carried out within “behaviours”

A behaviour is implemented as an object of a class that extends jade.core.behaviours.Behaviour.

Page 69: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Behaviour

In order to make an agent execute the task implemented by a behaviour object it is sufficient to add the behaviour to the agent by means of the addBehaviour() method of the Agent class.

Behaviours can be added at any time: when an agent starts (in the setup() method) or from within other behaviours.

Page 70: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

action() and done() methods

Each class extending Behaviour must implement the action() method actually defines the

operations to be performed when the behaviour is in execution

the done() method (returns a boolean value), that specifies whether or not a behaviour has completed and have to be removed from the pool of behaviours of an agent

Page 71: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Behaviours scheduling and execution An agent can execute several behaviours

concurrently. It is important to notice that scheduling of

behaviours in an agent is not pre-emptive (as for Java threads) but cooperative.

This means that when a behaviour is scheduled for execution its action() method is called and runs until it returns.

Therefore it is the programmer who defines when an agent switches from the execution of a behaviour to the execution of the next one.

Page 72: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.
Page 73: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Overbearing Behaviour

A behaviour prevents any other behaviour to be executed since its action() method never returns.

Page 74: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

No Behaviours

When there are no behaviours available for execution the agent’s thread goes to sleep in order not to consume CPU time.

It is waken up as soon as there is again a behaviour available for execution.

Page 75: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

One-shot behaviours

Complete immediately and action() method is executed only once.

The jade.core.behaviours.OneShotBehaviour already implements the done() method by returning true and can be conveniently extended to implement one-shot behaviours.

Page 76: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Cyclic behaviours

Never complete and action() method executes each time it is called.

The jade.core.behaviours.CyclicBehaviour already implements the done() method by returning false and can be conveniently extended to implement cyclic behaviours.

Page 77: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Generic behaviours Generic behaviours that embeds a status and

execute different operations depending on that status. They complete when a given condition is met.

Page 78: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Complex Behaviours

JADE provides the possibility of combining simple behaviours together to create complex behaviours.

This feature is outside the scope. Refer to the Javadoc of the

SequentialBehaviour, ParallelBehaviour and FSMBehaviour for the details.

Page 79: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Scheduling operations

JADE provides two ready-made classes (in the jade.core.behaviours package) by means of which it is possible to easily implement behaviours that execute certain operations at given points in time.

Page 80: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Waker Behaviour

action() and done() methods are already implemented in such a way to execute the handleElapsedTimeout() abstract method after a given timeout (specified in the constructor) expires.

After the execution of the handleElapsedTimeout() method the behaviour completes.

Page 81: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Waker Behaviour

Page 82: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Ticker Behaviour

action() and done() methods are already implemented in such a way to execute the onTick() abstract method repetitively waiting a given period (specified in the constructor) after each execution.

A TickerBehaviour never completes.

Page 83: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Book-buyer agent behaviours

Book-buyer agent periodically requests seller agents the book it was instructed to buy.

We can easily achieve that by using a TickerBehaviour that, on each tick, adds another behaviour that actually deals with the request to seller agents.

Page 84: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

TickerBehaviour

Page 85: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Book-seller agent behaviours

Book-seller agent waits for requests from buyer agents and serves them requests to provide an offer for a book purchase orders

two cyclic behaviours: one dedicated to serve requests for offer the other dedicated to serve purchase orders a one-shot behaviour updating the catalogue of

books

Page 86: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Result

Page 87: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Agent Communication

The communication paradigm adopted is the asynchronous message passing.

Each agent has a sort of mailbox (the agent message queue) where the JADE runtime posts messages.

Whenever a message is posted in the message queue the receiving agent is notified.

If and when the agent actually picks up the message from the message queue is completely up to the programmer.

Page 88: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Messaging

Page 89: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

ACL language

Messages exchanged by JADE agents have a format specified by the ACL language defined by the FIPA (http://www.fipa.org) international standard for agent interoperability.

Page 90: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Message Fields

The sender of the message The list of receivers The performative The content The content language i.e. the syntax used to

express the content The ontology i.e. the vocabulary of the symbols

used in the content and their meaning Some fields used to control several concurrent

conversations and to specify timeouts for receiving a reply such as conversation-id, reply-with, in-reply-to, reply-by.

Page 91: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Performative

The communicative intention (also called “performative”) indicating what the sender intends to achieve by sending the message.

The performative can be REQUEST, if the sender wants the receiver to perform an action, INFORM, if the sender wants the receiver to be aware a fact, QUERY_IF, if the sender wants to know whether or not a given

condition holds, CFP (call for proposal), PROPOSE, ACCEPT_PROPOSAL, REJECT_PROPOSAL, and more.

Page 92: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Message in JADE

A message in JADE is implemented as an object of the jade.lang.acl.ACLMessage class

It provides get and set methods for handling all fields of a message

After filling the fields of an ACLMessage object

Call the send() method of the Agent class

Page 93: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Message Example

Page 94: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Messages of scenario

CFP to request an offer for a book PROPOSE for messages carrying seller

offers ACCEPT_PROPOSAL for messages

carrying offer acceptance REFUSE for messages sent by seller agents

when the requested book is not in their catalogue

Page 95: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Messages of scenario

In both types of messages sent by buyer agents we assume that the message content is the title of the book.

The content of PROPOSE messages will be the price of the book.

Page 96: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

CFP message

Page 97: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Receiving messages

An agent can pick up messages by means of the receive() method.

This method returns the first message in the message queue

(removing it) null if the message queue is empty

Page 98: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Seller behaviours

Behaviours that process messages received by other agents

the case for the OfferRequestsServer and PurchaseOrdersServer behaviours

behaviour must be continuously running must check if a message has been received

and process it The two behaviours are very similar

Page 99: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

OfferRequestsServer behaviour The behaviour used by Book-seller agents to

serve incoming requests for offer from buyer agents

If the requested book is in the local catalogue the seller agent replies with a PROPOSE

message specifying the price otherwise

a REFUSE message is sent back

Page 100: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.
Page 101: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

createReply() method

The createReply() method of the ACLMessage class automatically creates a new ACLMessage properly setting the receivers and all the fields used to control the conversation conversation-id reply-with in-reply-to

Page 102: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Blocking of behaviour

When we add the above behaviour, the agent’s thread starts a continuous loop

To avoid that we would like to execute the action() method only when a new message is received

We can use the block() method of the Behaviour class

Page 103: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Right approach

The code is the typical (and strongly suggested) pattern for receiving messages inside a behaviour

Page 104: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Selecting messages with given characteristics from the message queue How can we be sure that the

OfferRequestsServer behaviour picks up from the agent’s message queue only messages carrying requests for offer and the PurchaseOrdersServer behaviour only messages carrying purchase orders?

Specifying proper “templates” when we call the receive() method we solve the problem

Page 105: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Message Template

Such templates are implemented as instances of the jade.lang.acl.MessageTemplate class that provides a number of factory methods to create templates in a very simple and flexible way

Page 106: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Adding templates

We modify the action() method of the OfferRequestsServer so that the call to myAgent.receive() ignores all messages except those whose performative is CFP

Page 107: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Complex conversations

The RequestPerformer behaviour represents an example of a behaviour carrying out a “complex” conversation

A conversation is a sequence of messages exchanged by two or more agents with well defined causal and temporal relations

Page 108: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

RequestPerformer behaviour

Buyer has to send a CFP message to several agents get back all the replies in case at least one PROPOSE reply is received,

send a further ACCEPT_PROPOSAL message get back the response

Page 109: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Yellow Pages Service

We have assumed that there is a fixed set of seller agents (seller1 and seller2)

Each buyer agent already knows them How to get rid of this assumption? Exploit the yellow pages service provided by

the JADE platform Make buyer agents dynamically discover

seller agents available at a given point in time

Page 110: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

The DF agent

A “yellow pages” service allows agents to publish one or more services they provide so that other agents can find and successively exploit them

The yellow pages service in JADE is an agent called DF (Directory Facilitator)

Each FIPA compliant platform hosts a default DF agent

Other DF agents can be activated and several DF agents can be federated so that to provide a single distributed yellow pages catalogue

Page 111: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Example

Page 112: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Interacting with the DF

it is possible to interact with DF as usual by exchanging ACL messages using a proper content language (the SL0 language) and a proper ontology (the FIPA-agent-management ontology)

In order to simplify these interactions, however JADE provides the jade.domain.DFService class by means of which it is possible to publish and search for services through method calls

Page 113: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Publishing services

An agent must provide the DF with a description including its AID, possibly the list of languages and ontologies that other agents need to know to interact with it and the list of published services

For each published service a description is provided including the service type, the service name, the languages and ontologies required to exploit that service and a number of servicespecific properties

The DFAgentDescription, ServiceDescription and Property classes, included in the jade.domain.FIPAAgentManagement package, represent the three mentioned abstractions

Page 114: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

To publish a book selling service An agent must create a proper description

and call the DFService.register()

Page 115: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

De-registration

When an agent terminates it is a good practice to de-register published services

Page 116: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Searching for services

An agent wishing to search for services must provide the DF with a template description

The result of the search is the list of all the descriptions that match the provided template

A description matches the template if all the fields specified in the template are present in the description with the same values

The search() static method of the DFService class can be used

Page 117: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

Update the list of seller agents

Page 118: Programming Agents with JADE for Multi-Agent Systems Collected by Anton Naumenko Industrial Ontologies Group Based on Jade, Java and Eclipse documentation.

DF subscription

Note that the update of the list of known seller agents is done before each attempt to buy the target book since seller agents may dynamically appear and disappear in the system

The DFService class also provides support for subscribing to the DF to be notified as soon as an agent publishes a given service (see the searchUntilFound() and createSubscriptionMessage() methods


Recommended