Agent Oriented Programming Lecture outline
description
Transcript of Agent Oriented Programming Lecture outline
![Page 1: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/1.jpg)
Multi-Agent SystemsLecture 5Lecture 5
University “Politehnica” of Bucarest2004 - 2005
Adina Magda [email protected]
http://turing.cs.pub.ro/blia_2005
![Page 2: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/2.jpg)
Agent Oriented ProgrammingAgent Oriented ProgrammingLecture outlineLecture outline
11 AOP principlesAOP principles
22 An agent scenarioAn agent scenario
3 Overview of the AOP framework3 Overview of the AOP framework
4 AGENT-04 AGENT-0
5 A sample program5 A sample program
![Page 3: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/3.jpg)
3
promotes a societal view of computing uses mental states to design agents; mental
categories appear in the programming language
the semantics of the PL is related to the semantics of mental states
first AOPL: Agent-0 mental states of Agent-0: beliefs,
commitments, capabilities, decisions
1 AOP principles1 AOP principles
![Page 4: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/4.jpg)
4
1.1 OOP versus AOP1.1 OOP versus AOP
OOP AOPBasic unit object agentParametersdefining basicunit
unconstrained beliefs,commitments,abilities,decisions (goals)
Process ofcomputation
message passingand response tomethods
message passingand response tomethods
Types ofmessages
unconstrained based on speechact theory
Constraints onmethods
none honesty,consistency, etc.
![Page 5: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/5.jpg)
5
Airline ReservationAirline Reservation
Agents:
P is a passenger.
· C is an airline clerk, a program.
· S is C’s supervisor. By confirming a reservation, the airline enters into a
commitment to issue a boarding pass to the passenger at the appropriate time.
2 An agent scenario2 An agent scenario
![Page 6: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/6.jpg)
6
March • P to C: Please inform me what flights you have from San Francisco to
New York on April 18. • C to P: Flight #354 departs at 08:30. flight #293 departs at 10:00, flight
#441 departs at noon, • P to C: Please book me on #354. • C to P: That is sold out. • P to C: Please book me on #293. • C to P: That is confirmed: your reservation number is 112358. • P to C: Please book me also on #441. • C to P: That conflicts with #293: I am not allowed to double book a
passenger. • P to C: Please get permission to do so. • C to S: I request permission for the fallowing double booking: • S to C: Permission denied. • C to P: Sorry, I cannot get approval.
Airline reservationAirline reservation
![Page 7: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/7.jpg)
7
April 18, at the airport • P to C: My name is P; I have a
reservation for flight =293. • C to P: Here is your boarding pass.
Airline reservationAirline reservation
![Page 8: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/8.jpg)
3 Overview of the AOP Framework3 Overview of the AOP Framework
A complete AOP system should have 3 components:
A formal (logical) language for defining the mental state of the agents
An (interpreted) programming language in which to define and program agents, with communication primitives based on speech-act theory; the semantics of the PL must match the semantics of the mental states
An "agentification" process converting neutral devices into programmable agents
8
![Page 9: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/9.jpg)
4 Agent-04 Agent-0
4.1 Components of Mental State4.1 Components of Mental State Two mental categories: beliefs and decisions
A third (not per se mental) category: capabilities.
A forth category: obligation, or commitment - treat decision as commitment to oneself.
9
![Page 10: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/10.jpg)
The agent’s beliefs refer to:
states of the world,
mental states of other agents, and
capabilities of this and other agents.
The actions of an agent are determined by its decisions, or choices.
Decisions are constrained (but nor determined) by the agent’s beliefs
Decisions are also constrained by prior decisions.
10
![Page 11: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/11.jpg)
4.2 Representation of Belief, Obligation, and 4.2 Representation of Belief, Obligation, and CapabilityCapability
Time
We adopt a point-based temporal language
holding(robot,cup)t
Action
We don’t distinguish between actions and facts: the occurrence of an action is represented by the corresponding fact holding,
e.g., instead of saying that the robot took the action raise-arm at time t, we say that the sentence
raise-arm(robot)t
is true.
Since actions are facts, they’re instantaneous.11
![Page 12: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/12.jpg)
Belief
Using modal operator B,
Bta
“At time t agent a believes that “,
where is a (recursively defined) sentence.
B3a B10
b like(a,b)7
“At time 3 agent a believes that at time 10 agent b will believe that at time 7 a liked b.”
Obligation (commitment)
OBLta,b
“At time t agent a is obligated (committed) to agent b about .”
Decision (choice)
Decision is defined to be obligation to oneself:
DECta defOBLt
a,a 12
![Page 13: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/13.jpg)
Capability
CANta
“At time t agent a is capable of .”
CAN5robotopen(door)8
“At time 5 the robot can ensure that the door is open at time 8.”
ABLE is the “immediate” version of CAN.
time() - the outermost time occurring in sentence time(open(door)t)=t
ABLEa def CANtime()a
13
![Page 14: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/14.jpg)
Persistence of Mental State
Beliefs persist by default: agents have perfect memory of their beliefs; a belief is dropped only when a contradictory fact is learned.
The absence of belief also persists by default.
Obligations persist by default, but there are conditions under which they’re revoked, e.g.:
explicit release of the agent by the party to which it’s obligated,
realization by the agent that it’s no longer able to fulfill the obligation.
Since decision is defined in terms of obligation, it inherits the default persistence.
14
![Page 15: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/15.jpg)
Linear discrete time Beliefs Ba
t Actions raise_arm(robot)t
Obligations (commitments) OBLa,bt (CMTa,b
t ) Decisions (choices) DECa
t = OBLa,at
Abilities (capabilities) CANat
Properties of mental categories
• Internal consistency of beliefs and commitments Good faith Persistence of beliefs Persistence of commitments
15
Summary of mental categories in AGENT0Summary of mental categories in AGENT0
![Page 16: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/16.jpg)
The role of an agent program is to control the evolution of an agent’s mental state.
Actions occur as side-effects of the agent being committed to an action whose time has come.
The Basic LoopEach agent iterates the following steps at regular intervals:1. Read the current messages and update your mental state,
including your beliefs and commitments.(The agent program is crucial for the update.)
2. Execute the commitments for the current time, possibly resulting in further belief change.(This is independent of the agent program.)
16
4.3 A generic interpreter4.3 A generic interpreter
![Page 17: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/17.jpg)
Actions to which agents can be committed include arbitrary private actions communicative actions (e.g., informing and requesting)
Private actions may or may not involve IO.
Communicative actions always involve IO and are common to all agents.
Actions may also be:
unconditional actions
conditional actions
A conditional action relies on a mental condition, which refers to the mental state of the agent.
17
A generic interpreter - contA generic interpreter - cont
![Page 18: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/18.jpg)
Assumptions about Message Passing the platform can pass messages to other agents
addressable by name.
the interpreter determines when messages are sent.
Assumptions about the Clock
The clock initiates iterations of the two-step loop at regular intervals.
The length of these intervals is determined by the variable timegrain.
Assume that a single iteration through the loop lasts less than the time grain.
18
A generic interpreter - contA generic interpreter - cont
![Page 19: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/19.jpg)
Initialize mental stateand capabilitiesDefine rules for makingnew commitments
Update mentalstate
Execute commitmentfor current time
Clock Representationof mental stateand capabilities
Outgoing message
Incoming message
A flow diagram of the generic agent interpreter
Control
Data
![Page 20: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/20.jpg)
Fact statements Fact statements are used to specify both the content of actions and
conditions for their execution.(t (employee smith acm))(NOT (t (employee jones acm)))
<fact> ::= (<time> (<predicate> <arg>*))<time> ::= <integer> | now | <time-constant> |
(+ <time> <time>) | (- <time> <time>) |
(<time> <time>); Time may be a <variable> when; it appears in a commitment rule
<time-constant> ::= m | h | d | y; m (minute) =60, h (hour) 3600, etc.
20
4.4 Agent language4.4 Agent language
![Page 21: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/21.jpg)
Action Statements
Private actions The syntax for a private action is
(DO t p-action)
where t is a time point and p-action is a private action name.
Communicative actions The syntax of informing is
(INFORM t a fact)
where t is a time point, a an agent name, and fact is a fact statement. The syntax of requesting is
(REQUEST t a action)
where action is an action statement, recursively defined.
e.g.,
(REQUEST 1 a (DO 10 update-database))
(REQUEST 1 a (REQUEST 5 b
(INFORM 10 a fact)))21
![Page 22: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/22.jpg)
The syntax of canceling a request is
(UNREQUEST t a action) We can also prevent commitment to a particular action:
(REFRAIN action)
<action> ::=
(DO <time> <privateaction>) |
(INFORM <time> <agent> <fact>) |
(REQUEST <time> <agent> <action>) |
(UNREQUEST <time> <agent> <action>) |
(REFRAIN <action>) |
(IF <mental-cond> <action>)
22
![Page 23: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/23.jpg)
Conditional Action StatementsWe distinguish between: commitments for conditional actions, which include conditionsto be tested just before acting, and conditions for entering into commitments in the first place
When the time comes to execute the action, the mental state at that time is examined to see whether the mental condition is satisfied. So the agent and time components of the mental state are left implicit.
A mental condition is then any combination of modal statements in the temporal-modal language, with the primary agent and time arguments omitted.
(IF (B (t1 (employee smith ibm))) (INFORM t a (t1 (employee smith ibm))))
23
![Page 24: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/24.jpg)
<action> ::= (IF <mental-cond> <action>)
< mental-cond > ::=
< mental- conj> | (OR < mental- conj>*)
< mental- conj> ::=
< mental- pattern> | (AND < mental- pattern>*)
< mental- pattern> ::=
(B <fact>) |
((CMT <agent>) <action>) |
(NOT < mental- pattern>)
24
![Page 25: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/25.jpg)
Variablesagent names, fact statements, action statements ?x ?!x
Ex: (IF (NOT ((CMT ?x) (REFRAIN sing))) sing)
(IF (B (t (emp ?!x ibm)))
(INFORM a (t (emp ?!x ibm))))
<variable> ::= ?<alphanumeric_string> | ?!<alphanumeric_string>
<agent> ::= <alphanumeric_string> | <variable>
<predicate> ::= <alphanumeric_string>
<arg> : := <alphanumeric_string> | <variable>25
![Page 26: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/26.jpg)
Commitment rules - key to AOP
Conditions for entering a commitment: mental condition message condition
Message condition = a logical combination of message patterns
Message pattern (sender type content)
type: INFORM, REQUEST, UNREQUEST, REFRAIN
content: a fact statement or an action statement, depending on type
Commitment rule
(COMMIT message-cond mental-cond (agenti actioni)*)
Ex: (COMMIT (?a REQUEST ?action)
(B (now (myfriend ?a)))
(?a ?action))26
![Page 27: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/27.jpg)
Commitment rules
<commitrule> ::=
(COMMIT <mes-cond> <mental-cond>
(<agent> <action>)*)
< mes- cond> ::=
< mes- conj> | (OR <mes- conj>*)
< mes- conj> ::=
< mes- pattern> | (AND < mes- pattern>*)
< mes- pattern> ::=
(<agent> INFORM <fact>) |
(<agent> REQUEST <action>) |
(<agent> UNREQUEST <action>) |
(<agent> REFRAIN <action>) |
(NOT < mes- pattern>) 27
![Page 28: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/28.jpg)
A commitment rule adds a commitment to "action"
(COMMIT mes-cond mental-cond (ai actioni)*)
If: the message condition holds for the incoming
message the mental condition holds for the current mental state the agent is capable of doing all actioni
the agent is not committed to any REFRAIN actioni
if actioni=REFRAIN action1 the agent is not committed to action1
Then, for all i, commit to ai to perform actioni.28
![Page 29: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/29.jpg)
Agent program fix the time grain define agent's abilities for all agents define agents' initial beliefs state sequence of commitment rules
<program> ::=
timegrain := <time>
CAPABILITIES := (<action> <mental-cond>)*
INITIAL BELIEFS := <fact>*
COMMITMENT RULES := <commitrule>* 29
![Page 30: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/30.jpg)
The Basic Loop of AGENT01. Read the current messages and update your mental state,
including your beliefs and commitments.
(1a) Update the beliefs.
(2a) Update the commitments.
(1a) The belief database is updated either as a result of being informed or as a result of taking a private action -- e.g.,
- a database agent comes to believe a fact after performing a
retrieval operation.
- a robotic agent comes to believe something after performing a visual routine.
30
![Page 31: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/31.jpg)
The Basic Loop of AGENT0(2a) Updating commitments Items in the database of commitments are pairs
(agent action),
the agent to which the commitment was made and the content of the commitment.
Items in the database of capabilities are pairs
(privateaction mental-cond). The mental condition part prevents commitment to
incompatible actions.
E.g.,
((?!time (rotate wheelbase ?degrees))
(NOT ((CMT ?x) ?!time (service wheelbase))))
31
![Page 32: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/32.jpg)
Existing commitments are removed either as a result of UNREQUEST messages
The agent removes the corresponding item from the commitment
database if it exists, else does nothing.
or as a result of belief change.
Belief change may affect capabilities since the capability of each private action depends on mental preconditions. So, whenever a belief update occurs, the AGENT-0 interpreter examines the current commitments to private actions. It removes those whose preconditions in the capability database have been violated.
It should add a commitment to inform the agent to which it was
committed (but AGENT-0 doesn’t enforce this).
32
![Page 33: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/33.jpg)
Removing existing commitments is independent of the program, but adding them depends on the program.
Adding commitments – see commitment rule
The Basic Loop of AGENT0
2. Execute the commitments for the current time, possibly resulting in further belief change.
33
![Page 34: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/34.jpg)
Conditions for an agent to be capable of an action: An agent can request and unrequest anything from anyone. An agent can inform anyone of a fact he believes. An agent can inform itself of any fact at all (useful to
implement reasoning in the agent). An agent is capable of any private action in the capability
database provided the mental condition associated with that private action by the database holds at that time.
An agent can refrain from any action provided he’s not already committed to it.
An agent can perform a conditional action (IF mental-cond action) if he can perform action under the condition mental-cond.
34
![Page 35: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/35.jpg)
Carrying Out Commitments Each commitment in the commitment database has an
associated time. In 2) the interpreter executes all actions whose time is in the
interval (now - timegrain, now]. The meaning of “execute” depends on the type of action:INFORM, REQUEST, UNREQUEST: Send the appropriate
message.REFRAIN: No effect on execution.DO: Consulting the belief and commitment databases, check
the mental condition associated with the primitive action in the capability database; if it holds, then perform the primitive action.
IF: Consulting the belief and commitment databases, test themental condition; if it holds, then (recursively) execute the action.
35
![Page 36: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/36.jpg)
5 A sample program5 A sample program
A program for the initial scenario
The ideas behind the program are that:
the relevant activity on the part of the airline is issuing a boarding pass to the passenger, and
confirming a reservation is a commitment to issue a boarding pass at the appropriate time.
36
![Page 37: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/37.jpg)
5.1 Macros5.1 Macros(issue_bp pass flightnum time) (IF (AND (B ((- time h) (present pass))) (B (time (flight ?from ?to flightnum))))
(DO time – h (physical_issue_bppass flightnum time)))
(query_which t asker askee q) (REQUEST t askee(IF (B q) (INFORM (+ t 1) asker q)))
(query_whether t asker askee q) (REQUEST t askee(IF (B q) (INFORM (+ t 1) asker q)))(REQUEST t askee(IF (B (NOT q))(INFORM (+ t 1) asker (NOT q))))
37
Private action
![Page 38: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/38.jpg)
5.2 Initial Beliefs5.2 Initial BeliefsConcerning the flight schedule:
(time (flight from to number))And the number of seats available:
(time (remaining_seats time1 flight_number seats)
5.3 Capabilities5.3 CapabilitiesThese are issuing boarding passes and updating the count of theavailable seats on flights.((issue_bp ?a ?flight ?time) true)((DO ?time
(update_remaining_seats ?time1 ?flight_number?additional_seats))
(AND(B (?time (remaining_seats ?time1?flight_number ?current_seats)))(?current_seats >= |?additional_seats|)))
38
![Page 39: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/39.jpg)
5.4 Commitment Rules5.4 Commitment Rules
(COMMIT
(?pass REQUEST
(IF (B ?p) (INFORM ?t ?pass ?p)))
true
?pass
(IF (B ?p) (INFORM ?t ?pass ?p)))
39
![Page 40: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/40.jpg)
(COMMIT
(?cust REQUEST
(issue_bp ?pass ?flight ?time))
(AND
(B (?time (remaining_seats ?flight ?n)
(?n > 0)
(NOT ((CMT ?anyone)
(issue_bp ?pass ?anyflight ?time))))
(myself
(DO (+ now 1)
(update_remaining_seats ?time ?flight -1)))
(?cust (issue_bp ?pass ?flight ?time))) 40
![Page 41: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/41.jpg)
5.5 Sample exchange between a passenger and an airline 5.5 Sample exchange between a passenger and an airline agentagent
smith (query_which lmarch/l:00 smith airline(18april/?!time (flight sf ny ?!
num)))airline (INFORM lmarch/2:00 smith
(18april/8:30 (flight sf ny #354)))airline (INFORM lmarch/2:00 smith
(18april/10:00 (flight sf ny #293)))airline (INFORM lmarch/2:00 smith
(18april/ smith (REQUEST lmarch/3:00 airline
(issue_bp smith #354 18april/8:30))smith (query_whether lmarch/4:00 smith airline
((CMT smith)(issue-bp smith #354
18april/8:30)))41
![Page 42: Agent Oriented Programming Lecture outline](https://reader036.fdocuments.in/reader036/viewer/2022062409/56815145550346895dbf65c5/html5/thumbnails/42.jpg)
airline (INFORM lmarch/5:00 smith
(NOT ((CMT smith)
(issue-bp smith #354 18april/8:30))))
smith (REQUEST lmarch/6:00 airline
(issue-bp smith #293 18april/10,.00))
smith (query-whether lmarch/7:00 smith airline
((CMT smith)
(issue-bp smith #293 18april/10:00)))
airline (INFORM lmarch/8:00 smith
((CMT smith)
(issue-bp smith #293 18april/10:00)))
smith (INFORM 18april/9:00 airline
(present smith))
airline (DO 18april/9:00
(issue-bp smith #293 18april/10:00))
42