460 likes | 670 Views
Introduction to AgentSpeak and Jason for Programming Multi-agent Systems (2). Dr Fuhua (Oscar) Lin SCIS Athabasca University June 19, 2009. The Procedural Reasoning System. Beliefs. Plan library. Sensor input. Interpreter. Action output. Desires. Intentions. Introduction.
E N D
Introduction to AgentSpeak and Jason for Programming Multi-agent Systems(2) Dr Fuhua (Oscar) Lin SCIS Athabasca University June 19, 2009
The Procedural Reasoning System Beliefs Plan library Sensor input Interpreter Action output Desires Intentions Athabasca University
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. Athabasca 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. Athabasca University
MAS Configuration File • Simple way of defining a multi-agent system MAS my_system { infrastructure: Jade environment: MyEnv ExecuctionControl: … agents: ag1; ag2; ag3; } Athabasca 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; Athabasca 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). Athabasca University
Execution Modes 3 3 2 2 1 1 Asynchronous Synchronous Debug Athabasca University
Jason Reasoning Cycle Athabasca University
Jason Reasoning Cycle Athabasca University
Jason Reasoning Cycle Athabasca 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 Athabasca 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)] Athabasca 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 Athabasca University
Annotated Plan Example @aPlan[ chance_of_success(0.3), usual_payoff(0.9), any_other_property] +!g(X) : c(t) <- a(X). Athabasca 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 Athabasca University
Contingency Plan Example • To create an agent that is blindly committed to goal g: +!g : g <- true +!g : … <- … ?g … -!g : true <- !g Athabasca 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 Athabasca 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} Athabasca 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. Athabasca University
A Jason Plan +green_patch(Rock) : ~battery_charge(low) & .desire(at(_)) <- .drop_desires(at(_)); dip.get_coords(Rock, Coords); !at(Coords); !examine(Rock). Athabasca 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 Athabasca 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() Athabasca 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() Athabasca 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() Athabasca 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)]”); } Athabasca University
An Example • Jason is available Open Source under GNU LGPL at: http://jason.sf.net Athabasca University
An Agent-based Auction Game (Simplified)Goal Overview Diagram Athabasca University
System Overview Diagram Athabasca University
auction.mas2j // creates an MAS called auction MAS auction { infrastructure: Centralised agents: ag1; ag2; ag3; auctioneer agentArchClass AuctioneerGUI; } Athabasca University
Agent overview diagram:Agent Auctioneer Athabasca 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(_). Athabasca University
Agent overview diagram: Agent ag1 Athabasca University
ag1.asl // this agent always bids 6 +auction(N)[source(S)] : true <- .send(S, tell, place_bid(N,6)). Athabasca University
Agent overview diagram: Agent ag2 Athabasca University
ag2.asl // This agent usually bids 4, when it has an alliance with ag3, it bids 0 default_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)). Athabasca University
Agent overview diagram: Agent ag3 Athabasca 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). Athabasca University
Protocol auction Athabasca University
Protocol alliance Athabasca 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 Athabasca University