42
Introduction to AgentSpeak and Jason for Programming Multi-agent Systems (2) Dr Fuhua (Oscar) Lin SCIS Athabasca University June 19, 2009

Introduction to AgentSpeak and Jason for Programming Multi-agent Systems (2) Dr Fuhua (Oscar) Lin SCIS Athabasca University June 19, 2009

Embed Size (px)

Citation preview

Introduction to AgentSpeak and Jason for Programming Multi-agent Systems

(2)

Dr Fuhua (Oscar) LinSCIS

Athabasca UniversityJune 19, 2009

The Procedural Reasoning System

04/18/23 Athabasca University 2

BeliefsBeliefs

IntentionsIntentions

Plan libraryPlan

library

DesiresDesires

InterpreterInterpreterSensor inputSensor input Action outputAction output

Introduction

• Jason is a fully-fledged interpreter for an extended version of AgentSpeak, a BDI agent-oriented logic programming language, and is implemented in Java. Using SACI or JADE, a multi-agent system can be distributed over a network effortlessly.

04/18/23 3Athabasca University

Saci (Simple Agent Communication Infrastructure)

• is a tool that facilitates the task of programming communication among distributed agents.

• The main features provided by Saci are an API to manipulate KQML messages like composing, sending and receiving and tools to provide useful services in a distributed environment like– agent name service, – directory service, – remote launching,– communication debug, to name a few.

04/18/23 4Athabasca University

MAS Configuration File

• Simple way of defining a multi-agent system MAS my_system { infrastructure: Jade environment: MyEnv ExecuctionControl: … agents: ag1; ag2; ag3;

}

04/18/23 5Athabasca University

MAS Definition (Cont.)

• Infrastructure options: Centralized, Saci, Jade• Easy to define the host where agents and the

environment will run• If the file name with the code is unusual

agents: ag1 at host1.dur.ac.uk; agents: ag1 file1;

04/18/23 6Athabasca University

When should I Use the SACI or JADE Infrastructure?

• The centralized infrastructure does not support:– Execution of the agents at distributed hosts, and – Interoperability with non-Jason agents

• If you need any of these features, you should choose the SACI or JADE infrastructures or implement/plug a new infrastructure for/into Jason yourself).

04/18/23 7Athabasca University

Execution Modes

04/18/23 Athabasca University 8

12

3

Asynchronous Synchronous

12

3

Debug

Jason Reasoning Cycle

04/18/23 9Athabasca University

Jason Reasoning Cycle

04/18/23 10Athabasca University

Jason Reasoning Cycle

04/18/23 11Athabasca University

Belief Annotations

• Annotated predicate: ps(t1, …, tn) [a1, …, am] where ai are first order terms

• All predicates in the belief base have a special annotation source(si) where si belongs to {self, percept} or AgId

04/18/23 12Athabasca University

Example of Annotations

• An agent’s belief base with a user-defined doc annotation (degree of certainty --- doc) blue(box1)[source(ag1)] red(box1)[source(percept)] colourblind(ag1)[source(self), doc(0.7)] lier(ag1)[source(self), doc(0.2)]

04/18/23 13Athabasca University

Plan Annotations

• Plan labels also can have annotations (e.g. to specify meta-level information)

• Selection functions (Java) can use such information in plan/intention selection

• Possible to change those annotations dynamically (e.g., to update priorities)

• Annotations go in the plan label

04/18/23 14Athabasca University

Annotated Plan Example

@aPlan[ chance_of_success(0.3), usual_payoff(0.9), any_other_property]+!g(X) : c(t) <- a(X).

04/18/23 15Athabasca University

Handling Plan Failure

• Goal-deletion events were syntactically defined, but no semantics

• We use them for a plan failure handling mechanism (probably not what they were meant for)

• Handling plan failure is very important as agents are situated in dynamic environments

• A form of “contingency ( 机动 ) plan”, possibly to “clean up” before attempting another plan

04/18/23 16Athabasca University

Contingency Plan Example

• To create an agent that is blindly committed to goal g:

+!g : g <- true +!g : … <- … ?g … -!g : true <- !g

04/18/23 17Athabasca University

Internal Actions

• Unlike actions, internal actions do not change the environment

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

• AgentSpeak is meant as a high-level language for the agent’s practical reasoning

• Internal actions can be used for invoking legacy code elegantly

04/18/23 18Athabasca University

Internal Actions (Cont.)• Libraries of user-defined internal actions

lib_name.action_name(...)

• Pre-defined internal actions have an empty library name

• Internal action for communication .send(r,ilf,pc) where ilf {tell, untell, achieve, ∈

unachieve, askOne, askAll, askHow, tellHow, untellHow}

04/18/23 19Athabasca University

Internal Actions (Cont.)• Examples of BDI-related internal actions:

.desire(literal) .intend(literal) .drop_desires(literal) .drop_intentions(literal)

Many others available for: printing, list/string operations, manipulating the beliefs/annotations/plan library, creating agents, waiting/generation events, etc.

04/18/23 20Athabasca University

A Jason Plan

+green_patch(Rock) : ~battery_charge(low) & .desire(at(_)) <- .drop_desires(at(_)); dip.get_coords(Rock, Coords); !at(Coords); !examine(Rock).

04/18/23 21Athabasca University

AgentSpeak X Prolog

• With the Jason extensions, nice separation of theoretical and practical reasoning

• BDI architecture allows– long-term goals (goal-based behavior)– reacting to changes in a dynamic environment– handling multiple foci of attention (concurrency)

• Acting on an environment and a higher-level conception of a distributed system

• Direct integration with Java

04/18/23 22Athabasca University

Agent Customization• Users can customize the Agent class to define the

selection functions, social relations for communication, and belief update and revision (buf and brf)– selectMessage()– selectEvent()– selectOption()– selectIntention()– socAcc()– buf()– brf()

