Multi-Agent Oriented Programming – Agent-Oriented Programming – The Jason Agent Programming Language Olivier Boissier ENS Mines Saint-Etienne http://www.emse.fr/~boissier “Web Intelligence” Master — October 2013 Thanks to Jomi F. Hübner, UFSC/DAS Brazil and Rafael H. Bordini PUCRS Brazil for providing most of the slides Outline 1 Origins and Fundamentals 2 Features 3 Use of Jason within a Multi-Agent System 4 Current Shortfalls and Future Trends Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison Agent Oriented Programming Use of mentalistic notions and a societal view of computation Various sophisticated abstractions Agent: Belief, Goal, Intention, Plan (this course) Organisation: Group, Role, Norm (see next course) Interaction: Speech Acts, Interaction protocols (this course) Environment: Artifacts, Percepts, Actions (see next course) “Web Intelligence” Master, October 2013 3 / 59 Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison Agent Oriented Programming Features Reacting to events ⇥ long-term goals Course of actions depends on circumstance Plan failure (dynamic environments) Rational behaviour Social ability Combination of theoretical and practical reasoning “Web Intelligence” Master, October 2013 4 / 59
15
Embed
Multi-Agent Oriented Programming – Agent-Oriented ...boissier/enseignement/maop13/courses/aop-4pp.pdf · Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans
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.
Thanks to Jomi F. Hübner, UFSC/DAS Braziland Rafael H. Bordini PUCRS Brazil for providing most of the slides
Outline
1 Origins and Fundamentals
2 Features
3 Use of Jason within a Multi-Agent System
4 Current Shortfalls and Future Trends
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Agent Oriented Programming
Use of mentalistic notions and a societal view of computation
Various sophisticated abstractionsAgent: Belief, Goal, Intention, Plan (this course)Organisation: Group, Role, Norm (see next course)Interaction: Speech Acts, Interaction protocols (this course)Environment: Artifacts, Percepts, Actions (see next course)
“Web Intelligence” Master, October 2013 3 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Agent Oriented ProgrammingFeatures
Reacting to events ⇥ long-term goalsCourse of actions depends on circumstancePlan failure (dynamic environments)Rational behaviourSocial abilityCombination of theoretical and practical reasoning
“Web Intelligence” Master, October 2013 4 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
AgentSpeakthe foundational language for Jason
Originally proposed by Rao (1996)Programming language for BDI agentsElegant notation, based on logic programmingInspired by PRS (Georgeff & Lansky), dMARS (Kinny), and BDILogics (Rao & Georgeff)Abstract programming language aimed at theoretical results
“Web Intelligence” Master, October 2013 6 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Jasona practical implementation of AgentSpeak
Jason implements the operational semantics of a variant ofAgentSpeakHas various extensions aimed at a more practical programminglanguage (e.g. definition of the MAS, communication, ...)Highly customised to simplify extension and experimentationDeveloped by Rafael H. Bordini and Jomi F. Hübner
“Web Intelligence” Master, October 2013 7 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Basics
As in Prolog, any symbol (i.e. a sequence of characters) startingwith a lowercase letter is called an atomAn atom is used to represent particular individuals or objectsA symbol starting with an uppercase letter is interpreted as alogical variableInitially variables are free or uninstantiated and once instantiatedor bound to a particular value, they maintain that valuethroughout their scope (plan).Variables are bound to values by unification ; a formula is calledground when it has no more uninstantiated variables.
“Web Intelligence” Master, October 2013 8 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
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 aboutPlans: are recipes for action, representing the agent’s know-howEvents: happen as a consequence to changes in the agent’sbeliefs or goalsIntentions: plans instantiated to achieve some goal
“Web Intelligence” Master, October 2013 9 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Main Architectural Components
Belief base: where beliefs are storedSet of events: to keep track of events the agent will have tohandlePlan library: stores all the plans currently known by the agentSet of Intentions: each intention keeps track of the goals theagent is committed to and the courses of action it chose in orderto achieve the goals for one of various foci of attention the agentmight have
“Web Intelligence” Master, October 2013 10 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Jason basic reasoning cycle
perceives the environment and update belief baseprocesses new messagesselects eventselects relevant plansselects applicable planscreates/updates intentionselects intention to execute
“Web Intelligence” Master, October 2013 11 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Jason Architecture
SI
EventsExternal
EventSelected
SE
Beliefs toAdd and
Delete
RelevantPlans
New PlanPush
IntentionUpdated
OS
ApplicablePlans
MeansIntended
EventsExternal
PlanLibrary
Events
InternalEvents
3
checkMail
Intentions
ExecuteIntention
...NewNew
9
BeliefBase
NewIntention
Percepts
act
SelectedIntention
Intentions
Action
Percepts1 2
BUF
10
Events
ContextCheck
EventUnify
BRF
Beliefs
Agent
sendMsg
Beliefs
8
Messages
Plans
perceive
7
5
6
Actions
Beliefs
Suspended Intentions(Actions and Msgs)
...
.send
SocAcc
4
Messages MessagesSM
“Web Intelligence” Master, October 2013 12 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Beliefs – Representation
SyntaxBeliefs are represented by annotated literals of first order logic
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Beliefs – Dynamics I
by perceptionbeliefs annotated with source(percept) are automatically updatedaccordingly to the perception of the agent
by intentionthe operators + and - can be used to add and remove beliefsannotated with source(self)
+lier(alice); // adds lier(alice)[source(self)]
-lier(john); // removes lier(john)[source(self)]
-+lier(john); // updates lier(john)[source(self)]
“Web Intelligence” Master, October 2013 14 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Beliefs – Dynamics II
by communicationwhen an agent receives a tell message, the content is a new beliefannotated 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
“Web Intelligence” Master, October 2013 15 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Goals – Representation
Types of goalsAchievement goal: goal to doTest goal: goal to know
SyntaxGoals have the same syntax as beliefs, but are prefixed by! (achievement goal)? (test goal)
Example (initial goal of agent Tom)
!write(book).
“Web Intelligence” Master, October 2013 16 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Goals – Dynamics I
by intentionthe operators ! and ? can be used to add a new goal annotated withsource(self)
...// adds new achievement goal !write(book)[source(self)]
!write(book);
// adds new test goal ?publisher(P)[source(self)]
?publisher(P);...
“Web Intelligence” Master, October 2013 17 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Goals – Dynamics II
by communication – achievement goalwhen an agent receives an achieve message, the content is a newachievement 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
“Web Intelligence” Master, October 2013 18 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Goals – Dynamics III
by communication – test goalwhen an agent receives an askOne or askAll message, the content isa 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
“Web Intelligence” Master, October 2013 19 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Events – Representation
Events happen as a consequence to changes in the agent’sbeliefs or goalsAn agent reacts to events by executing plansTypes of plan triggering events
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Plans – Representation
An AgentSpeak plan has the following general structure:
triggering_event : context <- body.
where:the triggering event denotes the events that the plan is meant tohandle (cf. events description)the context represents the circumstances in which the plan canbe usedthe body is the course of action to be used to handle the event ifthe context is believed to be true at the time a plan is beingchosen to handle the event
“Web Intelligence” Master, October 2013 21 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Plans – Operators for Plan Body
A plan body may contain:Belief operators (+, -, -+)Goal operators (!, ?, !!)Actions (internal/external) and Constraints
Example (plan’s body)
+beer : time_to_leave(T) & clock.now(H) & H >= T<- !g1; // new sub-goal suspending plan execution
!!g2; // new goal not suspending plan execution
+b1(T-H); // adds new belief
-+b2(T*H); // updates belief
?b(X); // new test goal
X > 10; // constraint to carry on
close(door).// external action
“Web Intelligence” Master, October 2013 23 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
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).
“Web Intelligence” Master, October 2013 24 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Plans – Dynamics
The plans that form the plan library of the agent comes from:initial plans defined by the programmerplans added dynamically and intentionally by
.add_plan
.remove_planplans received from messages of type:
tellHowuntellHow
messages
“Web Intelligence” Master, October 2013 25 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Jason basic reasoning cycle
perceives the environment and update belief baseprocesses new messagesselects eventselects relevant plansselects applicable planscreates/updates intentionselects intention to execute
“Web Intelligence” Master, October 2013 26 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Jason reasoning cycle
SI
EventsExternal
EventSelected
SE
Beliefs toAdd and
Delete
RelevantPlans
New PlanPush
IntentionUpdated
OS
ApplicablePlans
MeansIntended
EventsExternal
PlanLibrary
Events
InternalEvents
3
checkMail
Intentions
ExecuteIntention
...NewNew
9
BeliefBase
NewIntention
Percepts
act
SelectedIntention
Intentions
Action
Percepts1 2
BUF
10
Events
ContextCheck
EventUnify
BRF
Beliefs
Agent
sendMsg
Beliefs
8
Messages
Plans
perceive
7
5
6
Actions
Beliefs
Suspended Intentions(Actions and Msgs)
...
.send
SocAcc
4
Messages MessagesSM
“Web Intelligence” Master, October 2013 27 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Jason vs Java I
Consider a very simple robot with two goals:when a piece of gold is seen, go to itwhen battery is low, charge
Example (Java code – go to gold)public class Robot extends Thread {
boolean seeGold, lowBattery;public void run() {
while (true) {while (! seeGold) {}while (seeGold) {
a = selectDirection();
doAction(go(a));
} } } }
“Web Intelligence” Master, October 2013 28 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Jason vs Java II
(how to code the charge battery behaviour?)
Example (Java code – charge battery)public class Robot extends Thread {
boolean seeGold, lowBattery;public void run() {
while (true) {while (! seeGold)
if (lowBattery) charge();while (seeGold) {
a = selectDirection ();if (lowBattery) charge();doAction(go(a));if (lowBattery) charge();
} } } }
(note where the test for low battery have to be done)
“Web Intelligence” Master, October 2013 29 / 59
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Jason vs Java III
Example (Jason code)
+see(gold)<- !goto(gold).
+!goto(gold) : see(gold) // long term goal<- !select_direction(A);
Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison
Jason vs Prolog
With the Jason extensions, nice separation of theoretical andpractical reasoning
BDI architecture allowslong-term goals (goal-based behaviour)reacting to changes in a dynamic environmenthandling multiple foci of attention (concurrency)
Acting on an environment and a higher-level conception of adistributed system
Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations
Negation
Negation as failurenot: formula is true if the interpreter fails to derive itClosed world assumption: anything that is neither known to betrue, nor derivable from the known facts using the rules in theprogram, is assumed to be false.
Strong negation~: used to express that an agent explicitly believes something tobe false.
“Web Intelligence” Master, October 2013 33 / 59
Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations
Strong negation
Example
+!leave(home): ~raining<- open(curtains); ...
+!leave(home): not raining & not ~raining<- .send(mum,askOne,raining,Answer,3000); ...
“Web Intelligence” Master, October 2013 34 / 59
Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations
Prolog-like Rules in the Belief Base
RulesRules can be used to simplify certain taks, i.e. making certainconditions used in plans more succinct.Their syntax is similar to the one used for plans.
Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations
Plan Annotations
Like beliefs, plans can also have annotations, which go in theplan labelAnnotations contain meta-level information for the plan, whichselection functions can take into considerationThe annotations in an intended plan instance can be changeddynamically (e.g. to change intention priorities)There are some pre-defined plan annotations, e.g. to force abreakpoint at that plan or to make the whole plan executeatomically
in the event of a failure to achieve any goal G due to norelevant plan, asks a teacher for plans to achieve G and thentry G again
The failure event is annotated with the error type, line, source, ...error(no_relevant) means no plan in the agent’s plan library toachieve G{ +!G } is the syntax to enclose triggers/plans as terms
“Web Intelligence” Master, October 2013 38 / 59
Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations
Internal Actions
Unlike actions, internal actions do not change the environmentCode to be executed as part of the agent reasoning cycleAgentSpeak is meant as a high-level language for the agent’spractical reasoning and internal actions can be used for invokinglegacy code elegantly
Internal actions can be defined by the user in Java
libname.action_name(. . .)
“Web Intelligence” Master, October 2013 39 / 59
Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations
Standard Internal Actions
Standard (pre-defined) internal actions have an empty libraryname
.print(term1, term2, . . .)
.union(list1, list2, list3)
.my_name(var)
.send(ag,perf,literal)
.intend(literal)
.drop_intention(literal)
Many others available for: printing, sorting, list/string operations,manipulating the beliefs/annotations/plan library, creating agents,waiting/generating events, etc.
“Web Intelligence” Master, October 2013 40 / 59
Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations
Jason Customisations
Agent class customisation:selectMessage, selectEvent, selectOption, selectIntetion, buf,brf, ...
Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools
Definition of a Simulated Environment
There will normally be an environment where the agents aresituatedThe agent architecture needs to be customised to getperceptions and to act on such environmentWe often want a simulated environment (e.g. to test a MASapplication)This is done in Java by extending Jason’s Environment class
“Web Intelligence” Master, October 2013 44 / 59
Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools
Interaction with the Environment Simulator
EnvironmentSimulator
Agent Architecture
executeAction
getPercepts
changepercepts
Reasoner
perceive
act
“Web Intelligence” Master, October 2013 45 / 59
Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools
Example of an Environment Class1 import jason.*;2 import ...;3 public class robotEnv extends Environment {4 ....5 public robotEnv() {6 Literal gp =7 Literal.parseLiteral("green_patch(souffle)");8 addPercept(gp);9 }
1011 public boolean executeAction(String ag, Structure action) {12 if (action.equals(...)) {13 addPercept(ag,14 Literal.parseLiteral("location(souffle,c(3,4))");15 }16 ...17 return true;18 } }
“Web Intelligence” Master, October 2013 46 / 59
Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools
MAS Configuration Language I
Simple way of defining a multi-agent system
Example (MAS that uses JADE as infrastructure)MAS my_system {
infrastructure: Jadeenvironment: robotEnvagents:
c3po;r2d2 at jason.sourceforge.net;bob #10; // 10 instances of bob
classpath: "../lib/graph.jar";}
“Web Intelligence” Master, October 2013 47 / 59
Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools
MAS Configuration Language II
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"]
Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools
jEdit plugin
“Web Intelligence” Master, October 2013 49 / 59
Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools
Eclipse plugin
“Web Intelligence” Master, October 2013 50 / 59
Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools
Mind inspector
“Web Intelligence” Master, October 2013 51 / 59
1 Origins and Fundamentals
2 Features
3 Use of Jason within a Multi-Agent System
4 Current Shortfalls and Future TrendsPerspectives: Some Past and Future ProjectsSummary
Fundamentals Features Use in MAS Perspectives Perspectives Summary
Some Related Projects I
Speech-act based communicationJoint work with Renata Vieira, Álvaro Moreira, and MikeWooldridgeCooperative plan exchangeJoint work with Viviana Mascardi, Davide AnconaPlan Patterns for Declarative GoalsJoint work with M.WooldridgePlanning (Felipe Meneguzzi and Colleagues)Web and Mobile Applications (Alessandro Ricci and Colleagues)Belief RevisionJoint work with Natasha Alechina, Brian Logan, Mark Jago
“Web Intelligence” Master, October 2013 53 / 59
Fundamentals Features Use in MAS Perspectives Perspectives Summary
Some Related Projects II
Ontological ReasoningJoint work with Renata Vieira, Álvaro MoreiraJASDL: joint work with Tom Klapiscak
Goal-Plan Tree Problem (Thangarajah et al.)Joint work with Tricia ShawTrust reasoning (ForTrust project)Agent verification and model checkingJoint project with M.Fisher, M.Wooldridge, W.Visser, L.Dennis,B.Farwer
“Web Intelligence” Master, October 2013 54 / 59
Fundamentals Features Use in MAS Perspectives Perspectives Summary
Some Related Projects III
Environments, Organisation and NormsNormative environmentsJoin work with A.C.Rocha Costa and F.OkuyamaMADeM integration (Francisco Grimaldo Moreno)Normative integration (Felipe Meneguzzi)CArtAgO integrationM OISE+ integration
More on jason.sourceforge.net, related projects
“Web Intelligence” Master, October 2013 55 / 59
Fundamentals Features Use in MAS Perspectives Perspectives Summary
Some Trends for Jason I
Modularity and encapsulationCapabilities (JACK, Jadex, ...)Roles (Dastani et al.)Mini-agents (?)
Recently done: meta-eventsTo appear soon: annotations for declarative goals, improvementin plan failure handling, etc.Debugging is hard, despite mind inspector, etc.Further work on combining with environments and organisations
“Web Intelligence” Master, October 2013 56 / 59
Fundamentals Features Use in MAS Perspectives Perspectives Summary
Summary
AgentSpeakLogic + BDIAgent programming
JasonAgentSpeak interpreterimplements the operational semantics of AgentSpeakspeech act basedhighly customisableuseful toolsopen sourceopen issues
“Web Intelligence” Master, October 2013 57 / 59
Fundamentals Features Use in MAS Perspectives Perspectives Summary
More information
http://jason.sourceforge.net
Bordini, R. H., Hübner, J. F., and Wooldrige,M.Programming Multi-Agent Systems inAgentSpeak using JasonJohn Wiley & Sons, 2007.
“Web Intelligence” Master, October 2013 58 / 59
Fundamentals Features Use in MAS Perspectives Perspectives Summary
Bibliography I
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 inComputer Science, pages 42–55. Springer.