Koen HindriksMulti-Agent Systems 2012 Introduction Agent Programming Koen Hindriks Delft University of Technology, The Netherlands Learning to program teaches you how to think. Computer science is a liberal art. Steve Jobs Multi-Agent Systems Course
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Introducing Myself Dr. Koen Hindriks –PhD on Agent Programming Languages (Utrecht, ) –Consultant at Accenture (Amsterdam, ) –Assistant Professor Artificial Intelligence (Nijmegen, ) –Assistant Professor MMI Group (Delft, …) Main Research Interests –Rational agent programming and theory –Automated negotiation –Logic (with applications to agent modeling and NLP semantics) –Cognitive engineering and architectures
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Outline This lecture: –Blocks, Blocks, Blocks… Basic Blocks World example in the G OAL agent programming language –Actions –Rule-Based Action Selection
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems This Part: BW4T Assignment Abstract simulated environment called: Blocks World for Teams (BW4T) Search and retrieval task Control robot by cognitive agent program Your task: implement decision-making
Koen HindriksMulti-Agent Systems 2012 The G OAL Agent Programming Language
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems 2012 THE BLOCKS WORLD The Hello World example of Agent Programming
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems The Blocks World Positioning of blocks on table is not relevant. A block can be moved only if it there is no other block on top of it. Objective: Move blocks in initial state such that result is goal state. A classic AI planning problem.
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Mental State of G OAL Agent knowledge{ block(X) :- on(X, _). clear(X) :- block(X), not(on(Y,X)). clear(table). tower([X]) :- on(X,table). tower([X,Y|T]) :- on(X,Y), tower([Y|T]). } beliefs{ on(a,b). on(b,c). on(c,table). on(d,e). on(e,table). on(f,g). on(g,table). } goals{ on(a,e), on(b,table), on(c,table), on(d,c), on(e,b), on(f,d), on(g,table). } The knowledge, belief, and goal sections together constitute the specification of the mental state of a G OAL Agent. Initial mental state of agent
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Previous Lecture Percepts Action events actionsgoals plans beliefs environment agent
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems This Lecture Percepts Action events actionsgoals plans beliefs environment agent
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Next Lecture Percepts Action events actionsgoals plans beliefs environment agent
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Why “Hello World” Example? The Blocks World is: –Single agent: no other agents that can change the world –Fully observable: the agent can see “everything” –Static: only actions of agent can change the world We do not need sensing / percepts.
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Agent Oriented Programming Agents provide a very effective way of building applications for dynamic and complex environments + Develop agents based on Belief-Desire-Intention agent metaphor, i.e. develop software components as if they have beliefs and goals, act to achieve these goals, and are able to interact with their environment and other agents.
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems 2012 ACTIONS SPECIFICATIONS Changing Blocks World Configurations
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Actions Change the Environment… move(a,d)
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems and Require Updating Mental States. To ensure adequate beliefs after performing an action the belief base needs to be updated (and possibly the goal base). –Add effects to belief base: insert on(a,d) after move(a,d). –Delete old beliefs: delete on(a,b) after move(a,d).
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems and Require Updating Mental States. If a goal has been (believed to be) completely achieved, the goal is removed from the goal base. It is not rational to have a goal you believe to be achieved. Default update implements a blind commitment strategy. move(a,b) beliefs{ on(a,table), on(b,table). } goals{ on(a,b), on(b,table). } beliefs{ on(a,b), on(b,table). } goals{ }
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Action Specifications Actions in GOAL have preconditions and postconditions. Executing an action in GOAL means: –Preconditions are conditions that need to be true: Check preconditions on the belief base. –Postconditions (effects) are add/delete lists (STRIPS): Add positive literals in the postcondition Delete negative literals in the postcondition STRIPS-style specification move(X,Y){ pre { clear(X), clear(Y), on(X,Z), not( on(X,Y) ) } post { not(on(X,Z)), on(X,Y) } }
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems move(X,Y){ pre { clear(X), clear(Y), on(X,Z), not( on(X,Y) ) } post { not(on(X,Z)), on(X,Y) } } Example: move(a,b) Check: clear(a), clear(b), on(a,Z), not( on(a,b) ) Remove: on(a,Z) Add: on(a,b) Note: first remove, then add. Actions Specifications table
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems move(X,Y){ pre { clear(X), clear(Y), on(X,Z), not( on(X,Y) ) } post { not(on(X,Z)), on(X,Y) } } Example: move(a,b) Actions Specifications beliefs{ on(a,table). on(b,table). } beliefs{ on(b,table). on(a,b). }
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems move(X,Y){ pre { clear(X), clear(Y), on(X,Z), not( on(X,Y) ) } post { not(on(X,Z)), on(X,Y) } } 1.Is it possible to perform move(a,b) ? 2.Is it possible to perform move(a,d) ? Actions Specifications EXERCISE: knowledge{ block(a), block(b), block(c), block(d), block(e), block(f), block(g), block(h), block(i). clear(X) :- block(X), not(on(Y,X)). clear(table). tower([X]) :- on(X,table). tower([X,Y|T]) :- on(X,Y), tower([Y|T]). } beliefs{ on(a,b). on(b,c). on(c,table). on(d,e). on(e,table). on(f,g). on(g,table). } No, clear(b) fails. Yes.
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems move(X,Y){ pre { clear(X), clear(Y), on(X,Z), not( on(X,Y) ) } post { not(on(X,Z)), on(X,Y) } } We already check clear(Y). Why do we also have not(on(X,Y)) in the precondition? Actions Specifications EXERCISE: Since we always have clear(table). The condition prevents moving blocks that are already on the table. knowledge{ block(a), block(b), block(c), block(d), block(e), block(f), block(g), block(h), block(i). clear(X) :- block(X), not(on(Y,X)). clear(table). tower([X]) :- on(X,table). tower([X,Y|T]) :- on(X,Y), tower([Y|T]). } beliefs{ on(a,b). on(b,c). on(c,table). on(d,e). on(e,table). on(f,g). on(g,table). }
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems 2012 ACTION RULES Selecting actions to perform
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Agent-Oriented Programming How do humans choose and/or explain actions? Examples: I believe it rains; so, I will take an umbrella with me. I go to the video store because I want to rent I-robot. I don’t believe busses run today so I take the train. Use intuitive common sense concepts: beliefs + goals => action See Chapter 1 of the Programming Guide
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Selecting Actions: Action Rules Action rules are used to define a strategy for action selection. Defining a strategy for blocks world: –If constructive move can be made, make it. –If block is misplaced, move it to table. program{ if bel(tower([Y|T])), a-goal(tower([X,Y|T])) then move(X,Y). if a-goal(tower([X|T])) then move(X,table). }
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Selecting Actions: Action Rules What happens? Check whether condition a-goal(tower([X|T]) can be derived from the current mental state of agent. If so, then apply rule and perform move(X,table). if a-goal(tower([X|T])) then move(X,table).
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Selecting Actions: Action Rules What happens? if a-goal(tower([X|T])) then move(X,table). knowledge{ block(X) :- on(X, _). clear(X) :- block(X), not(on(Y,X)). clear(table). tower([X]) :- on(X, table). tower([X,Y|T]) :- on(X,Y), tower([Y|T]). } beliefs{ on(a, b). on(c, d). } goals{ on(a, table), on(c, table). } d c b a EXERCISE: Random choice for either moving a or c.
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Order of Action Rules Action rules are executed by default in linear order. The first rule that fires is executed. Default order can be changed to random. Arbitrary rule that is able to fire may be selected. program{ if bel(tower([Y|T])), a-goal(tower([X,Y|T])) then move(X,Y). if a-goal(tower([X|T])) then move(X,table). } program[order=random]{ if bel(tower([Y|T])), a-goal(tower([X,Y|T])) then move(X,Y). if a-goal(tower([X|T])) then move(X,table). }
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Example Program: Action Rules Agent program may allow for multiple action choices d To table Random, arbitrary choice program[order=random]{ if bel(tower([Y|T])), a-goal(tower([X,Y|T])) then move(X,Y). if a-goal(tower([X|T])) then move(X,table). }
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems The Sussman Anomaly (1/5) Non-interleaved planners typically separate the main goal, on(A,B),on(B,C) into 2 sub-goals: on(A,B) and on(B,C). Planning for these two sub-goals separately and combining the plans found does not work in this case, however. a c Initial state bc b a Goal state
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems The Sussman Anomaly (2/5) Initially, all blocks are misplaced One constructive move can be made (c to table) Note: move(b,c) not enabled. Only action enabled: c to table (2x). Need to check conditions of action rules: if bel(tower([Y|T]),a-goal(tower([X,Y|T))then move(X,Y). if a-goal(tower([X|T))then move(X,table). We have bel(tower([c,a]) and a-goal(tower([c])). c b a Goal state a c Initial state b
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems The Sussman Anomaly (3/5) Only constructive move enabled is –Move b onto c Need to check conditions of action rules: if bel(tower([Y|T]), a-goal(tower([X,Y|T))then move(X,Y). if a-goal(tower([X|T))then move(X,table). Note that we have: a-goal(on(a,b),on(b,c),on(c,table)), but not: a-goal(tower[c])). Current state c b a Goal state a c b
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems The Sussman Anomaly (4/5) Again, only constructive move enabled –Move a onto b Need to check conditions of action rules: if bel(tower([Y|T]), a-goal(tower([X,Y|T))then move(X,Y). if a-goal(tower([X,T))then move(X,Y). Note that we have: a-goal(on(a,b),on(b,c),on(c,table)), but not: a-goal(tower[b,c]). c b a Goal state a c b Current state
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems The Sussman Anomaly (5/5) Upon achieving a goal completely that goal is automatically removed. The idea is that no resources should be wasted on achieving the goal. In our case, goal(on(a,b),on(b,c),on(c,table)) has been achieved, and is dropped. The agent has no other goals and is ready. c b a Goal state a c b Current state
Koen Hindriks Multi-Agent Systems Koen HindriksMulti-Agent Systems Organisation Read Programming Guide Ch1-3 (+ User Manual) See: Tutorial: –Download G OAL : See –Practice exercises from Programming Guide –BW4T assignments 3 and 4 made available today Next lecture: –Sensing, perception, environments –Other types of rules & macros –Agent architecture