04/18/23 23Athabasca University

Overall Agent Architecture

• Users customize the AgentArch class to change the way the agent interacts with the infrastructure: perception, action, and communication

• Helps switching between simulation for testing and real deployment– perceive()– act()– sendMsg()– broadcast()– checkMail()

04/18/23 24Athabasca University

Belief Base Customization

• Logical belief base might not be appropriate for large applications

• Jason has an alternative belief base combined with a database

• Users can create other customization– add()– remove()– contain()– getRelevant()

04/18/23 25Athabasca University

Customized MAS

MAS Custom { agents: a1 agentClass MyAg agentBaseClass MyAgArch beliefBaseClass Jason.bb.JDBCPersistentBB( “org.hsqldb.jdbcDriver”, “jdbc:hsqldb:bookstore”, … ”[count_exec(1, tablece)]”); }

04/18/23 26Athabasca University

An Example

• Jason is available Open Source under GNU LGPL at: http://jason.sf.net

04/18/23 27Athabasca University

An Agent-based Auction Game (Simplified)

Goal Overview Diagram

04/18/23 28Athabasca University

System Overview Diagram

04/18/23 29Athabasca University

auction.mas2j

// creates an MAS called auction

MAS auction { infrastructure: Centralised

agents: ag1; ag2; ag3; auctioneer agentArchClass AuctioneerGUI;}04/18/23 30Athabasca University

Agent overview diagram:Agent Auctioneer

04/18/23 31Athabasca University

auctioneer.asl// this agent starts the auction and identify the winner/* beliefs and rules */ all_bids_received(N) :- .count(place_bid(N,_),3).

/* plans */

+!start_auction(N) : true // this goal is created by the GUI of the agent

<- -+auction(N); -+winner(N, noone, 0); .broadcast(tell, auction(N)).

// receive bid and check for new winner@pb1[atomic]+place_bid(N,V)[source(S)] : auction(N) & winner(N,CurWin,CurVl) & V > CurVl <- -winner(N,CurWin,CurVl); +winner(N,S,V); .print("New winner is ",S, " with value

",V); !check_end(N).

@pb2[atomic]+place_bid(N,_) : true <- !check_end(N).

+!check_end(N) : all_bids_received(N) & winner(N,W,Vl) <- .print("Winner is ",W," with ", Vl); show_winner(N,W); // show it in the GUI .broadcast(tell, winner(W)); .abolish(place_bid(N,_)).+!check_end(_).

04/18/23 32Athabasca University

Agent overview diagram: Agent ag1

04/18/23 33Athabasca University

ag1.asl

// this agent always bids 6

+auction(N)[source(S)] : true <- .send(S, tell, place_bid(N,6)).

04/18/23 34Athabasca University

Agent overview diagram: Agent ag2

04/18/23 35Athabasca University

ag2.asl// This agent usually bids 4, when it has an alliance with ag3, it

bids 0default_bid_value(4).ally(ag3).

+auction(N)[source(S)] : not alliance <- ?default_bid_value(B); .send(S, tell, place_bid(N,B)).+auction(N)[source(S)] : alliance <- .send(S, tell, place_bid(N,0)).

// alliance proposal from another agent+alliance[source(A)] : .my_name(I) & ally(A) <- .print("Alliance proposed by ", A); ?default_bid_value(B); .send(A,tell,bid(I,B)); .send(A,tell,alliance(A,I)).04/18/23 36Athabasca University

Agent overview diagram: Agent ag3

04/18/23 37Athabasca University

ag3.asl

// this agent bids 3, if it looses 3 auctions, it proposes an alliance to ag2 and therefore it bids 7 (3 from itself + 4 from ag2)

default_bid_value(3). ally(ag2).threshold(3).

+auction(N)[source(S)] : (threshold(T) & N < T) | (.my_name(I) & winner(I) & ally(A) & not alliance(I,A)) <- !bid_normally(S,N).+auction(N)[source(S)] : .my_name(I) & not winner(I) & ally(A) & not alliance(I,A) <- !alliance(A); !bid_normally(S,N).@palliance+auction(N)[source(S)] : alliance(_,A) <- ?default_bid_value(B); ?bid(A,C); .send(S, tell, place_bid(N,B+C)).+!bid_normally(S,N) : true <- ?default_bid_value(B); .send(S, tell,

place_bid(N,B)).@prop_alliance[breakpoint]+!alliance(A) : true <- .send(A,tell,alliance).

04/18/23 38Athabasca University

Protocol auctionName auction

Description

Included messages new auction: auctioneer agent --> ag1, ag2, ag3, bid: ag1 --> auctioneer agent, bid: ag2 --> auctioneer agent, bid: ag3 --> auctioneer agent, winner announcement: auctioneer agent --> ag1, ag2, ag3

Scenarios

Agents auctioneer agent, ag1, ag2, ag3

04/18/23 39Athabasca University

Protocol allianceName alliance

Description

Included messages alliance proposal: ag3 ag2, alliance accepted: ag2 ag3

Scenarios

Agents ag1, ag2

04/18/23 40Athabasca University

console[auctioneer] New winner is ag1 with value 6[auctioneer] Winner is ag1 with 6[auctioneer] New winner is ag3 with value 3[auctioneer] New winner is ag1 with value 6[auctioneer] Winner is ag1 with 6[auctioneer] New winner is ag2 with value 4[ag2] Alliance proposed by ag3[auctioneer] New winner is ag1 with value 6[auctioneer] Winner is ag1 with 6[auctioneer] New winner is ag1 with value 6[auctioneer] New winner is ag3 with value 7[auctioneer] Winner is ag3 with 7

04/18/23 41Athabasca University

04/18/23 42Athabasca University