seminario ciia@uv · 2018-08-28 · jason reasoning cycle. 13 extensions on beliefs (1/3) ......

43
1 Seminario [email protected] Programming Multi-Agent Systems in AgentSpeak Using Jason Departament d'Informàtica Escola Tècnica Superior d'Enginyeria Universitat de València Francisco Grimaldo Moreno http://www.uv.es/grimo

Upload: others

Post on 02-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

1

Seminario [email protected]

Programming Multi-Agent Systems in AgentSpeak Using Jason

Departament d'InformàticaEscola Tècnica Superior d'Enginyeria

Universitat de València

Francisco Grimaldo Morenohttp://www.uv.es/grimo

Page 2: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

2

Outline

■ AgentSpeak.

■ Introduction to Jason.

■ Developing Multi-Agent Systems.

■ Jason GUI & Eclipse Plugin.

■ References & Examples.

■ Library extensions & Useful Tips.

Page 3: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

3

AgentSpeak (1/2)

■ Originally proposed by Rao [MAAMAW 1996].

■ Programming language for BDI agents.

■ Elegant notation, based on logic programming.

■ Inspired by PRS (Georgeff & Lansky), dMARS (Kinny), and BDI Logics (Rao & Georgeff)

■ Abstract programming language aimed at theoretical results

Page 4: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

4

AgentSpeak (2/2)

■ The main language constructs of AgentSpeak are:

Beliefs Goals (Desires) Plans (Intentions)

■ The architecture of an AgentSpeak agent has four

main components:

Belief Base Plan Library Set of Events Set of Intentions (instantiated plans)

Page 5: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

5

Overview of a MAS in Jason

Page 6: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

6

Syntax of AgentSpeak Beliefs & Goals

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

publisher(wiley)

■ Goals represent states of affairs the agent wants to bring about (come to believe, when goals are used declaratively)

Achievement goals: !write(book)

Or attempts to retrieve information from the belief base (test goals):

?publisher(P)

Page 7: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

7

Syntax of AgentSpeak Events

■ An agent reacts to events by executing plans.

■ Events happen as a consequence to changes in the agent’s beliefs or goals.

■ AgentSpeak triggering events: +b (belief addition) -b (belief deletion) +!g (achievement-goal addition) -!g (achievement-goal deletion) +?g (test-goal addition) -?g (test-goal deletion)

Page 8: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

8

Syntax of AgentSpeak Plans (1/2)

■ Plans are recipes for action, representing the agent’s know-how, with the following structure:

triggering_event : context <- body.■ where:

the triggering event denotes the events that the plan is meant to handle.

the context represent the circumstances in which the plan can be used (i.e. the conjunction of literals to be checked whether they follow from the current state of the belief base);

the body is the course of action to be used to handle the event if the context is believed true at the time a plan is being chosen to handle the event (i.e. the sequence of actions and (sub) goals to achieve).

Page 9: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

9

Syntax of AgentSpeak Plans (2/2)

■ Example of plans:

Page 10: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

10

Outline

■ AgentSpeak.

■ Introduction to Jason.

■ Developing Multi-Agent Systems.

■ Jason GUI & Eclipse Plugin.

■ References & Examples.

■ Library extensions & Useful Tips.

Page 11: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

11

Jason overview

■ Java-based platform for developing MAS.

■ Implements the operational semantics of an extended version of AgentSpeak (AS).

■ It supports the original AS syntax and allows other things in the context and body of plans.

■ Various extensions aimed at a more practical programming language.

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

Page 12: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

12

Jason Reasoning Cycle

Page 13: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

13

Extensions on Beliefs (1/3)

■ Each belief is an annotated predicate: ps(t1,...,tn)[a1,...,am]■ where a

i are first order terms.

■ All predicates in the belief base have a special annotation: source(s

i)

■ where si ϵ {self,percept} U AgId.

■ An agent’s belief base with a user-defined doc annotation (degree of certainty):

blue(box1)[source(ag1)]. red(box1)[source(percept)]. colourblind(ag1)[source(self),doc(0.7)]. lier(ag1)[source(self),doc(0.2)].

Page 14: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

14

Extensions on Beliefs (2/3)

■ Prolog-like rules are allowed in the belief base:

likely_color(Obj,C) :- colour(Obj,C)[degOfCert(D1)] & not ( colour(Obj,_)[degOfCert(D2)] & D2 > D1 ).

■ These beliefs are dynamically inferred when invoked within plan contexts or test goals:

+!price_insurance(car, P) : likely_color(car,red) ?number_friends(N)

Page 15: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

15

