Top Banner
Agent Oriented Programming with Jason Jomi F. H¨ ubner Federal University of Santa Catarina, Brazil PPGEAS 2014 — UFSC
75

Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Aug 02, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Agent Oriented Programming

with Jason

Jomi F. Hubner

Federal University of Santa Catarina, Brazil

PPGEAS 2014 — UFSC

Page 2: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Outline

I Introduction

I BDI architecture

I Jason hello world

I Jason (details)

I Conclusions

(slides written together with R. Bordini, O. Boissier, and A. Ricci)

2

Page 3: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Multi-Agent System (our perspective)

def...

An organisation of autonomous agents interacting together within

a shared environment

I agents can be: software/hardware, coarse-grain/small-grain,

heterogeneous/homogeneous, reactive/pro-active entities

I environment can be virtual/physical, passive/active,

deterministic/non deterministic, ...

I interaction is the motor of dynamic in MAS. Interaction can

be: direct/indirect between agents, interaction between

agent and environment

I organisation can be pre-defined/emergent, static/adaptive,

open/closed, ...

3

Page 4: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Multi-Agent System (our perspective)

def...

An organisation of autonomous agents interacting together within

a shared environment

I agents can be: software/hardware, coarse-grain/small-grain,

heterogeneous/homogeneous, reactive/pro-active entities

I environment can be virtual/physical, passive/active,

deterministic/non deterministic, ...

I interaction is the motor of dynamic in MAS. Interaction can

be: direct/indirect between agents, interaction between

agent and environment

I organisation can be pre-defined/emergent, static/adaptive,

open/closed, ...

3

Page 5: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Multi-Agent System (our perspective)

def...

An organisation of autonomous agents interacting together within

a shared environment

I agents can be: software/hardware, coarse-grain/small-grain,

heterogeneous/homogeneous, reactive/pro-active entities

I environment can be virtual/physical, passive/active,

deterministic/non deterministic, ...

I interaction is the motor of dynamic in MAS. Interaction can

be: direct/indirect between agents, interaction between

agent and environment

I organisation can be pre-defined/emergent, static/adaptive,

open/closed, ...

3

Page 6: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Multi-Agent System (our perspective)

def...

An organisation of autonomous agents interacting together within

a shared environment

I agents can be: software/hardware, coarse-grain/small-grain,

heterogeneous/homogeneous, reactive/pro-active entities

I environment can be virtual/physical, passive/active,

deterministic/non deterministic, ...

I interaction is the motor of dynamic in MAS. Interaction can

be: direct/indirect between agents, interaction between

agent and environment

I organisation can be pre-defined/emergent, static/adaptive,

open/closed, ...

3

Page 7: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Multi-Agent System (our perspective)

def...

An organisation of autonomous agents interacting together within

a shared environment

I agents can be: software/hardware, coarse-grain/small-grain,

heterogeneous/homogeneous, reactive/pro-active entities

I environment can be virtual/physical, passive/active,

deterministic/non deterministic, ...

I interaction is the motor of dynamic in MAS. Interaction can

be: direct/indirect between agents, interaction between

agent and environment

I organisation can be pre-defined/emergent, static/adaptive,

open/closed, ...

3

Page 8: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Multi-Agent System (our perspective)

def...

An organisation of autonomous agents interacting together within

a shared environment

MAS is not a simple set of agents

I agents can be: software/hardware, coarse-grain/small-grain,

heterogeneous/homogeneous, reactive/pro-active entities

I environment can be virtual/physical, passive/active,

deterministic/non deterministic, ...

I interaction is the motor of dynamic in MAS. Interaction can

be: direct/indirect between agents, interaction between

agent and environment

I organisation can be pre-defined/emergent, static/adaptive,

open/closed, ...

3

Page 9: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Levels in Multi-Agent Systems

roleorgmission

schema

ORGAMISATIONLEVEL

AGENTLEVEL

ENDOGENOUSENVIRONMENTLEVELwsp

artifact

network node

EXOGENOUS ENVIRONMENT

agent

4

Page 10: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Abstractions in Multi-Agent Systems

I Individual levelI autonomy, situatednessI beliefs, desires, goals, intentions, plansI sense/reason/act, reactive/pro-active behaviour

