Jason - Programming Multi-Agent Systems using Jason fileIntroduction Introduction to Agent-Oriented...

34
Jason Programming Multi-Agent Systems using Jason Jan Toennemann, TU Clausthal . June Jan Toennemann Jason TU Clausthal

Transcript of Jason - Programming Multi-Agent Systems using Jason fileIntroduction Introduction to Agent-Oriented...

JasonProgramming Multi-Agent Systems using Jason

Jan Toennemann, TU Clausthal27. June 2017

Jan Toennemann JasonTU Clausthal 1

Table of Contents

Introduction

Jason – an Extension of AgentSpeak

Development of Multi-Agent Systems using Jason

Conclusion

Sources

Jan Toennemann JasonTU Clausthal 2

IntroductionIntroduction to Agent-Oriented ProgrammingA very short Introduction to PrologThe BDI-Model

Jason – an Extension of AgentSpeak

Development of Multi-Agent Systems using Jason

Conclusion

Sources

Jan Toennemann JasonTU Clausthal 3

Introduction to Agent-OrientedProgramming

Functional program: Input – computing – Output;f : I 7→ OReactive system: state-based, concurrent composition offunctional programsAgents: reactive system with a degree of autonomy

Jan Toennemann JasonTU Clausthal 4

“A logic program is a set of axioms, or rules,defining relations between objects. A compu-tation of a logic program is a deduction of con-sequences of the program. A program definesa set of consequences, which is its meaning.The art of logic programming is constructingconcise and elegant programs that have thedesired meaning.” (The Art of Prolog, p. 47)

Jan Toennemann JasonTU Clausthal 5

Facts and Queries

Facts:drinks(beer).drinks(water).

Queries:? - drinks(beer). % → yes? - drinks(milk). % → no? - drinks(X). % → beer

Jan Toennemann JasonTU Clausthal 6

Facts and Queries

Facts:drinks(beer).drinks(water).Queries:? - drinks(beer). % → yes? - drinks(milk). % → no? - drinks(X). % → beer

Jan Toennemann JasonTU Clausthal 6

Relationships and Rules

Facts and Rules:drinks(john, water).drinks(jeremy, milk).drinks(camilla, beer).drinks(jeremy, X) :- drinks(john, X).

Queries:? - drinks(camilla, X) % → X = beer? - drinks(X, gin). % → no? - drinks(jeremy, X). % see proof/query tree

Jan Toennemann JasonTU Clausthal 7

Relationships and Rules

Facts and Rules:drinks(john, water).drinks(jeremy, milk).drinks(camilla, beer).drinks(jeremy, X) :- drinks(john, X).Queries:? - drinks(camilla, X) % → X = beer? - drinks(X, gin). % → no? - drinks(jeremy, X). % see proof/query tree

Jan Toennemann JasonTU Clausthal 7

Relationships and Rules Getting Started 11

drinksUohn, X )

dnnksOL.~ The straight lines show how one goal sets up another goal. The curved lines show the alternative values for X for different solutions.

The general case is of a sequence of queries that must be satisfied. The subgoals in a query are separated by commas. Prolog begins from left to right attempting to satisfy each query. If a subgoal succeeds, Prolog tries the next one on the right. If a subgoal fails, Prolog goes back to the goal on the left to see if there are any more solutions. So, if we wish to test whether some X is human and honest, the query

?- human(X), honest(X).

is executed. This picture might help:

if subgoal succeeds, move right

~~ fi ·1 human(X), honest(X). query al s

"-J~ query succeeds

if subgoal fails, move left

This way of showing how success and failure propagate though a sequence of subgoals works for any number of subgoals in the body of a clause.

Jan Toennemann JasonTU Clausthal 7

Agent-Oriented Programming

BeliefsDesiresIntentions

Jan Toennemann JasonTU Clausthal 8

Reasoning based on the BDI-Modelreasoning is done in a control loopsimplified graphic of procedural reasoning:2.4. THE PROCEDURAL REASONING SYSTEM 23

Beliefs

Desires

Planlibrary

Interpreter

Intentions

Sensor input Action output

Figure 2.2 The Procedural Reasoning System (PRS).

In the PRS, an agent does no planning from first principles. Instead, it isequipped with a library of pre-compiled plans. These plans are manually con-structed, in advance, by the agent programmer. Plans in the PRS each have thefollowing components:

• a goal − the post-condition of the plan;

