multi-agent oriented programming – agent-oriented programming...

15
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 — Nov 2012 Thanks to Jomi F. H¨ ubner, 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 I Use of mentalistic notions and a societal view of computation I Various sophisticated abstractions I Agent: Belief, Goal, Intention, Plan (this course) I Organisation: Group, Role, Norm (see next course) I Interaction: Speech Acts, Interaction protocols (this course) I Environment: Artifacts, Percepts, Actions (see next course) WI Master, Nov 2012 3 / 59 Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison Agent Oriented Programming Features I Reacting to events long-term goals I Course of actions depends on circumstance I Plan failure (dynamic environments) I Rational behaviour I Social ability I Combination of theoretical and practical reasoning WI Master, Nov 2012 4 / 59

Upload: others

Post on 01-Feb-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

  • 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 — Nov 2012

    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

    I Use of mentalistic notions and a societal view of computation

    I Various sophisticated abstractionsI Agent: Belief, Goal, Intention, Plan (this course)I Organisation: Group, Role, Norm (see next course)I Interaction: Speech Acts, Interaction protocols (this course)I Environment: Artifacts, Percepts, Actions (see next course)

    WI Master, Nov 2012 3 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Agent Oriented ProgrammingFeatures

    I Reacting to events ⇥ long-term goalsI Course of actions depends on circumstance

    I Plan failure (dynamic environments)

    I Rational behaviour

    I Social ability

    I Combination of theoretical and practical reasoning

    WI Master, Nov 2012 4 / 59

  • Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Languages and Platforms

    Jason (Hübner, Bordini, ...); 3APL and 2APL (Dastani, vanRiemsdijk, Meyer, Hindriks, ...); Jadex (Braubach, Pokahr);MetateM (Fisher, Guidini, Hirsch, ...); ConGoLog (Lesperance,Levesque, ... / Boutilier – DTGolog); Teamcore/ MTDP (MilindTambe, ...); IMPACT (Subrahmanian, Kraus, Dix, Eiter); CLAIM(Amal El Fallah-Seghrouchni, ...); SemantiCore (Blois, ...);GOAL(Hindriks); BRAHMS (Sierhuis, ...); 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); ...

    WI Master, Nov 2012 5 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    AgentSpeakthe foundational language for Jason

    I Originally proposed by Rao (1996)

    I Programming language for BDI agents

    I Elegant notation, based on logic programming

    I Inspired by PRS (George↵ & Lansky), dMARS (Kinny), andBDI Logics (Rao & George↵)

    I Abstract programming language aimed at theoretical results

    WI Master, Nov 2012 6 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Jasona practical implementation of AgentSpeak

    I Jason implements the operational semantics of a variant ofAgentSpeak

    I Has various extensions aimed at a more practical programminglanguage (e.g. definition of the MAS, communication, ...)

    I Highly customised to simplify extension and experimentation

    I Developed by Rafael H. Bordini and Jomi F. Hübner

    WI Master, Nov 2012 7 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Basics

    I As in Prolog, any symbol (i.e. a sequence of characters)starting with a lowercase letter is called an atom

    I An atom is used to represent particular individuals or objects

    I A symbol starting with an uppercase letter is interpreted as alogical variable

    I Initially variables are free or uninstantiated and onceinstantiated or bound to a particular value, they maintain thatvalue throughout their scope (plan).

    I Variables are bound to values by unification ; a formula iscalled ground when it has no more uninstantiated variables.

    WI Master, Nov 2012 8 / 59

  • Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Main Language Constructs and Runtime Structures

    I Beliefs: represent the information available to an agent (e.g.about the environment or other agents)

    I Goals: represent states of a↵airs the agent wants to bringabout

    I Plans: are recipes for action, representing the agent’sknow-how

    I Events: happen as a consequence to changes in the agent’sbeliefs or goals

    I Intentions: plans instantiated to achieve some goal

    WI Master, Nov 2012 9 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Main Architectural Components

    I Belief base: where beliefs are stored

    I Set of events: to keep track of events the agent will have tohandle

    I Plan library: stores all the plans currently known by the agent

    I Set of Intentions: each intention keeps track of the goals theagent is committed to and the courses of action it chose inorder to achieve the goals for one of various foci of attentionthe agent might have

    WI Master, Nov 2012 10 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Jason basic reasoning cycle

    I perceives the environment and update belief base

    I processes new messages

    I selects event

    I selects relevant plans

    I selects applicable plans

    I creates/updates intention

    I selects intention to execute

    WI Master, Nov 2012 11 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    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)].

    WI Master, Nov 2012 12 / 59

  • Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Beliefs – Dynamics I

    by perception

    beliefs annotated with source(percept) are automatically updatedaccordingly to the perception of the agent

    by intention

    the 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)]

    WI Master, Nov 2012 13 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Beliefs – Dynamics II

    by communication

    when 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

    WI Master, Nov 2012 14 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    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)? (test goal)

    Example (initial goal of agent Tom)

    !write(book).

    WI Master, Nov 2012 15 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Goals – Dynamics I

    by intention

    the operators ! and ? can be used to add a new goal annotatedwith source(self)

    ...

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

    !write(book);

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

    ?publisher(P);

    ...

    WI Master, Nov 2012 16 / 59

  • Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Goals – Dynamics II

    by communication – achievement goal

    when 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

    WI Master, Nov 2012 17 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Goals – Dynamics III

    by communication – test goal

    when an agent receives an askOne or askAll message, the contentis 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

    WI Master, Nov 2012 18 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Events – Representation

    I Events happen as a consequence to changes in the agent’sbeliefs 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)

    WI Master, Nov 2012 19 / 59

    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

  • Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Plans – Operators for Plan Context

    Boolean operators

    & (and)

    | (or)not (not)

    = (unification)

    >, >= (relational)

  • Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Jason basic reasoning cycle

    I perceives the environment and update belief base

    I processes new messages

    I selects event

    I selects relevant plans

    I selects applicable plans

    I creates/updates intention

    I selects intention to execute

    WI Master, Nov 2012 25 / 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

    WI Master, Nov 2012 26 / 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:

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

    I when battery is low, charge

    WI Master, Nov 2012 27 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Jason vs Java II

    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));

    } } } }

    (how to code the charge battery behaviour?)

    WI Master, Nov 2012 28 / 59

  • Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Jason vs Java III

    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)

    WI Master, Nov 2012 29 / 59

    Fundamentals Features Use in MAS Perspectives Beliefs Goals Events Plans Reasoning Comparison

    Jason vs Java IV

    Example (Jason code)

    +see(gold)

  • Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations

    Negation

    Negation as failure

    I not: formula is true if the interpreter fails to derive it

    I Closed world assumption: anything that is neither known tobe true, nor derivable from the known facts using the rules inthe program, is assumed to be false.

    Strong negation

    I ~: used to express that an agent explicitly believes somethingto be false.

    WI Master, Nov 2012 33 / 59

    Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations

    Strong negation

    Example

    +!leave(home)

    : ~raining

  • Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations

    Failure handling

    Example (an agent blindly committed to g)

    +!g : g.

    +!g : ...

  • Fundamentals Features Use in MAS Perspectives Negation Rules Plan Annotations Failure Internal Actions Customisations

    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: persistent belief base(in text files, in data bases, ....)

    WI Master, Nov 2012 41 / 59

    1 Origins and Fundamentals

    2 Features

    3 Use of Jason within a Multi-Agent SystemPlatformsDefinition of a Simulated EnvironmentMAS projectTools

    4 Current Shortfalls and Future Trends

    Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools

    Execution & Communication Platform

    Di↵erent execution and communication platforms can be used withJason:

    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

    Saci: distributed agents, KQML

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

    WI Master, Nov 2012 43 / 59

    Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools

    Definition of a Simulated Environment

    I There will normally be an environment where the agents aresituated

    I The agent architecture needs to be customised to getperceptions and to act on such environment

    I We often want a simulated environment (e.g. to test a MASapplication)

    I This is done in Java by extending Jason’s Environment class

    WI Master, Nov 2012 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

    WI Master, Nov 2012 45 / 59

    Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools

    Example of an Environment Class

    1 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 } }

    WI Master, Nov 2012 46 / 59

    Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools

    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";

    }

    WI Master, Nov 2012 47 / 59

    Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools

    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 MyAgagentArchClass MyAgArchbeliefBaseClass jason.bb.JDBCPersistentBB(

    "org.hsqldb.jdbcDriver","jdbc:hsqldb:bookstore",...

    }

    WI Master, Nov 2012 48 / 59

  • Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools

    jEdit plugin

    WI Master, Nov 2012 49 / 59

    Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools

    Eclipse plugin

    WI Master, Nov 2012 50 / 59

    Fundamentals Features Use in MAS Perspectives Platforms Environment MAS project Tools

    Mind inspector

    WI Master, Nov 2012 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

    I Speech-act based communicationJoint work with Renata Vieira, Álvaro Moreira, and MikeWooldridge

    I Cooperative plan exchangeJoint work with Viviana Mascardi, Davide Ancona

    I Plan Patterns for Declarative GoalsJoint work with M.Wooldridge

    I Planning (Felipe Meneguzzi and Colleagues)

    I Web and Mobile Applications (Alessandro Ricci andColleagues)

    I Belief RevisionJoint work with Natasha Alechina, Brian Logan, Mark Jago

    WI Master, Nov 2012 53 / 59

    Fundamentals Features Use in MAS Perspectives Perspectives Summary

    Some Related Projects II

    I Ontological Reasoning

    I Joint work with Renata Vieira, Álvaro MoreiraI JASDL: joint work with Tom Klapiscak

    I Goal-Plan Tree Problem (Thangarajah et al.)Joint work with Tricia Shaw

    I Trust reasoning (ForTrust project)

    I Agent verification and model checkingJoint project with M.Fisher, M.Wooldridge, W.Visser,L.Dennis, B.Farwer

    WI Master, Nov 2012 54 / 59

    Fundamentals Features Use in MAS Perspectives Perspectives Summary

    Some Related Projects III

    I Environments, Organisation and NormsI Normative environments

    Join work with A.C.Rocha Costa and F.OkuyamaI MADeM integration (Francisco Grimaldo Moreno)I Normative integration (Felipe Meneguzzi)I CArtAgO integrationI Moise+ integration

    I More on jason.sourceforge.net, related projects

    WI Master, Nov 2012 55 / 59

    Fundamentals Features Use in MAS Perspectives Perspectives Summary

    Some Trends for Jason I

    I Modularity and encapsulationI Capabilities (JACK, Jadex, ...)I Roles (Dastani et al.)I Mini-agents (?)

    I Recently done: meta-events

    I To appear soon: annotations for declarative goals,improvement in plan failure handling, etc.

    I Debugging is hard, despite mind inspector, etc.

    I Further work on combining with environments andorganisations

    WI Master, Nov 2012 56 / 59

  • Fundamentals Features Use in MAS Perspectives Perspectives Summary

    Summary

    I AgentSpeakI Logic + BDII Agent programming

    I JasonI AgentSpeak interpreterI implements the operational semantics of AgentSpeakI speech act basedI highly customisableI useful toolsI open sourceI open issues

    WI Master, Nov 2012 57 / 59

    Fundamentals Features Use in MAS Perspectives Perspectives Summary

    More information

    I http://jason.sourceforge.net

    I Bordini, R. H., Hübner, J. F., andWooldrige, M.Programming Multi-Agent Systems inAgentSpeak using JasonJohn Wiley & Sons, 2007.

    WI Master, Nov 2012 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 in Computer Science, pages 42–55. Springer.

    WI Master, Nov 2012 59 / 59