I Environment levelI resources and services that agents can access and controlI sense/act

I Social levelI cooperation, languages, protocols

I Organisation levelI coordination, regulation patterns, norms, obligations, rights

5

Page 11: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Agent Oriented Programming— AOP —

Page 12: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Literature I

Books: [Bordini et al., 2005], [Bordini et al., 2009]

Proceedings: ProMAS, DALT, LADS, EMAS, ...

Surveys: [Bordini et al., 2006], [Fisher et al., 2007] ...

Languages of historical importance: Agent0 [Shoham, 1993],

AgentSpeak(L) [Rao, 1996],

MetateM [Fisher, 2005],

3APL [Hindriks et al., 1997],

Golog [Giacomo et al., 2000]

Other prominent languages:

Jason [Bordini et al., 2007],

Jadex [Pokahr et al., 2005], 2APL [Dastani, 2008],

GOAL [Hindriks, 2009], JACK [Winikoff, 2005],

JIAC, AgentFactory

But many others languages and platforms...

7

Page 13: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Some Languages and Platforms

Jason (Hubner, Bordini, ...); 3APL and 2APL (Dastani, van

Riemsdijk, Meyer, Hindriks, ...); Jadex (Braubach, Pokahr);

MetateM (Fisher, Guidini, Hirsch, ...); ConGoLog (Lesperance,

Levesque, ... / Boutilier – DTGolog); Teamcore/ MTDP (Milind

Tambe, ...); IMPACT (Subrahmanian, Kraus, Dix, Eiter); CLAIM

(Amal El Fallah-Seghrouchni, ...); GOAL (Hindriks); BRAHMS

(Sierhuis, ...); SemantiCore (Blois, ...); STAPLE (Kumar, Cohen,

Huber); Go! (Clark, McCabe); Bach (John Lloyd, ...); MINERVA

(Leite, ...); SOCS (Torroni, Stathis, Toni, ...); FLUX

(Thielscher); JIAC (Hirsch, ...); JADE (Agostino Poggi, ...);

JACK (AOS); Agentis (Agentis Software); Jackdaw (Calico

Jack); ...

8

Page 14: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

The State of Multi-Agent Programming

I Already the right way to implement MAS is to use an AOSE

methodology (Prometheus, Gaia, Tropos, ...) and an MAS

programming language!

I Many agent languages have efficient and stable interpreters

— used extensively in teaching

I All have some programming tools (IDE, tracing of agents’

mental attitudes, tracing of messages exchanged, etc.)

I Finally integrating with social aspects of MAS

I Growing user base

9

Page 15: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Agent Oriented ProgrammingFeatures

I Reacting to events × long-term goals

I Course of actions depends on circumstance

I Plan failure (dynamic environments)

I Social ability

I Combination of theoretical and practical reasoning

10

Page 16: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Agent Oriented ProgrammingFundamentals

I Use of mentalistic notions and a societal view of

computation [Shoham, 1993]

I Heavily influence by the BDI architecture and reactive

planning systems [Bratman et al., 1988]

11

Page 17: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

BDI architecture[Wooldridge, 2009]

begin1

while true do2

p ← perception()3

B ← brf (B, p) ; // belief revision4

D ← options(B, I ) ; // desire revision5

I ← filter(B,D, I ) ; // deliberation6

execute(I ) ; // means-end7

end8

12

Page 18: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

BDI architecture[Wooldridge, 2009]

while true do1

B ← brf (B, perception())2

D ← options(B, I )3

I ← filter(B,D, I )4

π ← plan(B, I ,A)5

while π 6= ∅ do6

execute( head(π) )7

π ← tail(π)8

13

Page 19: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

BDI architecture[Wooldridge, 2009]

while true do1

B ← brf (B, perception())2

D ← options(B, I )3

I ← filter(B,D, I )4

π ← plan(B, I ,A)5

while π 6= ∅ do6

execute( head(π) )7

π ← tail(π)8

13

Page 20: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

BDI architecture[Wooldridge, 2009]

while true do1

B ← brf (B, perception())2

D ← options(B, I )3

I ← filter(B,D, I )4

π ← plan(B, I ,A)5

while π 6= ∅ do6

execute( head(π) )7

π ← tail(π)8

B ← brf (B, perception())9

