software agents and applications maria ganzha & marcin paprzycki systems research institute...

76
Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Post on 21-Dec-2015

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Software Agents and Applications

Maria Ganzha & Marcin Paprzycki

Systems Research Institute

Polish Academy of Science

Page 2: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

GeneralitiesGeneralities

1. Agent Metaphors2. Definitions 3. Critical Analysis

Page 3: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

What is an Agent? Seem to be as many definitions as their users Dictionary:

a·gent n.– One that acts or has the power or authority to act– One empowered to act for or represent another: an

author's agent; an insurance agent– A means by which something is done or caused;

instrument– A force or substance that causes a change: a chemical

agent; an infectious agent– A representative or official of a government or

administrative department of a government: an FBI agent– A spy– Linguistics. The noun or noun phrase that specifies the

person through whom or the means by which an action is effected

Page 4: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Technology Metaphors (1) Based on human agents

travel agent insurance / real-estate secret agent personal assistant (a.k.a. secretary)

Result agentshave specialized knowledgerepresent our interests find / filter / customize information

P. Maes, Agents that Reduce Work and Information Overload, CACM, 37, 1994, 31-40

Page 5: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Technology Metaphors (2) Agents as “effect” of software evolution

OOactive objectsagents

Result agentsmethodology for software creation

complex systems build out of interacting intelligent agents

? using agent environments ?

N. R. Jennings, An agent-based approach for building complex software systems, CACM, 44 (4), 2001, 35-41

Page 6: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Technology Metaphors (3) Other agents

Bio-agents (J. Liu, 2001) based on cellular automata / “ants” simple behavior (no intelligence) “intelligence” emergent behavior

Embodied agents Agent-robots (robo-soccer)

Agents in modeling and simulations modeling social interactions (H. Hexmoor, 2003)

modeling crowd behavior (S. Bandini, 2005)

Page 7: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Definition (1) Definition 1

Anything that can be viewed as perceiving its environment through sensors and acting upon that environment through effectors (Russell and Norvig, 1995)

Definition 2Software entities that carry out some set of

operations on behalf of a user or another program with some degree of independence or autonomy, and in so doing, employ some knowledge or representation of the user’s goals or desires (IBM, 1997)

Page 8: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Definition (2)

Definition 3Autonomous system situated in a dynamical

environment acting independently of its restrictions and fulfilling in it a set of goals or directives for which it was created (Maes, 1998)

Definition 4An encapsulated computer system that is

situated in some environment and that is capable of flexible action in that environment in order to meet its design objectives (Jennings et al, 2000)

there is more (or no definition at all; e.g. Liu)…

Page 9: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Definition (3)• Features of software

agents– reactiveness– ability to

communicate– capacity for

cooperation– reasoning based on

collected knowledge– capacity for

reasoning– intelligence– adaptability

– interactiveness– learning ability– proactiveness– goal orientation– friendliness and

reliability– mobility– autonomy– situatedness– …

Page 10: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Definition (4) No agreed-on definition No agreed-on typology Researchers take various characteristics from

the set proposed for agents and make their own “definition” (Galant & Tyburcy, 2001)

Let us use basic intuitionsSoftware artifact

autonomous represents user and has delegation to act on her

behalf interacts with environment and other agents possibly mobile

Page 11: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Client-Server vs. Mobile Agents

Client

Server Server

Client

Agent

Server

Client

Agent

Server

Client

Agent

Traditional Mobile Agent-Based

Mobile agent agent that:can move from one computer to anotheruser-directed / autonomous / mixed

Page 12: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Examples of Agent Systems

• Internet– avatars– search/browsing– monitoring– info-agents

• e-mail• meeting assistants• news

– e-commerce

• Complex systems– trading

• electricity• stock market

– network and resource management

– production control– supply chain

management– complex system

simulations

Page 13: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Why Agents? (some reasons)

Operate where data and/or resources are combine data from multiple repositories possible to combine with GRID computing

load balancing quality of service / service level agreement

Disconnected operations and autonomy short “on-line” times (ideal for mobile devices)

Redundancy / fail-safe behavior multiple agents can “back-up” each other

Page 14: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Few General Criticisms (there is more)

Everything that can be done with agents can be done some other way…

Have been around for years and… ??? Security have to protect

host(s) from agent(s) / agent(s) from host(s)agent(s) from agent(s) / communication

Only one step removed from a virus In many cases agents were not necessary! WHAT, NO DEFINITION?

