MAS Session1
MAS Session1
1
Evaluation
• Project 2 (courses 4 to 7) → 75 %
Argumentation-based Dialogue
Dealdine: 22/04/2023 (23h59)
2
Table of contents
3. What is an agent?
3
Motivations: Multi-Agent
Systems and AI
Motivations
4
Motivations
AI is not about
7 Building intelligent machines
7 Building machines that think
4
Artificial Intelligence: several definitions!
Reproduce cognition
The automation of activities that we Study mental faculties through the use of com-
associate with human thinking, such putational models (McDermott, 1985)
as decision-making, problem-solving,
learning. (Bellman, 1978) Perceive, Reason and Act (Winston, 1992)
Rationnality
Reproduce acts
5
Artificial Intelligence: several definitions!
6
Artificial Intelligence: several definitions!
6
Artificial Intelligence: several definitions!
3 Reproduce cognition
3 Rational behaviours (but not only)
3 Rule-based models with explicit knowledge (but not only)
7
A brief history of MAS
A brief history of Multiagent Systems
8
MAS as seen by a software engineer
• Improve the speed, the reusability, the readability, the security of code, . . . ?
• From Object to Service:
• A piece of code, possibly a thread, should be provided with some
machine-understandable interface;
• Allows other code to use it without a priori knowledge of its
operational content.
• Software engineers rely on interaction protocols to define how the different
services should be assembled, how the information has to be exchanged
between them, so as to produce some expected result.
9
MAS as seen by a software engineer
Multiagent system
• Platforms to support the development of such service-oriented software
• Coordination entities capable to interpreting protocols.
10
MAS as seen by a distributed systems engineer
Ü The agents (or processes) can run on one single computer but:
• they have independent memory spaces,
• they have independent runtimes ( They cannot rely on synchronous interactions).
calling function waits for the compute function to end before the code continues 11
MAS as seen by a distributed systems engineer
12
MAS as seen by a distributed systems engineer
Consequences
• Don’t wait for the answer: agents must carry on their activity while
a possible answer is computed by another agent;
• Use timeouts: agents must deal with the absence of answers.
and support the distribution of the system among different physical supports
(optional: most MAS architectures run on a single machine)
13
MAS as seen by an Artificial Intelligence engineer
14
MAS as seen by an Artificial Intelligence engineer
1
2 Initial state : At ( A ) , Level ( low ) , BoxAt ( C ) , BananasAt ( B )
3 Goal state : Have ( bananas )
4
5 Actions :
6 // move from X to Y
7 _Move (X , Y ) _
8 Preconditions : At ( X ) , Level ( low )
9 Post conditi ons : not At ( X ) , At ( Y )
10
11 // climb up on the box
12 _ClimbUp ( Location ) _
13 Preconditions : At ( Location ) , BoxAt ( Location ) , Level ( low )
14 Post conditi ons : Level ( high ) , not Level ( low )
15
16 // climb down from the box
17 _ClimbDown ( Location ) _
18 Preconditions : At ( Location ) , BoxAt ( Location ) , Level ( high )
19 Post conditi ons : Level ( low ) , not Level ( high )
20
21 // move monkey and box from X to Y
22 _MoveBox (X , Y ) _
23 Preconditions : At ( X ) , BoxAt ( X ) , Level ( low )
24 Post conditi ons : BoxAt ( Y ) , not BoxAt ( X ) , At ( Y ) , not At ( X )
25
26 // take the bananas
27 _TakeBananas ( Location ) _
28 Preconditions : At ( Location ) , BananasAt ( Location ) , Level ( high )
29 Post conditi ons : Have ( bananas )
16
To be remembered
An agent is :
17
To be remembered
18
Some Practical Application of MAS
1 Antoine Le Mortellec, Joffrey Clarhaut, Yves Sallez, Thierry Berger, Damien Trentesaux,
• The R&D branch of EDF has been working on a MAS for the simulation
of electrical consumption in households. This applied research project is
called SMACH2 .
• The MAS platform is used for the generation of realistic load curves in
answer to prospective studies: market research & pricing, new production
means, new consumption habits, etc.
2 https://www.youtube.com/watch?v=Hyc7XX4vEjw&t=17s
20
Some Practical Application of MAS
21
Some Practical Application of MAS
• Massive Software was originally developed for use in Peter Jackson’s The
Lord Of The Rings film trilogy.
• Massive has become the leading software for crowd related visual effects
and autonomous character animation.
• It combines MultiAgent Systems with Graphical Design.
22
Some Practical Application of MAS
MASA
23
Subjects–AAMAS 2022/2023
24
Subjects–AAMAS 2022/2023
25
What is an agent?
PRS architecture [Georgeff and Lansky 87]
Agent
• The environment: characterized by a (partially)
Monitor Sensors Perceptions
From signal to knowledge. . . observable state:
Beliefs
Goals Beliefs • it can be modified,
(desires) (knowledge base)
Environment • some of the variable values can be
Reasoning Reasoner Agents are situated observed by the agents.
Plans Intentions a set of observation functions and a set of
Actions modification functions.
Command
Generator
Actuators Actions & interactions • Agent: sensors (to access the observation func-
From knowledge to signal. . . tion ) + actuators (to access the modification
→ Procedural Loop functions).
27
PRS architecture [Georgeff and Lansky 87]
1 environment_variable = 0
2
3 def o p e r a t i o n _ i n c r e a s e _ v a r i a b l e () :
4 global e n v i r o n m e n t _ v a r i a b l e
5 e n v i r o n m e n t _ v a r i a b l e += 1
6
7 def p e r c e p t i o n _ g e t _ v a r i a b l e () :
8 global e n v i r o n m e n t _ v a r i a b l e
9 return e n v i r o n m e n t _ v a r i a b l e
10
11 def agent ( preferred_val u e ) :
12 v = p e r c e p t i o n _ g e t _ v a r i a b l e () # this is a sensor
13 while (v < preferred_v al ue ) :
14 o p e r a t i o n _ i n c r e a s e _ v a r i a b l e () # this is an actuator
15 v = p e r c e p t i o n _ g e t _ v a r i a b l e ()
16
28
PRS architecture [Georgeff and Lansky 87]
Environment
Reasoning Reasoner Agents are situated into internal variables, called beliefs. It
then combines these with a set of goals
Plans Intentions
Actions
and a set of plans so as to decide for some
intention that will be turn into a concrete
Command
Actuators Actions & interactions
Generator action in the environment.)
From knowledge to signal. . .
3. Action on the environment
→ Procedural Loop
29
PRS architecture [Georgeff and Lansky 87]
Environment
Reasoning Reasoner Agents are situated into internal variables, called beliefs. It
then combines these with a set of goals
Plans Intentions
Actions
and a set of plans so as to decide for some
intention that will be turn into a concrete
Command
Actuators Actions & interactions
Generator action in the environment.)
From knowledge to signal. . .
3. Action on the environment
→ Procedural Loop
29
An agent: remark
30
An agent: remark
30
Agent Models
31
Agent Models
31
Agent Models
31
Agent Models
STRIPS example
31
Agent Models
31
To be remembered
According to the PRS model that is at the core of agent modeling, an agent:
32
Agent and MAS: Exercices
33
Agent and MAS: Exercices
Questions
• Why does this not behave as a multiagent system?
• What is the problem?
34
Agent and MAS: Exercices
Questions
• Why does this not behave as a multiagent system?
• What is the problem?
Answers
34
Agent and MAS: Exercices
Questions
To overcome the above limitation, two solutions can be considered.
The first one is to write a scheduler, i.e. a piece of code that calls the
procedural loops of all agents, one after the other.
• Modify the previous code so that Runtime creates two agents and
calls a single-step procedural loop for all agents.
35
Answers. Version1: with home made scheduler
1
2 from time import sleep
3
4 class Environment :
5 def act ( self , message ) :
6 print ( message )
7 def perceive ( self ) :
8 pass
9
10 class Agent :
11 def __init__ ( self , name , env ) :
12 self . name = name
13 self . env = env
14 def p ro ce d ur al _l o op ( self ) :
15 self . env . act ( " Agent " + self . name + " says hello ! " )
16 sleep (0.1)
17
18 class Runtime :
19 def __init__ ( self ) :
20 e = Environment ()
21 a = Agent ( " Alice " ,e )
22 b = Agent ( " Bob " ,e )
23 while True :
24 a . p ro ce du r al _l oo p ()
25 b . p ro ce du r al _l oo p ()
26
27 Runtime ()
28
36
Answers. Version1: with home made scheduler
1. This MAS verifies a specific property, which is that the procedural loop of
all agents is performed at each time step: all agents run at the same
“speed”.
This is called a synchronous MAS. While the agent has its own runtime,
interleaved with the one of the other agents (which corresponds to the
specification of a MAS) these runtimes are synchronised.
2. The agents procedural loops are always invoked in the same order, which
is not a valid hypothesis in a MAS. Agents should never use that property.
If you want to avoid this, you can simply modify the Runtime class as
follows:
37
Answers. Version1: with home made scheduler – Avoiding the
same order
1
2 from time import sleep
3
4 class Environment :
5 def act ( self , message ) :
6 print ( message )
7 def perceive ( self ) :
8 pass
9
10 class Agent :
11 def __init__ ( self , name , env ) :
12 self . name = name
13 self . env = env
14 def p ro ce d ur al _l o op ( self ) :
15 self . env . act ( " Agent " + self . name + " says hello ! " )
16 sleep (0.1)
17
18 class Runtime :
19 def __init__ ( self ) :
20 e = Environment ()
21 agents = [ Agent ( " Alice " , e ) , Agent ( " Bob " , e ) ]
22 while True :
23 shuffle ( agents )
24 for a in agents :
25 a . pr o ce du r al _l oo p ()
26 Runtime ()
27
Questions
The second solution to have agent’s procedural loop interleave is to rely
on the Operating System’s multitasking mechanism (threads): each
agent must be a different thread.
• Modify the initial code so that Agents are threads which Runtime
starts when creating the agents.
39
Answers. Version2: with Threads
Questions
Do we have a multiagent system yet?
41
Agent and MAS: Exercices
Questions
Do we have a multiagent system yet?
Answers
• The agents in the preceding example are not really situated since the
perception phase does nothing.
• They use encapsulated data (the agent’s name), but we can’t really call
these a set of beliefs since they are not connected to the perception.
• Although they have asynchronous runtimes, with a procedural loop, we
cannot really call them agents, even not reactive agents. In order to write
reactive agents, we want the deliberation phase, in the procedural loop, to
depend on the perceptions.
41
Agent and MAS: Exercices
Questions
Write a new multi-agent system in which the environment has some
variable that the agents can perceive.
Write two reactive agents: the first one increases the variable by a
random value when it is even, the other one when it is odd.
42
Answers. Two agents and an environment’s variable
1
2 from time import sleep
3 from random import *
4 from threading import Thread
5
6 class Environment :
7 v = 0
8
9 def increase ( self , name ) :
10 x = randint (1 ,4)
11 print ( " Agent " + name + " increase the value by " + str ( x ) )
12 self . v = self . v + x
13 print ( " --> " + str ( self . v ) )
14
15 def perceive ( self ) :
16 return self . v
17
18 class Agent ( Thread ) :
19 def __init__ ( self , name , env ) :
20 Thread . __init__ ( self )
21 self . name = name
22 self . env = env
23
24 def run ( self ) :
25 while True :
26 self . pr oc e du ra l_ l oo p ()
27
28 def p ro ce d ur al _l o op ( self ) :
29 self . b = self . env . perceive ()
30 self . act ()
31 sleep ( uniform (0.1 ,0.5) )
32 43
Answers. Two agents and an environment’s variable (next)
1
2
3 class AgentOdd ( Agent ) :
4 def act ( self ) :
5 if self . b % 2 != 0:
6 self . env . increase ( self . name )
7
8 class AgentEven ( Agent ) :
9 def act ( self ) :
10 if self . b % 2 == 0:
11 self . env . increase ( self . name )
12
13 class Runtime :
14 def __init__ ( self ) :
15 e = Environment ()
16 a = AgentOdd ( " Alice " , e )
17 b = AgentEven ( " Bob " , e )
18 a . start ()
19 b . start ()
20
21 Runtime ()
22
44
Concurrent Modifications
45
Concurrent Modifications
Questions
• What do you expect to be a problem? Explain why.
• What is a possible solution?
45
Concurrent Modifications: Answers
• the scheduler interrupts the code between line 1 and 2, or even between
line 2 and 3, and passes the “handle” to the other agent:
the first agent will perform an increase operation on a variable that
might not be of the right parity. This is perfectly correct according to a
MAS specification!
46
Concurrent Modifications: Answers
• the scheduler interrupts the code between line 1 and 2, or even between
line 2 and 3, and passes the “handle” to the other agent:
the first agent will perform an increase operation on a variable that
might not be of the right parity. This is perfectly correct according to a
MAS specification!
• the scheduler stops in the middle of the Environment.increase() method.
This is a problem because the calling agent could perfectly assume this
method to be atomic, uninterruptible. This is what you expect when you
perform operations in an environment.
Property of a MAS: actions in the environment must be atomic
46
Concurrent Modifications: Answers
• the scheduler interrupts the code between line 1 and 2, or even between
line 2 and 3, and passes the “handle” to the other agent:
the first agent will perform an increase operation on a variable that
might not be of the right parity. This is perfectly correct according to a
MAS specification!
• the scheduler stops in the middle of the Environment.increase() method.
This is a problem because the calling agent could perfectly assume this
method to be atomic, uninterruptible. This is what you expect when you
perform operations in an environment.
Property of a MAS: actions in the environment must be atomic
When writing an asynchronous MAS with threads, the environment operations should be protected
by some lock.
46
Properties and Definitions
Properties of an environment [Russel &Norvig 2003]
47
Properties of the Agents in the MAS
Autonomous agents
The independence of one agent’s behavior (i.e. action selection) with
respect to some part of the system.
48
Properties of the Agents in the MAS
1. In tightly coupled MAS, the developer has a complete view of the MAS,
of possible actions performed by other agents. In other words, it can use
some of this information to design action mechanism in a more efficient
manner.
2. In a loosely coupled MAS, you must make no assumption on the design
of other agents in the MAS. This means that you must define very robust
behaviours to avoid deadlocks, infinite loops or unnecessary waiting times
in communication.
49
Properties of the Agents in the MAS
Open MAS?
• a specific kind of system in which you assume that agents can enter and
leave the system at any time during the execution.
• requires programmers to design specific mechanism to ensure that
messages are not left unanswered, that some feature in the system will
not disappear when not expected, etc.
• Concrete examples of open MAS are ant colonies or prey-predator
simulations
50
Properties of the Agents in the MAS
Distributed systems?
51
The mesa platform for Python
The mesa platform for Python
3 https://arxiv.org/abs/cond-mat/0211175
52