if ¬sound(π, I ,B) then10

π ← plan(B, I ,A)11

revise commitment to plan – re-planning for context adaptation

13

Page 21: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

BDI architecture[Wooldridge, 2009]

while true do1

B ← brf (B, perception())2

D ← options(B, I )3

I ← filter(B,D, I )4

π ← plan(B, I ,A)5

while π 6= ∅ and ¬succeeded(I ,B) and ¬impossible(I ,B) do6

execute( head(π) )7

π ← tail(π)8

B ← brf (B, perception())9

if ¬sound(π, I ,B) then10

π ← plan(B, I ,A)11

revise commitment to intentions – Single-Minded Commitment

13

Page 22: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

BDI architecture[Wooldridge, 2009]

while true do1

B ← brf (B, perception())2

D ← options(B, I )3

I ← filter(B,D, I )4

π ← plan(B, I ,A)5

while π 6= ∅ and ¬succeeded(I ,B) and ¬impossible(I ,B) do6

execute( head(π) )7

π ← tail(π)8

B ← brf (B, perception())9

if reconsider(I ,B) then10

D ← options(B, I )11

I ← filter(B,D, I )12

if ¬sound(π, I ,B) then13

π ← plan(B, I ,A)14

reconsider the intentions (not always!)

13

Page 23: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Jason(let’s go programming those nice concepts)

Page 24: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

(BDI) Hello World

i am(happy). // B

!say(hello). // D

+!say(X) : not i am(sad) ¡- .print(X). // I

15

Page 25: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Desires in Hello World

+i am(happy) ¡- !say(hello).

+!say(X) : not i am(sad) ¡- .print(X).

16

Page 26: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Hello Worldsource of beliefs

+i am(happy)[source(A)]

: someone who knows me very well(A)

¡- !say(hello).

+!say(X) : not i am(sad) ¡- .print(X).

17

Page 27: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Hello Worldplan selection

+is happy(H)[source(A)]

: sincere(A) & .my name(H)

¡- !say(hello).

+is happy(H)

: not .my name(H)

¡- !say(i envy(H)).

+!say(X) : not i am(sad) ¡- .print(X).

18

Page 28: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Hello Worldintention revision

+is happy(H)[source(A)]

: sincere(A) & .my name(H)

¡- !say(hello).

+is happy(H)

: not .my name(H)

¡- !say(i envy(H)).

+!say(X) : not i am(sad) ¡- .print(X); !say(X).

-is happy(H)

: .my name(H)

¡- .drop intention(say(hello)).

19

Page 29: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Hello Worldintention revision

+is happy(H)[source(A)]

: sincere(A) & .my name(H)

¡- !say(hello).

+is happy(H)

: not .my name(H)

¡- !say(i envy(H)).

+!say(X) : not i am(sad) ¡- .print(X); !say(X).

-is happy(H)

: .my name(H)

¡- .drop intention(say(hello)).

19

Page 30: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

AgentSpeakThe foundational language for Jason

I Originally proposed by Rao [Rao, 1996]

I Programming language for BDI agents

I Elegant notation, based on logic programming

I Inspired by PRS (Georgeff & Lansky), dMARS (Kinny), and

BDI Logics (Rao & Georgeff)

I Abstract programming language aimed at theoretical results

20

Page 31: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

JasonA practical implementation of a variant of AgentSpeak

I Jason implements the operational semantics of a variant of

AgentSpeak

I Has various extensions aimed at a more practical

programming language (e.g. definition of the MAS,

communication, ...)

I Highly customised to simplify extension and experimentation

I Developed by Jomi F. Hubner, Rafael H. Bordini, and others

21

Page 32: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Main Language Constructs

Beliefs: represent the information available to an agent (e.g.

about the environment or other agents)

Goals: represent states of affairs the agent wants to bring

about

Plans: are recipes for action, representing the agent’s

know-how

Events: happen as consequence to changes in the agent’s

beliefs or goals

Intentions: plans instantiated to achieve some goal

22

Page 33: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Main Language Constructs and Runtime Structures

Beliefs: represent the information available to an agent (e.g.

about the environment or other agents)

Goals: represent states of affairs the agent wants to bring

about

Plans: are recipes for action, representing the agent’s

know-how