Page 15: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Possible Responses Agents as a unified framework

Security and virus-related concerns can be addressed (can it be worse than Windows™?)

Agent systems are (and depend on) “bleeding edge” technology that “disappears” (Aglets, BlueStone, e-speak,…)

No way to establish usability / worthlessness until full blown implementations tried…

Page 16: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Specific Criticisms Nwana, Ndumu (1999) A perspective on software

agents research, Knowledge Engineering Review, 14 (2), 1–18

Information discovery problem where is the relevant data and how to keep up with the dynamics of

the Internet? Communication problem

how to make different systems (including agent-agent and agent-non-agent) to communicate with each other?

Legacy software problem how to make agents interact with legacy systems?

Reasoning and coordination problem how to reason about the retrieved data (“AI”)?

Ontology problem how to make different systems understand each other?

Page 17: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

8-years Later (1) Substantial progress

information discovery web / text mining / filtering

communication ACL + FIPA SL (and other) standards by FIPA

legacy systems Java – wrappers

reasoning and coordination a lot of progress in various areas of AI

Page 18: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

8-years Later (2) Ontology problem

hot research area SemanticWeb supported by EU

need of standards is being addressed need of “demarcated” web-pages / sites

critical mass of available data required to establish for each proposed approach its

feasibility strengths weaknesses

agents proposed as a natural technology for the SemanticWeb (Hendler, 2001)

Page 19: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

GeneralitiesGeneralities

4. FIPA – towards agent environments

Page 20: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Foundation for Intelligent Physical Agents (FIPA)Standards Organization

http://www.fipa.org/

Agent Platform (AP) infrastructure for agent environment key agents for management

Agent Communication Language (ACL)communicative acts

Contents of messages (FIPA SL) Protocols – later

message patterns transport level

Page 21: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

FIPA reference architecture Specifies rules for agent societies

to interoperate and to be managed ACL formally defined

syntax and semantics Utilized in modern agent environments

in a long-run may provide interoperability

Other AgentsSpeaks IIOP

or RMI

Message Transport System

AgentManagement

System

DirectoryFacilitator

Agent Platform

Agent1

YellowPages

Supervisorycontrol

Authentication of agents

Registration of agents

Agentn

Page 22: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Communication Language Semantically defined standard vocabulary and syntax

string-based messages An ACL Message:

Structured message, targeted for flexible communication Performative (INFORM, QUERY, REFUSE, …) Addressing (to/from) ConversationID – Used to link messages in same

conversation In reply to – Sender uses to help distinguish answers Reply with – Another field to help distinguish answers Reply by – Used to set a time limit on an answer Language – Specifies which language is used in the

content Ontology – Specifies which ontology is used in the content Protocol – Specifies the protocol Content – This is the main content of the message

Page 23: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Why Use Agent Environments? (1) No need to implement basic services

agent “platform” agent “containers” management infrastructure (such as)

Agent Management System (AMS) – white pages Directory Facilitator (DF) – yellow pages

No need to implement agent-management ontology and functionalities agent is registered within its constructor

it is given a name and an address

agent class provides a simplified interface to access the services of the DF (registration, searching, …)

Page 24: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Why Use Agent Environments? (2) No need to implement Message Transport and Parsing

automatically (and possibly efficiently) done by the environment when sending/receiving messages

Interaction Protocols must only be extended via handle methods

In modern environments FIPA standards are immediately supported… (to a certain extent)

SUMMARIZING some form of an infrastructure to support agent system

development is provided by the environment one can concentrate on designing and implementing

agents systems (high level functionalities)

Page 25: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

GeneralitiesGeneralities

5. Everything You Always Wanted to Know About (JADE) Agents But Were Afraid to Ask

/almost Woody Allen/

Page 26: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

JADE (Java Agent DEvelopment Framework) http://jade.tilab.com target users: agent programmers for MAS includes

a library of classes to create agents a distributed runtime environment (an agent platform)

that provides agent services

life-cycle, white-page, yellow-page, message transport, message encoding

set of tools to support the debugging phase remote monitoring agent, dummy agent, sniffer agent

designed to support scalability from debugging to deployment from small scale to large scale to micro scale

claims to comply with FIPA specifications

Page 27: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

JADE

Page 28: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Distributed architecture of a JADE Agent Platform

Network protocol stack using RMI or IIOP

JRE 1.5 JRE 1.5 JRE 1.5

