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

Seminario CIIA@UV

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

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

2

Outline

■ AgentSpeak.

■ Introduction to Jason.

■ Developing Multi-Agent Systems.

■ Jason GUI & Eclipse Plugin.

■ References & Examples.

■ Library extensions & Useful Tips.

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

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)

5

Overview of a MAS in Jason

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)

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)

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

9

Syntax of AgentSpeak Plans (2/2)

■ Example of plans:

10

Outline

■ AgentSpeak.

■ Introduction to Jason.

■ Developing Multi-Agent Systems.

■ Jason GUI & Eclipse Plugin.

■ References & Examples.

■ Library extensions & Useful Tips.

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.

12

Jason Reasoning Cycle

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

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)

15

Extensions on Beliefs (3/3)

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

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

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:

18

Plan bodies

■ Plan bodies invoke:

Belief add/del.

Test goals.

Achieve goals.

Environment actions.

Internal Actions:➔ Predefined.➔ User-defined.

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:

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

21

Outline

■ AgentSpeak.

■ Introduction to Jason.

■ Developing Multi-Agent Systems.

■ Jason GUI & Eclipse Plugin.

■ References & Examples.

■ Library extensions & Useful Tips.

22

MAS configuration file

MAS my_system {

infrastructure: Jade

environment: MyEnv

ExecuctionControl: …

agents: ag1; ag2; ag3;}

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

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

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

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

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.

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

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]

30

Outline

■ AgentSpeak.

■ Introduction to Jason.

■ Developing Multi-Agent Systems.

■ Jason GUI & Eclipse Plugin.

■ References & Examples.

■ Library extensions & Useful Tips.

31

Jason GUI

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

32

Jason's Mind Inspector

33

References & Examples

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

■ http://jason.sourceforge.net

34

New references to arrive

35

Outline

■ AgentSpeak.

■ Introduction to Jason.

■ Developing Multi-Agent Systems.

■ Jason GUI & Eclipse Plugin.

■ References & Examples.

■ Library extensions & Useful Tips.

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.

37

J-Moise+ internal actions■ create/remove

group

■ add responsible group

■ adopt/remove role

■ set goal arguments

■ set goal state

■ commit mission

■ remove mission

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

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

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.

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

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

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]