Events: happen as consequence to changes in the agent’s

beliefs or goals

Intentions: plans instantiated to achieve some goal

22

Page 34: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Basic Reasoning cycleruntime interpreter

I perceive the environment and update belief base

I process new messages

I select event

I select relevant plans

I select applicable plans

I create/update intention

I select intention to execute

I execute one step of the selected intention

23

Page 35: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Jason Reasoning Cycle

SI

EventsExternal

EventSelected

SE

Beliefs toAdd and

Delete

RelevantPlans

New PlanPush

IntentionUpdated

OS

Applicable

Plans

Means

Intended

EventsExternal

PlanLibrary

Events

InternalEvents

3

checkMail

Intentions

ExecuteIntention

...NewNew

9

BeliefBase

NewIntention

Percepts

act

SelectedIntention

Intentions

Action

Percepts1 2

BUF

10

Events

Context

Check

Event

Unify

BRF

Beliefs

Agent

sendMsg

Beliefs

8

Messages

Plans

perceive

7

5

6

Actions

Beliefs

Suspended Intentions(Actions and Msgs)

...

.send

SocAcc

4

Messages MessagesSM

24

Page 36: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Beliefs — Representation

Syntax

Beliefs are represented by annotated literals of first order logic

functor(term1, ..., termn)[annot1, ..., annotm]

Example (belief base of agent Tom)

red(box1)[source(percept)].

friend(bob,alice)[source(bob)].

lier(alice)[source(self),source(bob)].

˜lier(bob)[source(self)].

25

Page 37: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Beliefs — Dynamics I

by perception

beliefs annotated with source(percept) are automatically updated

accordingly to the perception of the agent

by intention

the plan operators + and - can be used to add and remove beliefs

annotated with source(self) (mental notes)

+lier(alice); // adds lier(alice)[source(self)]

-lier(john); // removes lier(john)[source(self)]

26

Page 38: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Beliefs — Dynamics II

by communication

when an agent receives a tell message, the content is a new belief

annotated with the sender of the message

.send(tom,tell,lier(alice)); // sent by bob

// adds lier(alice)[source(bob)] in Tom’s BB

...

.send(tom,untell,lier(alice)); // sent by bob

// removes lier(alice)[source(bob)] from Tom’s BB

27

Page 39: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Goals — Representation

Types of goals

I Achievement goal: goal to do

I Test goal: goal to know

Syntax

Goals have the same syntax as beliefs, but are prefixed by

! (achievement goal) or

? (test goal)

Example (Initial goal of agent Tom)

!write(book).

28

Page 40: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Goals — Dynamics I

by intention

the plan operators ! and ? can be used to add a new goal

annotated with source(self)

...

// adds new achievement goal !write(book)[source(self)]

!write(book);

// adds new test goal ?publisher(P)[source(self)]

?publisher(P);

...

29

Page 41: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Goals — Dynamics IIby communication – achievement goal

when an agent receives an achieve message, the content is a new

achievement goal annotated with the sender of the message

.send(tom,achieve,write(book)); // sent by Bob

// adds new goal write(book)[source(bob)] for Tom

...

.send(tom,unachieve,write(book)); // sent by Bob

// removes goal write(book)[source(bob)] for Tom

30

Page 42: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Goals — Dynamics III

by communication – test goal

when an agent receives an askOne or askAll message, the content

is a new test goal annotated with the sender of the message

.send(tom,askOne,published(P),Answer); // sent by Bob

// adds new goal ?publisher(P)[source(bob)] for Tom

// the response of Tom will unify with Answer

31

Page 43: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Triggering Events — Representation

I Events happen as consequence to changes in the agent’s

beliefs or goals

I An agent reacts to events by executing plans

I Types of plan triggering events

+b (belief addition)

-b (belief deletion)

+!g (achievement-goal addition)

-!g (achievement-goal deletion)

+?g (test-goal addition)

-?g (test-goal deletion)

32

Page 44: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Plans — Representation

An AgentSpeak plan has the following general structure:

triggering event : context ¡- body.

where:

I the triggering event denotes the events that the plan is

meant to handle

I the context represent the circumstances in which the plan

can be used

I the body is the course of action to be used to handle the

event if the context is believed true at the time a plan is