Jade Main-container Jade Agent Container Jade Agent Container

Jade distributed Agent Platform

DF

Age

nt

AM

S A

gent

App

licat

ion

Age

nt

App

licat

ion

Age

nt

App

licat

ion

Age

nt

App

licat

ion

Age

nt

App

licat

ion

Age

nt

App

licat

ion

Age

nt

Host 1 Host 2 Host 3

App

licat

ion

Age

nt

App

licat

ion

Age

nt

Page 29: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Internal architecture of a generic JADE agent

JADE library of interaction protocols and of generic agent behaviors

Page 30: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent and ACL messages

controls its thread of executionhas a private proxy of the life-

cycle manager decides when to read

messages and which messages to read the transport mechanism fills a

private queue but it does not call the agent code (no automatic callback)

other agents have no way to get the object reference

asynchronous message based communication

Page 31: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Running platform

set CLASSPATH environment variable – .jar library launch the main container of the platform with RMA:

java jade.Boot –gui

attach remote containerjava -cp $CLASSPATH jade.Boot -container

-host remoteMachine E.g.:

set CLASSPATH=%CLASSPATH%;.;c:\jade\lib\jade.jar;c:\jade\lib\jadeTools.jar;c:\jade\lib\commons-codec\commonscodec-1.3.jar; c:\jade\lib\iiop.jar

To launch RMA at/from remote machinejava -cp $CLASSPATH jade.Boot –container –host

remoteMachine rma:jade.tools.rma.rma

Page 32: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science
Page 33: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

GeneralitiesGeneralities

6. Agent environments – comparison

Page 34: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Environments (out of 80+)

Aglets (IBM) ?? relatively simple very popular in the past

Voyager (Object Space), Concordia (Mitsubishi) popular in the past

Grasshopper (IKV) worked very well became somewhat popular

NOMADS (UWF) ?? interesting, developed in the academia support?

JADE (Telecom Italia + France Telecom + others) build around FIPA standards long-term € perspective?

Page 35: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Comparing Agent Environments Only an “exercise” to illustrate the

diversity of the environments and their capabilities

Data based on manuals is it reliable? Composed in 2000

only data about JADE is from 2006 Compared

VoyagerConcordiaGrasshopperAgletsJADE

Page 36: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Garbage Collection For some agents “when work done” they

must be removedVoyager deletes an agent as soon as no

references to itGrasshopper agent persists unless it is removed

explicitly by itself, by the external software component, or by the user

Aglets and Concordia agents must be explicitly removed

JADE agent must be explicitly removed or programmed to kill itself

Page 37: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Remote Creation of Agents Capability of creating agents remotely by

sending only necessary parameters

Voyager, Grasshopper, Aglets and JADE support remote agent creation

Concordia does not

Page 38: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Object Mobility Ability to transfer data objects through the

network without the agent traveling itself network traffic reduction

Voyager supports object mobility

others – objects can be “manually” serialized within ACL Messages

Page 39: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Mobility Ability to migrate from one host to another

two types of migration: strong and weak strong migration agent migrates together with its

complete execution state weak migration agent migrates with its data state

(not the stack information)

Voyager, Grasshopper, Concordia, Aglets support weak migration only

JADE not so weak mobility (can program move between behaviors)

NOMADS support strong mobility

Page 40: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Ability to create a copy of itselfresults in “parallel computing”particularly beneficial

data resides in a physically distributed database database resides on a shared memory

multiprocessor

all five environments support cloning

Cloning

Page 41: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Communication Mechanisms Static and mobile agents communicate to solve

problemstypes of communication

synchronous (waits for answer/confirmation) asynchronous (can continue working) dynamic (communication follows the mobile agent)

in Concordia agent groups facilitate synchronous and asynchronous communication

Aglets support synchronous and asynchronous communication

Voyager, Grasshopper and JADE support synchronous, asynchronous, and dynamic communication

Page 42: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent teams need support for collaborationConcordia strongest collaboration facilities

agents form agent groups Java distributed objects access them via Java’s Remote Method Invocation (RMI)

facility to perform data exchange

Aglets agents negotiate and schedule distributed meetings

Grasshopper, Voyager and JADE do not support a specific model for collaboration

collaboration via messaging

Agent Collaboration

Page 43: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Security measures are necessary Grasshopper and Voyager support security by

implementing authentication, transmission control and confidentiality of communication