Extensions on Beliefs (3/3)

■ The operator ‘~’ is used for strong negation:

Page 16: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

16

Extensions on Plans

■ Plans can also be annotated through their labels to specify meta-level information.

■ Example: Selection functions (Java) can use such information in plan/intention selection

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

Page 17: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

17

Handling plan failure

■ Goal-deletion events in AgentSpeak were syntactically defined (-!g), but no semantics.

■ Jason uses them for plan failure handling (probably not what they were meant for).

■ Handling plan failures is very important as agents are situated in dynamic environments.

■ A form of “contingency plan”, possibly to “clean up” before attempting another plan.

■ To create an agent blindly committed to a goal:

Page 18: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

18

Plan bodies

■ Plan bodies invoke:

Belief add/del.

Test goals.

Achieve goals.

Environment actions.

Internal Actions:➔ Predefined.➔ User-defined.

Page 19: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

19

Internal actions (1/2)

■ Unlike environment actions, internal actions do not change the environment.

■ Code to be executed as part of the agent reasoning cycle.

■ Internal actions can be used for invoking legacy code elegantly.

■ Example: Predefined (i.e no library name) internal action for communication:

Page 20: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

20

Internal actions (2/2)

■ Other examples of BDI-related internal actions: .desire(literal) .intend(literal) .drop_desires(literal) .drop_intentions(literal)

■ Many others available for: printing, sorting, list/string operations, manipulating the

beliefs/annotations/plan library, creating agents, waiting/generating events, etc.

■ Libraries of user-defined internal actions: lib_name.action_name(...)

Page 21: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

21

Outline

■ AgentSpeak.

■ Introduction to Jason.

■ Developing Multi-Agent Systems.

■ Jason GUI & Eclipse Plugin.

■ References & Examples.

■ Library extensions & Useful Tips.

Page 22: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

22

MAS configuration file

MAS my_system {

infrastructure: Jade

environment: MyEnv

ExecuctionControl: …

agents: ag1; ag2; ag3;}

Page 23: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

23

Infrastructures

■ Centralized: + Easy to launch and run - Scalability

■ [JaCaMo] (changes after Jason 2.0): + Distributed artifacts (workload) - Mostly centralized agents (comunication) - Difficult to launch and program

■ Jade: + Distributed agents and monitoring - Difficult to launch and program

Page 24: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

24

Centralized concurrency models (1/2)■ Infrastructure configuration:

Centralised(threaded, <NUMBER-CYCLES-SENSE>, <NUMBER-CYCLES-DELIBERATE>, <NUMBER-CYCLES-ACT>)

Centralised(pool, <NUMBER-THREADS>, [NUMBER-REASONING-CYCLES])

Centralised(pool, <NUMBER-THREADS>, <NUMBER-CYCLES-SENSE>, <NUMBER-CYCLES-DELIBERATE>, <NUMBER-CYCLES-ACT>, [NUMBER-REASONING-CYCLES])

Centralised(synch_scheduled, <NUMBER-CYCLES-SENSE>, <NUMBER-CYCLES-DELIBERATE>, <NUMBER-CYCLES-ACT>)

Centralised(asynch_shared, <NUMBER-THREADS>, <NUMBER-CYCLES-SENSE>, <NUMBER-CYCLES-DELIBERATE>, <NUMBER-CYCLES-ACT>)

Page 25: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

25

Centralized concurrency models (2/2)■ Infrastructure configuration:

Centralised(asynch, <NUMBER-THREADS-SENSE>, <NUMBER-THREADS-DELIBERATE>, <NUMBER-THREADS-ACT>, <NUMBER-CYCLES-SENSE>, <NUMBER-CYCLES-DELIBERATE>, <NUMBER-CYCLES-ACT>)

agName_1 [cycles_sense = x, cycles_deliberate = y, cycles_act = z];

agName_2 [cycles = t];

Page 26: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

26

MAS definition

■ Infrastructures available: Centralised Jade (Distributed).

■ Easy to define the host where agents and the environment will run:

ag1 at bvnto.labss.istc.cnr.it;■ If the file name with the code is unusual agents: agents: ag1 file.asl;■ Multiple instances of an agent: agents: ag1 #10;■ Interpreter configuration (frequency of perception,

event handling, system messages, etc.): agents: ag1 [conf=option];

Page 27: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

27

Agent customisation

■ Users can customise the Agent class to define the selection functions, social relations for communication, and belief update and revision:

selectMessage(), selectEvent(), selectOption(), selectIntention(), socAcc(), buf(), brf()

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

perceive(), act(), sendMsg(), broadcast(), checkMail()