being chosen to handle the event

33

Page 45: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Plans — Operators for Plan Context

Boolean operators

& (and)

| (or)

not (not)

= (unification)

>, >= (relational)

<, <= (relational)

== (equals)

\ == (different)

Arithmetic operators

+ (sum)

- (subtraction)

* (multiply)

/ (divide)

div (divide – integer)

mod (remainder)

** (power)

34

Page 46: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Plans — Operators for Plan Body

+rain : time to leave(T) & clock.now(H) & H ¿= T

¡- !g1; // new sub-goal

!!g2; // new goal

?b(X); // new test goal

+b1(T-H); // add mental note

-b2(T-H); // remove mental note

-+b3(T*H); // update mental note

jia.get(X); // internal action

X ¿ 10; // constraint to carry on

close(door);// external action

!g3[hard deadline(3000)]. // goal with deadline

35

Page 47: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Plans — Example

+green patch(Rock)[source(percept)]

: not battery charge(low)

¡- ?location(Rock,Coordinates);

!at(Coordinates);

!examine(Rock).

+!at(Coords)

: not at(Coords) & safe path(Coords)

¡- move towards(Coords);

!at(Coords).

+!at(Coords)

: not at(Coords) & not safe path(Coords)

¡- ...

+!at(Coords) : at(Coords).

36

Page 48: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Plans — Dynamics

The plans that form the plan library of the agent come from

I initial plans defined by the programmer

I plans added dynamically and intentionally byI .add planI .remove plan

I plans received fromI tellHow messagesI untellHow

37

Page 49: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

A note about “Control”

Agents can control (manipulate) their own (and influence the

others)

I beliefs

I goals

I plan

By doing so they control their behaviour

The developer provides initial values of these elements and thus

also influence the behaviour of the agent

38

Page 50: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Other Language FeaturesStrong Negation

+!leave(home)

: ˜raining¡- open(curtains); ...

+!leave(home)

: not raining & not ˜raining¡- .send(mum,askOne,raining,Answer,3000); ...

39

Page 51: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Prolog-like Rules in the Belief Base

tall(X) :-

woman(X) & height(X, H) & H ¿ 1.70

man(X) & height(X, H) & H ¿ 1.80.

likely color(Obj,C) :-

colour(Obj,C)[degOfCert(D1)] &

not (colour(Obj, )[degOfCert(D2)] & D2 ¿ D1) &

not ˜colour(C,B).

40

Page 52: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Plan Annotations

I Like beliefs, plans can also have annotations, which go in the

plan label

I Annotations contain meta-level information for the plan,

which selection functions can take into consideration

I The annotations in an intended plan instance can be changed

dynamically (e.g. to change intention priorities)

I There are some pre-defined plan annotations, e.g. to force a

breakpoint at that plan or to make the whole plan execute

atomically

Example (an annotated plan)

@myPlan[chance of success(0.3), usual payoff(0.9),

any other property]

+!g(X) : c(t) ¡- a(X).

41

Page 53: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Failure Handling: Contingency Plans

Example (an agent blindly committed to g)

+!g : g.

+!g : ... ¡- ... ?g.

-!g : true ¡- !g.

42

Page 54: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Meta Programming

Example (an agent that asks for plans on demand)

-!G[error(no relevant)] : teacher(T)

¡- .send(T, askHow, { +!G }, Plans);.add plan(Plans);

!G.

in the event of a failure to achieve any goal G due to no

relevant plan, asks a teacher for plans to achieve G and

then try G again

I The failure event is annotated with the error type, line,

source, ... error(no relevant) means no plan in the agent’s

plan library to achieve G

I { +!G } is the syntax to enclose triggers/plans as terms

43

Page 55: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Internal Actions

I Unlike actions, internal actions do not change the

environment

I Code to be executed as part of the agent reasoning cycle

I AgentSpeak is meant as a high-level language for the agent’s

practical reasoning and internal actions can be used for

invoking legacy code elegantly

I Internal actions can be defined by the user in Java

libname.action name(. . .)

44

Page 56: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Standard Internal Actions

I Standard (pre-defined) internal actions have an empty librarynameI .print(term1, term2, . . .)I .union(list1, list2, list3)I .my name(var)I .send(ag,perf ,literal)I .intend(literal)I .drop intention(literal)

