Introduction to AgentSpeak and Jason for Programming Multi

Download Report

Transcript Introduction to AgentSpeak and Jason for Programming Multi

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
Plan
library
Beliefs
Interpreter
Sensor input
Action output
Desires
7/7/2015
Intentions
Athabasca University
2
Introduction
• Jason is a fully-fledged interpreter for an
extended version of AgentSpeak, a BDI agentoriented logic programming language, and is
implemented in Java. Using SACI or JADE, a
multi-agent system can be distributed over a
network effortlessly.
7/7/2015
Athabasca University
3
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.
7/7/2015
Athabasca University
4
MAS Configuration File
• Simple way of defining a multi-agent system
MAS my_system {
infrastructure: Jade
environment: MyEnv
ExecuctionControl: …
agents: ag1; ag2; ag3;
}
7/7/2015
Athabasca University
5
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;
7/7/2015
Athabasca University
6
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).
7/7/2015
Athabasca University
7
Execution Modes
3
1
3
2
Asynchronous
Synchronous
7/7/2015
Athabasca University
1
2
Debug
8
Jason Reasoning Cycle
7/7/2015
Athabasca University
9
Jason Reasoning Cycle
7/7/2015
Athabasca University
10
Jason Reasoning Cycle
7/7/2015
Athabasca University
11
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
7/7/2015
Athabasca University
12
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)]
7/7/2015
Athabasca University
13
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
7/7/2015
Athabasca University
14
Annotated Plan Example
@aPlan[
chance_of_success(0.3),
usual_payoff(0.9),
any_other_property]
+!g(X)
: c(t)
<- a(X).
7/7/2015
Athabasca University
15
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
7/7/2015
Athabasca University
16
Contingency Plan Example
• To create an agent that is blindly committed to
goal g:
+!g : g <- true
+!g : … <- … ?g
…
-!g : true <- !g
7/7/2015
Athabasca University
17
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
7/7/2015
Athabasca University
18
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}
7/7/2015
Athabasca University
19
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.
7/7/2015
Athabasca University
20
A Jason Plan
+green_patch(Rock)
: ~battery_charge(low)
& .desire(at(_))
<- .drop_desires(at(_));
dip.get_coords(Rock, Coords);
!at(Coords);
!examine(Rock).
7/7/2015
Athabasca University
21
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
7/7/2015
Athabasca University
22
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()
7/7/2015
Athabasca University
23
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()
7/7/2015
– checkMail()
Athabasca University
24
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
–
–
–
–
7/7/2015
add()
remove()
contain()
getRelevant()
Athabasca University
25
Customized MAS
MAS Custom {
agents:
a1 agentClass MyAg
agentBaseClass MyAgArch
beliefBaseClass Jason.bb.JDBCPersistentBB(
“org.hsqldb.jdbcDriver”,
“jdbc:hsqldb:bookstore”,
…
”[count_exec(1, tablece)]”);
}
7/7/2015
Athabasca University
26
An Example
• Jason is available Open Source under GNU
LGPL at: http://jason.sf.net
7/7/2015
Athabasca University
27
An Agent-based Auction Game (Simplified)
Goal Overview Diagram
7/7/2015
Athabasca University
28
System Overview Diagram
7/7/2015
Athabasca University
29
auction.mas2j
// creates an MAS called auction
MAS auction {
infrastructure: Centralised
agents: ag1; ag2; ag3;
auctioneer agentArchClass AuctioneerGUI;
}
7/7/2015
Athabasca University
30
Agent overview diagram:
Agent Auctioneer
7/7/2015
Athabasca University
31
// this agent starts the auction and identify the winner
/* beliefs and rules */
all_bids_received(N) :- .count(place_bid(N,_),3).
auctioneer.asl
/* 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).
7/7/2015
Athabasca University
@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(_).
32
Agent overview diagram:
Agent ag1
7/7/2015
Athabasca University
33
ag1.asl
// this agent always bids 6
+auction(N)[source(S)] : true
<- .send(S, tell, place_bid(N,6)).
7/7/2015
Athabasca University
34
Agent overview diagram:
Agent ag2
7/7/2015
Athabasca University
35
// This agent usually bids 4, when it has an alliance with ag3, it
bids 0
default_bid_value(4).
ally(ag3).
ag2.asl
+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)).
7/7/2015
Athabasca University
36
Agent overview diagram:
Agent ag3
7/7/2015
Athabasca University
37
// 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).
ag3.asl
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).
7/7/2015
Athabasca University
38
Protocol auction
Name
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
7/7/2015
auctioneer agent, ag1, ag2, ag3
Athabasca University
39
Protocol alliance
Name
alliance
Description
Included messages
alliance proposal: ag3  ag2,
alliance accepted: ag2  ag3
Scenarios
Agents
7/7/2015
ag1, ag2
Athabasca University
40
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
7/7/2015
Athabasca University
41
7/7/2015
Athabasca University
42