• a context − the pre-condition of the plan; and

• a body − the ‘recipe’ part of the plan − the course of action to carry out.

The goal of a PRS plan defines ‘what the plan is good for’, i.e. the things that itachieves. In conventional computer science terms, we can think of the goal as beingthe post-condition of the plan.

The context part of a PRS plan defines the pre-condition of the plan. Thus, thecontext of a plan defines what must be true of the environment in order for theplan to be successful.

The body of a PRS plan, however, is slightly unusual. We have so far describedplans as courses of action, and in the BDI agent control loop above, we assumedthat a plan was simply a list of actions. Executing such a plan simply involves exe-cuting each action in turn. Such plans are possible in the PRS, but much richerkinds of plans are also possible. The first main difference is that, as well hashaving individual primitive actions as the basic components of plans, it is pos-sible to have goals. The idea is that, when a plan includes a goal at a particular

Jan Toennemann JasonTU Clausthal 9

Introduction

Jason – an Extension of AgentSpeakCore Concepts: Beliefs, Goals and PlansAdvanced FeaturesBasic Example

Development of Multi-Agent Systems using Jason

Conclusion

Sources

Jan Toennemann JasonTU Clausthal 10

General

Prolog-like syntax, extended by dynamic elements+ to add to belief base, - to remove! for achievement goals, ? for test goalsplans consist of a trigger condition, a context and a body

Jan Toennemann JasonTU Clausthal 11

Beliefs and Plans

Recursive computation of the factorial of 5 using Jason:fact(0,1).

+fact(X,Y) : X < 5<- +fact(X + 1, (X + 1) * Y).

+fact(X,Y) : X == 5<- .print("fact 5 == ", Y).

Jan Toennemann JasonTU Clausthal 12

GoalsRecursive computation of the factorial of 5 using Jason’sgoals:!print_fact(5).

+!print_fact(N)<- !fact(N, F);

.print("Factorial of ", N, " is ", F).

+!fact(N, 1) : N == 0.

+!fact(N, F) : N > 0<- !fact(N - 1, F1);

F = F1 * N.Jan Toennemann JasonTU Clausthal 13

Actions and Internal Actions

Internal actions can be developed in Java and called fromagent codeIAs from standard library are preceded by a .

+!leave(home) : not raining & not ~raining<- !location(window);

?curtain_type(Curtains);open(Curtains).

+!leave(home) : not raining & not ~raining<- .send(mum, askIf, raining).

Jan Toennemann JasonTU Clausthal 14

Actions and Internal Actions

Internal actions can be developed in Java and called fromagent codeIAs from standard library are preceded by a .+!leave(home) : not raining & not ~raining

<- !location(window);?curtain_type(Curtains);open(Curtains).

+!leave(home) : not raining & not ~raining<- .send(mum, askIf, raining).

Jan Toennemann JasonTU Clausthal 14

Inter-Agent Communicationagents can communicate using.send(agent, action, content) and.broadcast(action, content)possible actions are tell, untell, achieve, unachieve,askOne, askAll, tellHow, untellHow and askHow

communication triggers events at the receiving agentwhen adding or removing beliefs, goals or plans

.send(maria, tell, colour(box, blue)).+colour(box, X)

<- .print("The box is ", X).+colour(box, X)[source(Y)] : Y \== self

<- .print(Y, " told me that the box is ", X).

Jan Toennemann JasonTU Clausthal 15

Inter-Agent Communicationagents can communicate using.send(agent, action, content) and.broadcast(action, content)possible actions are tell, untell, achieve, unachieve,askOne, askAll, tellHow, untellHow and askHowcommunication triggers events at the receiving agentwhen adding or removing beliefs, goals or plans.send(maria, tell, colour(box, blue)).

+colour(box, X)<- .print("The box is ", X).

+colour(box, X)[source(Y)] : Y \== self<- .print(Y, " told me that the box is ", X).

Jan Toennemann JasonTU Clausthal 15

Inter-Agent Communicationagents can communicate using.send(agent, action, content) and.broadcast(action, content)possible actions are tell, untell, achieve, unachieve,askOne, askAll, tellHow, untellHow and askHowcommunication triggers events at the receiving agentwhen adding or removing beliefs, goals or plans.send(maria, tell, colour(box, blue)).+colour(box, X)

<- .print("The box is ", X).

+colour(box, X)[source(Y)] : Y \== self<- .print(Y, " told me that the box is ", X).