I Many others available for: printing, sorting, list/string

operations, manipulating the beliefs/annotations/plan library,

creating agents, waiting/generating events, etc.

45

Page 57: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Jason × Java I

Consider a very simple robot with two goals:

I when a piece of gold is seen, go to it

I when battery is low, go charge it

46

Page 58: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Jason × Java II

Example (Java code – go to gold)

public class Robot extends Thread {boolean seeGold, lowBattery;

public void run() {while (true) {

while (! seeGold) {a = randomDirection();

doAction(go(a));

}while (seeGold) {

a = selectDirection();

doAction(go(a));

} } } }

47

Page 59: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Jason × Java III

Example (Java code – charge battery)

public class Robot extends Thread {boolean seeGold, lowBattery;

public void run() {while (true) {

while (! seeGold) {a = randomDirection();

doAction(go(a));

if (lowBattery) charge();

}while (seeGold) {

a = selectDirection ();

if (lowBattery) charge();

doAction(go(a));

if (lowBattery) charge();

} } } }

48

Page 60: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Jason × Java IV

Example (Jason code)

direction(gold) :- see(gold).

direction(random) :- not see(gold).

+!find(gold) // long term goal

¡- ?direction(A);

go(A);

!find(gold).

+battery(low) // reactivity

¡- !charge.

ˆ!charge[state(started)] // goal meta-events

¡- .suspend(find(gold)).

ˆ!charge[state(finished)]

¡- .resume(find(gold)).

49

Page 61: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Jason × Prolog

I With the Jason extensions, nice separation of theoretical and

practical reasoning

I BDI architecture allowsI long-term goals (goal-based behaviour)I reacting to changes in a dynamic environmentI handling multiple foci of attention (concurrency)

I Acting on an environment and a higher-level conception of a

distributed system

50

Page 62: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Communication Infrastructure

Various communication and execution management

infrastructures can be used with Jason:

Centralised: all agents in the same machine,

one thread by agent, very fast

Centralised (pool): all agents in the same machine,

fixed number of thread,

allows thousands of agents

Jade: distributed agents, FIPA-ACL

... others defined by the user (e.g. AgentScape)

51

Page 63: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

MAS Configuration Language I

I Simple way of defining a multi-agent system

Example (MAS that uses JADE as infrastructure)

MAS my˙system –

infrastructure: Jade

environment: robotEnv

agents:

c3po;

r2d2 at jason.sourceforge.net;

bob #10; // 10 instances of bob

classpath: ”../lib/graph.jar”;

˝

52

Page 64: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

MAS Configuration Language II

I Configuration of event handling, frequency of perception,

user-defined settings, customisations, etc.

Example (MAS with customised agent)

MAS custom –

agents: bob [verbose=2,paramters=”sys.properties”]

agentClass MyAg

agentArchClass MyAgArch