Concordia and Aglets supports authentication and transmission integrity

Concordia provides storage protection for operating without a secure file system

JADE security provided by JADE-S add-on supports: agents authentication, acts permissions, message

integrity and confidentiality; limitations: communication can be only encrypted but not

signed, no mobility related permissions, security features mostly not accessible on MIDP devices

Security

Page 44: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

GeneralitiesGeneralities

7. Applications8. Scalability

Page 45: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

What does exist in the world? (1) Industry

well kept industrial secretsMitsubishi used Concordia for ???Daimler-Chrysler – production flow control

prototype – 2001 working product – 2005/06 gain 10-20% effectiveness claimed

dynamic transport flow optimization overall cost reduction – about 11%

wineries in East Australia – flow of wine designed using agent tools implemented using C++

Page 46: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

What does exist in the world? (2) Academic paper content

lack of regard for FIPA standards (why? better now) frameworks and UML diagrams (tedious, ?easy?) new environments (easy) screen-shots of the interface (easy) initial implementation results (almost easy) no continued implementation effort (difficult) systems with few agents only (why?)

Page 47: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Why Few Agents Only? Size matters!

a lot of agents - how many? a lot of messages - how many?

Need for experiments no “benchmarks” for agent systems agent system “scalability” not “fashionable”

Comments We do not try to establish “benchmarks” Just a “feeling” how large can we get?

Page 48: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Experimental Setup JADE 3.1 agent platform Hardware

Sun workstations UltraSparc III (300 MHz) + 198 Mbytes of RAM

PC’s Pentium II (120 MHz) + 48 Mbytes of RAM

Cisco Switch 100 Mbit/s full backplane

Other machines also tried http://agentlab.swps.edu.pl

Page 49: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Spamming Test (1)

Spamming direction

Computer 1

Spammer

User

Computer 2

Spammer

User

Computer 3

Spammer

User

Each machine spammer and user

Spammers send 5000 ACL messages to all users on all machines

Users process messagesmessages stored in

the queue Message size 300

ASCI characters + ACL wrapper

Page 50: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Spamming Test (2)

821341406248

634847351647

448181288436

313625252175

217501251284

141778244403

87053400342

Receivingtime [ms]

Spamming time [ms]Agent pairs

0

5

10

15

20

25

2 3 4 5 6 7 8

agent "pairs"

tim

e p

er m

essa

ge

[ms]

Spamming

Receiving

Spamming time almost “flat” / receiving practically linear

320,000 messages (100 Mbytes of data) processed (in 14 minutes)

Page 51: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Relay-race (1) Multiple computers Each machine contains relay teams Agents from the Main-Container go to

the next machine and exchange messages to start the next group to move to the third machine…

5 laps Varying number of machines and

number of teams

Page 52: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent Relay-race (2)

• Large number of teams / homogeneous / 4 Sun’s

100000

200000

300000

400000

500000

600000

700000

20 40 60 80 100

number of agent-teams

tim

e (m

sec)

Page 53: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agents in an E-shop• Mother Client sends

Clients (C) to the store• Mother Shop

generates Sellers for each Client

• Seller and Client negotiate and report results of negotiations

• Mother Clients on separate machines

• Results for 30, 40, …, 120 Clients generated

• Scaled to 1450+

0

20000

40000

60000

80000

100000

1 2 3 4 5Number of M otherClient agents

Tim

e (m

s)

Page 54: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Comments On outdated hardware agent systems

“scaled” to: 1400+ agents 320,000 messages

We also did run 2000+ agents on better hardware

All “properties” scaled linearly No restrictions related to JADE but to

computer hardware and network speed

Large agent systems can be implemented!

Page 55: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

GeneralitiesGeneralities

9. Coding JADE Agents – preliminary considerations

Page 56: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Agent life-cycle as defined by FIPA

Page 57: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Java JADE: New Classes

jade.core jade.core.Agent jade.core.behaviours

jade.content jade.proto

fipa-request, fipa-query, fipa-contract-net, fipa-subscribe …

*.jar libraries:iiop.jarhttp.jar

jadeTools.jarjade.jar--------

commonscodec-1.3.jar

Page 58: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Code – step by step1.Creation of an agent