■ Helps switching between simulation for testing and real deployment.

Page 28: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

28

Environments

■ In actual deployment, there will normally be an environment where the agents are situated.

■ As discussed earlier, the AgentArchitecture needs to be customised to get perceptions and act on such environment.

■ We often want a simulated environment (e.g., to test a MAS application).

■ This is done in Java by extending Jason’s Environment class and using methods such as addPercept(String Agent, Literal Percept).

Page 29: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

29

Environments and execution models

■ Jason Environments: Environment (executeAction) TimeSteppedEnvironment (stepStarted, stepFinished) GridWorldModel and GridWorldView

■ Cartago Environments: Action on artifacts ditributed among workspaces Mixed environments (demo)

■ Execution modes: Asynchronous, sinchronous, debug, personalized. Add to the mas2j configuration file:

➔ executionControl: jason.control.ExecutionControl[GUI]

Page 30: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

30

Outline

■ AgentSpeak.

■ Introduction to Jason.

■ Developing Multi-Agent Systems.

■ Jason GUI & Eclipse Plugin.

■ References & Examples.

■ Library extensions & Useful Tips.

Page 31: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

31

Jason GUI

■ Available Open Source under GNU LGPL at: http://jason.sourceforge.net

Page 32: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

32

Jason's Mind Inspector

Page 33: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

33

References & Examples

■ Jason website: Jason download. Documents. Examples. Demos. Related projects. Etc.

■ http://jason.sourceforge.net

Page 34: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

34

New references to arrive

Page 35: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

35

Outline

■ AgentSpeak.

■ Introduction to Jason.

■ Developing Multi-Agent Systems.

■ Jason GUI & Eclipse Plugin.

■ References & Examples.

■ Library extensions & Useful Tips.

Page 36: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

36

Organizations in Moise+

■ MOISE+: model to build organizations in MAS.

■ Points of view: Structural: roles,

groups,communication and authoritylinks...

Functional: goals, plans,missions, norms...

Deontic: Relates roles tomissions.

Page 37: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

37

J-Moise+ internal actions■ create/remove

group

■ add responsible group

■ adopt/remove role

■ set goal arguments

■ set goal state

■ commit mission

■ remove mission

Page 38: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

38

Asincronía vs sincronía

■ Atención a los posibles cuellos de botella

■ Artefactos: Operaciones síncronas

Usar artifact_name en las llamadas a las operaciones

Limitar las propiedades observables y focalizaciones

Compromiso entre artefactos de utilidades compartidos e individuales

■ Acciones internas y funciones aritméticas

Page 39: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

39

Paralelismo vs serialización

■ Orden de ejecución no controlable al 100%

■ Problemas de acceso concurrente y actualización de las percepciones

■ Competición por recursos compartidos

■ Variables/acciones de acceso exclusivo [atomic]

■ Dilema entre des-sincronizar y sincronizar

Page 40: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

40

Iniciación del sistema (en Jason)

■ A través del entorno: TimeSteppedEnvironment → stepStarted

■ A través de un agente controlador: Suele convenir realizar un “saludo a tres bandas”

■ A través de un artefacto: Reloj o sistema de tiempo del espacio de trabajo Mantenimiento de variable observable temporal Envío de señal de inicio

■ Suele ser interesante dejar un tiempo inicial para garantizar que la inicialización se realice con éxito en experimentaciones grandes o distribuidas.

Page 41: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

41

Modularidad del comportamiento

■ Uso de agentes genéricos Estructura de módulos inspirada en la orientación a

objetos

■ Uso de librerías de planes

■ Uso de creencias iniciales en el fichero mas2j para configurar variables de estado relacionadas con tipos de comportamiento

■ Facilitar el intercambio de mecanismos

Page 42: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

42

Distribuciones de salida

■ Reproducir “stylized facts”: Validación del modelo generativo Resultados del modelo predictivo

■ Propiedades del logging: ¿Qué guardar y a qué nivel? Granularidad Datos/ficheros individuales y/o agregados Formatos (txt, csv, xml, json) Debug tools (FAQ): verbose, Java logging, mind states

■ Retroalimentación de la salida: Second-order emergence

Page 43: Seminario CIIA@UV · 2018-08-28 · Jason Reasoning Cycle. 13 Extensions on Beliefs (1/3) ... Interpreter configuration (frequency of perception, event handling, system messages,

43

Gracias!

Programming Multi-Agent Systems in AgentSpeak Using Jason

Departament d'InformàticaEscola Tècnica Superior d'Enginyeria

Universitat de València

Francisco Grimaldo [email protected]