beliefBaseClass jason.bb.JDBCPersistentBB(

”org.hsqldb.jdbcDriver”,

”jdbc:hsqldb:bookstore”,

...

˝

53

Page 65: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

JaCaMo Configuration Language I(beta version)

mas my˙system –

agent c3po

agent r2d2 –

focus: a1

roles: auctioneer in g1

˝

workspace robots –

artifact a1: Counter(10)

˝

organisation o1 –

group g1: auction

˝

platform: jade()

˝

54

Page 66: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

JaCaMo Configuration Language II(beta version)

agent bob –

beliefs: p(10), p(20)

goals: go(home), charge

instances: 5

verbose: 2

ag-class: MyAg

ag-arch: MyAgArch

ag-bb-class: jason.bb.JDBCPersistentBB(

”org.hsqldb.jdbcDriver”,

”jdbc:hsqldb:bookstore”,

...

˝

55

Page 67: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Jason Customisations

I Agent class customisation:

selectMessage, selectEvent, selectOption, selectIntetion, buf,

brf, ...

I Agent architecture customisation:

perceive, act, sendMsg, checkMail, ...

I Belief base customisation:add, remove, contains, ...I Example available with Jason: persistent belief base (in text

files, in data bases, ...)

56

Page 68: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Tools

I Eclipse Plugin

I Mind Inspector

I Integration withI CArtAgOI MoiseI MADEMI OntologiesI ...

I More on http://jason.sourceforge.net/wp/projects/

57

Page 69: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Summary

I AgentSpeakI Logic + BDII Agent programming language

I JasonI AgentSpeak interpreterI Implements the operational semantics of AgentSpeakI Speech-act based communicaitonI Highly customisableI Useful toolsI Open sourceI Open issues

58

Page 70: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Acknowledgements

I Many thanks to theI Various colleagues acknowledged/referenced throughout

these slidesI Jason users for helpful feedbackI CNPq for supporting some of our current researh

59

Page 71: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Further Resources

I http://jason.sourceforge.net

I R.H. Bordini, J.F. Hubner, and

M. Wooldrige

Programming Multi-Agent Systems in

AgentSpeak using Jason

John Wiley & Sons, 2007.

60

Page 72: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Bibliography I

Bordini, R. H., Braubach, L., Dastani, M., Fallah-Seghrouchni, A. E.,

Gomez-Sanz, J. J., Leite, J., O’Hare, G. M. P., Pokahr, A., and Ricci, A.

(2006).

A survey of programming languages and platforms for multi-agent systems.

Informatica (Slovenia), 30(1):33–44.

Bordini, R. H., Dastani, M., Dix, J., and Fallah-Seghrouchni, A. E., editors

(2005).

Multi-Agent Programming: Languages, Platforms and Applications, volume 15

of Multiagent Systems, Artificial Societies, and Simulated Organizations.

Springer.

Bordini, R. H., Dastani, M., Dix, J., and Fallah-Seghrouchni, A. E., editors

(2009).

Multi-Agent Programming: Languages, Tools and Applications.

Springer.

Bordini, R. H., Hubner, J. F., and Wooldridge, M. (2007).

Programming Multi-Agent Systems in AgentSpeak Using Jason.

Wiley Series in Agent Technology. John Wiley & Sons.

61

Page 73: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Bibliography II

Bratman, M. E., Israel, D. J., and Pollack, M. E. (1988).

Plans and resource-bounded practical reasoning.

Computational Intelligence, 4:349–355.

Dastani, M. (2008).

2apl: a practical agent programming language.

Autonomous Agents and Multi-Agent Systems, 16(3):214–248.

Fisher, M. (2005).

Metatem: The story so far.

In PROMAS, pages 3–22.

Fisher, M., Bordini, R. H., Hirsch, B., and Torroni, P. (2007).

Computational logics and agents: A road map of current technologies and

future trends.

Computational Intelligence, 23(1):61–91.

Giacomo, G. D., Lesperance, Y., and Levesque, H. J. (2000).

Congolog, a concurrent programming language based on the situation calculus.

Artif. Intell., 121(1-2):109–169.

Hindriks, K. V. (2009).

Programming rational agents in GOAL.

In [Bordini et al., 2009], pages 119–157.

62

Page 74: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Bibliography III

Hindriks, K. V., de Boer, F. S., van der Hoek, W., and Meyer, J.-J. C. (1997).

Formal semantics for an abstract agent programming language.

In Singh, M. P., Rao, A. S., and Wooldridge, M., editors, ATAL, volume 1365

of Lecture Notes in Computer Science, pages 215–229. Springer.

Pokahr, A., Braubach, L., and Lamersdorf, W. (2005).

Jadex: A bdi reasoning engine.

In [Bordini et al., 2005], pages 149–174.

Rao, A. S. (1996).

Agentspeak(l): Bdi agents speak out in a logical computable language.

In de Velde, W. V. and Perram, J. W., editors, MAAMAW, volume 1038 of

Lecture Notes in Computer Science, pages 42–55. Springer.

Shoham, Y. (1993).

Agent-oriented programming.

Artif. Intell., 60(1):51–92.

Winikoff, M. (2005).

Jack intelligent agents: An industrial strength platform.

In [Bordini et al., 2005], pages 175–193.

63

Page 75: Jomi F. H ubner - unige.it€¦ · Basic Reasoning cycle runtime interpreter I perceive the environment and update belief base I process new messages ... I select intention to execute

Bibliography IV

Wooldridge, M. (2009).

An Introduction to MultiAgent Systems.

John Wiley and Sons, 2nd edition.

64