import jade.core.Agent;public class ExampleAgent extends Agent {  protected void setup() {    // inicialization of an agent  }  protected void takeDown() {     // opt:executes before deleting of agent  }}

An agent terminates when its doDelete() method is calledOn termination the agent’s takeDown() method is invoked (intended to include clean-up operations)

Page 59: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Running In Eclipse (with arguments):-gui <name of instance>:<package>.<Agent localname>

Example:-gui ta:ibspan.lab1.ex2.TruckAgent(true)

___________________________________________________From console (Start, Run..., cmd):

java –classpath <JADE-classes>;. jade.Boot <name of instance>:<package>.<Agent localname>

Page 60: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Code – step by step2.Initialization of an agent

Each Agent instance is identified by an AID (jade.core.AID) An AID composed of a unique name plus additional addresses

<local-name>@<platform-name> An agent can retrieve its AID through the getAID() method of the

Agent class

public class MyAgent extends Agent {protected void setup() {

// TODO Auto-generated method stub//super.setup();System.out.println("My name is " +

getAID().getName());System.out.println("I am glad to see you");

};protected void takeDown() {

// TODO Auto-generated method stubsuper.takeDown();

}}

TA@MIG:1099/JADE

Page 61: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Local names, GUID and addresses The complete name of an agent must be globally

unique The platform name can be set using the –name

option Given the name of an agent its AID can be

created asAID id = new AID(localname,AID.ISLOCALNAME);AID id = new AID(name, AID.ISGUID);

The addresses included in an AID are those of the platform MTPs and are ONLY used in communication between agents living on different FIPA platforms

Page 62: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Code – step by step3. Passing parameters to an Agent

java jade.Boot .... a:myPackage.MyAgent(arg1,arg2)

public class TruckAgent extends Agent {private boolean isFree = false;//@Overrideprotected void setup() {

Object[] args = getArguments();if (args != null && args.length == 1)

isFree = Boolean.parseBoolean((String) args[0]);else {

doDelete();return;

}System.out.println("I am " + (isFree ? "free" : "not free") +" !");}

}

protected void takeDown(){System.out.println("Bye...");}

Ibspan.lab1.ex2

To run w

ithout/w

ith parameters

Add it and check how it

works

Page 63: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Behaviour class The actual job that an agent does is typically carried out

within “behaviors” Behaviours are created by extending the

jade.core.behaviours.Behaviour class To make an agent execute a task it is sufficient to create an

instance of the corresponding Behavior subclass and call the addBehaviour() method of the Agent class

Each Behaviour subclass must implement public void action(): what the behavior actually does public boolean done(): Whether the behavior is

finished An agent can execute several behaviors in parallel,

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

Behavior switch occurs only when the action() method of the currently scheduled behavior returns

Page 64: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Code – step by step4. Agent behavior

jade.core.behaviours.Behaviour

Difference between

doDelete(), and

takeDown()

setup()

Agent has been killed (doDelete())

Get the next behavior from the pool of active behaviors

b.action()

b.done()?

Remove currentBehaviorfrom the pool of active behavior

takeDown()

NO

YES

YES

Jade Tutorial: Jade Programming For Beginners, http://jade.tilab.com

Page 65: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Behavior types “One shot” behavior:public abstract class OneShotBehaviourextends SimpleBehaviour {

//Default constructor. It does not set the owner agentpublic OneShotBehaviour() {super();}

//This constructor sets the owner agent for this OneShotBehaviour //code. Parameter a is a “name” of agent this behaviour belongs to

public OneShotBehaviour(Agent a){super(a);

}// The following method makes this behaviour one-shot

public final boolean done(){return true;}

}

Page 66: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Examplepublic class TruckAgent extends Agent {

//Overrideprotected void setup() {Behaviour b = new OneShotBehaviour(this) {

//Overridepublic void action() {

System.out.println("My name is " + getAID().getName());

System.out.println("I am free on Monday!");}

};addBehaviour(b);}

}Ibspan.lab1.ex1

Page 67: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Behavior types (continued) “Cyclic” behaviorspublic abstract class CyclicBehaviourextends SimpleBehaviour {

//Default constructor. It does not set the owner agentpublic CyclicBehaviour() {super();}//This constructor sets the owner agent for this OneShotBehaviour //code. Parameter a is a “name” of agent this behaviour belongs topublic CyclicBehaviour(Agent a){

super(a);}// The following method makes this behaviour cyclic

public final boolean done(){return false;}

}

Page 68: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Example

public class TruckAgent extends Agent {private boolean isFree = false;//Overrideprotected void setup() {

Behaviour b = new CyclicBehaviour(this) {public void action() {

System.out.println("I am " +(isFree ? "free" : "not free") +" !");

}};

addBehaviour(b);}

}