Jan Toennemann JasonTU Clausthal 15

Inter-Agent Communicationagents can communicate using.send(agent, action, content) and.broadcast(action, content)possible actions are tell, untell, achieve, unachieve,askOne, askAll, tellHow, untellHow and askHowcommunication triggers events at the receiving agentwhen adding or removing beliefs, goals or plans.send(maria, tell, colour(box, blue)).+colour(box, X)

<- .print("The box is ", X).+colour(box, X)[source(Y)] : Y \== self

<- .print(Y, " told me that the box is ", X).Jan Toennemann JasonTU Clausthal 15

Annotations

annotations differentiate beliefs based on their origin orother propertiescolour(box1, blue)[source(bob)].~colour(box1, white)[source(john)].colour(box1, red)[source(percept)].

colourblind(bob)[source(self), degOfCert(0.7)].

they may be nested to indicate belief chainsloves(maria,bob)[source(john)[source(maria)]].

Jan Toennemann JasonTU Clausthal 16

Annotations

annotations differentiate beliefs based on their origin orother propertiescolour(box1, blue)[source(bob)].~colour(box1, white)[source(john)].colour(box1, red)[source(percept)].

colourblind(bob)[source(self), degOfCert(0.7)].

they may be nested to indicate belief chains

loves(maria,bob)[source(john)[source(maria)]].

Jan Toennemann JasonTU Clausthal 16

Annotations

annotations differentiate beliefs based on their origin orother propertiescolour(box1, blue)[source(bob)].~colour(box1, white)[source(john)].colour(box1, red)[source(percept)].

colourblind(bob)[source(self), degOfCert(0.7)].

they may be nested to indicate belief chainsloves(maria,bob)[source(john)[source(maria)]].

Jan Toennemann JasonTU Clausthal 16

Supermarket Agent

last_order_id(1).

+!order(Product, Quantity)[source(Ag)] : true<- ?last_order_id(N);

OrderId = N + 1;-+last_order_id(OrderId);deliver(Product, Quantity);.send(Ag, tell,

delivered(Product, Quantity, OrderId)).

Jan Toennemann JasonTU Clausthal 17

Introduction

Jason – an Extension of AgentSpeak

Development of Multi-Agent Systems using JasonScenario AnalysisAgent DesignProgramming

Conclusion

Sources

Jan Toennemann JasonTU Clausthal 18

Scenario Analysis

identify goals: strategic goals, maintenance goalsdetermine tasks to achieve goalssplit tasks into as many small sub-tasks as possibleassign commitment strategies:– blind commitment,– single-minded commitment,– relativised commitment,– open-minded commitment

Jan Toennemann JasonTU Clausthal 19

Agent Design

follow BDI-model, design common base for all agentsfocus on interaction & communicationdetermine collaborative strategies to achieve goalsassign sub-tasks based on agent type, individualstrengthspromote agents to leaders, design hierarchies

Jan Toennemann JasonTU Clausthal 20

Programming

implement internal actions for more complex tasks,shared among agentsuse declarative goals instead of procedural ones+!g : c <- p; ?g.

differ between global and agent-specific goalscover all contexts, fallback plans for error-recovery

Jan Toennemann JasonTU Clausthal 21

Introduction

Jason – an Extension of AgentSpeak

Development of Multi-Agent Systems using Jason

Conclusion

Sources

Jan Toennemann JasonTU Clausthal 22

Conclusion

agents based on BDI-model, logical reasoning(largely) autonomous reactive systemsfocus on collaboration, solving many small tasks to worktowards a large goalvery adaptable, can be deployed to unknownenvironmentsJason was developed with BDI concepts in mind

→ allows agent-oriented programming, requires adapteddesign patterns

Jan Toennemann JasonTU Clausthal 23

Introduction

Jason – an Extension of AgentSpeak

Development of Multi-Agent Systems using Jason

Conclusion

Sources

Jan Toennemann JasonTU Clausthal 24

Sources

R. H. Bordini, J. F. Hübner, M. Woolridge.Programming Multi-Agent Systems in AgentSpeak usingJason.John Wiley & Sons, 2007.

L. Sterling, E. Shapiro.The Art of Prolog.The MIT Press, 1994.W. F. Clocksin.Clause and Effect.Springer-Verlag Berlin Heidelberg, 1997.

Jan Toennemann JasonTU Clausthal 25