Ibspan.lab1.ex3

Page 69: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Behavior types “Complex” behaviors

FSMBehaviour – models a complex task whose subtasks correspond to activities performed in the states of a Finite States Machine

SequenceBehaviour – models o complex task whose sub-tasks are executed sequentially

ParallelBehaviour – models a complex task whose sub-tasks are executed concurrently

WakerBehaviour OneShotBehaviour The action() and done() methods are already implemented

so that the onWake() method (to be implemented by subclasses) is executed after a given timeout

After that execution the behaviour completes TickerBehaviour CyclicBehaviour

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

The behaviour runs forever unless its stop() method is executed

Page 70: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

Concurrency in JADE

Agent needs concurrency:to engage in multiple simultaneous conversationsto execute several concurrent tasks

Example - AirConditinioning application, responsible forChecking temperature insideChecking temperature outside

Activities must be performed

concurrently with different freqeuncy

Page 71: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

AirConditioning with threads (1)

Let see different approaches to handling concurrencyputting common-used functionality into separate

class: ibspan.lab1.ex3.AirConditioning Threads are managed by JVM in pre-emptive

manner This means threads work in competitive way Look at:

ibspan.lab1.ex4.AirConditioningThreads

Page 72: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

AirConditioning with threads (2)

public class AirConditioning {Random gen = new Random(System.currentTimeMillis());float outTemp, inTemp;public AirConditioning(float out, float in) {

outTemp = out;inTemp = in;}

public void checkTempOutside() {float c = (gen.nextFloat() - 0.5f) * 0.1f;outTemp = (1f - c) * outTemp + c;System.out.println("Outside: " + outTemp);}

public void checkTempInside() {float c = (gen.nextFloat() - 0.5f) * 0.05f;inTemp = (1f - c) * inTemp + c; System.out.println(" Inside: " + inTemp);}

}

Outside: 34.614143 Inside: 20.417917Outside: 35.44636 Inside: 20.85639Outside: 34.689354Outside: 34.93689 Inside: 20.849Outside: 33.34642 Inside: 21.218094Outside: 32.28482

Page 73: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

AirConditioning with Agents (1)

Each JADE agent is executed in a single Java thread Behaviours are managed by JADE in non-re-emptive

manner This means behaviours work in cooperative way

Every behaviour must release control to allow the other behaviours to be executed

Behaviour switch occurs only when the action() method of the currently scheduled behaviour returns

JADE scheduler carries out a round-robin policy among all behaviours in the ready queue

When the pool of active behaviours is empty the agent enters the IDLE state and its thread goes to sleep

Page 74: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

public class AirConditioningAgent1 extends Agent {AirConditioning ac;protected void setup() {ac = new AirConditioning(36f, 20f);

// Construct behaviour checking temperature outsideBehaviour b1 = new SimpleBehaviour(this) {public void action() {

while(true) { ac.checkTempOutside();block(5000);}}

public boolean done() { return false;}};

addBehaviour(b1); // Construct behaviour checking temperature inside

Behaviour b2 = new SimpleBehaviour(this) {public void action() {

while(true) { ac.checkTempInside(); block(8000);}}

public boolean done() {return false;}};addBehaviour(b2);

}

Outside: 35.71913Outside: 35.71527Outside: 35.012707Outside: 36.24267Outside: 36.591988Outside: 37.34552Outside: 37.01548

Infinite loop not allowed in non-

preemptive schedulling

Page 75: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

AirConditioning with agents (2)public class AirConditioningAgent2 extends Agent {

AirConditioning ac;protected void setup() {ac = new AirConditioning(36f, 20f);

// Construct behaviour checking temperature outsideBehaviour b1 = new CyclicBehaviour(this) {

public void action() { ac.checkTempOutside();block(5000);}};addBehaviour(b1);

// Construct behaviour checking temperature insideBehaviour b2 = new CyclicBehaviour(this) {public void action() { ac.checkTempInside();block(8000);}};addBehaviour(b2);

}}

Outside: 37.11966 Inside: 19.951431Outside: 36.17769 Inside: 20.149591Outside: 35.71485Outside: 34.88394 Inside: 20.61761

Page 76: Software Agents and Applications Maria Ganzha & Marcin Paprzycki Systems Research Institute Polish Academy of Science

The EndThe End