SYSC5103 Software Agents RoboCup and BDI Architecture Fall 2006 • • • • Yousif Al Ridhawi Morvarid Sehatkar Walter Kung Gayathri Jayaraman Outline • • • • Multi-Agent System and BDI Architecture; Jason and AgentSpeak(L); RoboCup; Design and Implementation of Jason Environment; • Design and Implementation of soccer player behavior; • Performance Results; • Evaluate Jason as a BDI Programming system; Multi-Agent System and BDI Architecture • Multi-agent system is the sub field of artificial intelligence, which studies systems involving multiple agents and their coordination. • When a group of agents in a multi-agent system share a common long-term goal, they can be said to form a team. • The BDI architecture is being widely used in dynamic and complex scenarios where agents may need to act under incomplete and incorrect information about other agents and the environment where they are situated. • The BDI model has some philosophical basis in the Belief-Desire-Intention theory of human practical reasoning. Jason and AgentSpeak(L) • Jason is a Java-based platform for the development of multi-agent systems • Jason is one of the interpreter for an extended version of AgentSpeak(L). • AgentSpeak(L) is the abstract languages based on BDI architecture. • AgentSpeak(L) maintains a set of beliefs and a set of plans. • The set of beliefs represents the information an agent presently has about the world • A plan is a sequence of steps the agent needs to execute in order to handle some perceived event. • A AgentSpeak(L) plan has – – – – – A head: triggering event A context: predicate for the plan to be considered applicable. A body: a sequence of basic actions head : context <- body e.g. “+e : true <- !g” RoboCup • Soccer Server – Provides a virtual field that simulates all movements of a ball and players. – Send field information to Clients via UDP/IP socket. • Soccer Monitor – Display graphical representation of the game. – Initial kick-off command. • Clients – client controls movements of one player by sending commands through UDP/IP socket to the server. Design and Implementation of Jason Environment jason.environment.Environment interface: SendCommand boolean executeAction(String ag, Term action) move(double x, double y); turn(double moment); turn_neck(double moment); dash(double power); kick(double power, double direction); say(String message); void stop() addPercept(Literal l) void init(String a[]) void move(double x, double y) void turn(double moment) void turn_neck(double moment)void dash(double power) void kick(double power, double direction) void say(String message) void changeView(String angle, String quality) void mainLoop(String[] a) throws IOException void send(String message) void see(VisualInfo info) void hear(int time, String message) void see(VisualInfo info); void hear(int time, int direction, String message); void hear(int time, String message); NewBrain SoccerPlayer int isAction int timedelay NewBrain brain SensorInput 1 n VisualInfo Memory Vector m_objects StringTokenizer m_tokenizer String m_message void store(VisualInfo info) ObjectInfo getObject(String name) void waitForNewInfo() Vector getBallList() Vector getPlayerList() Vector getGoalList() Vector getLineList() Vector getFlagList() void parse() Communication between threads Activity Chart RoboCUP Server init() Thread NewBrain(n) Thread SoccerPlayer Jason Send "Init" receive team side Send player visual info Process actions Add Perception to Jason Send actions executeAction handle the actions Process Perception. Generate actions Issues and Lessons Learned • Issue: Perceptions were added before the previous action could be completed. Solution Introduced a time delay between an action and the next perception received. • Open Issue: In multiplayer environment, multiple threads (one for each player) access the same environment methods resulting in socket overwrite. Recommendation (from Jomi Hubner) Use of Agent Architecture class (for each agent) instead of using environment class (Work in Progress) • Open Issue: Lack of good explanation of the APIs and examples in Jason documentation. • Open Issue: Debugging the code using breakpoints. State Diagram for Soccer Player Behavior ball(null) turn(20) Checking(ball) ba ll( D is ball(null) to the goal GDir - Direction kick(GDir, 100) ba ll ( t, D ir, nu ll ) 0, 0 ) Dist>1 Dash(25*Dist) ta nc D ef is ro t> m 1 th e ba ll. Found(ball) is Checking(goal) Dir <> 0 turn(Dir) <= ist :d is t kickoff D idle 1 D Goal(null) turn(20) AgentSpeak(L) Code //BELIEFS checking(ball). //PLANS // If the ball is not visible. go to checking(ball) state +ball(null) : true <-ball(null); -ball(Dist, Dir, DistChang, DirChng); turn(40); +checking(ball); -checking(goal). // If kickOff occurs. +kickOff <?ball(Dist, Dir, DistChang, DirChng); -ball(Dist, Dir, DistChang, DirChng). // REACHBALL: The ball Dir is correct and dist is okay. Search for the goal +ball(Dist, Dir, DistChng, DirChng) : Dist <= 1 <+checking(goal); !kick(goal); -ball(null). // Sub Goal 1: see goal, then kick ball +!kick(goal): goal(GDist, GDir, GDistChng, GDirChng) & checking(goal) <kick(100, GDir); -goal(GDist, GDir, GDistChng, GDirChng); -checking(goal). // Sub Goal 2: do not see goal, then search for goal +!kick(goal): goal(null) & checking(goal) <turn(40). // The ball Dir is not correct, turn to match dir +ball(Dist, Dir, DistChang, DirChng) : not (Dir = 0) & not checking(goal) <-ball(null); turn(Dir). // If ball is out of reach, run toward it. +ball(Dist, Dir, DistChang, DirChng) : Dist > 1 <-ball(null); -checking(goal); -ball(Dist, Dir, DistChang, DirChng); dash(Dist * 25); .wait(kickOff). // if I see the goal, that means is not goal(null) +goal(GDist, GDir, GDistChng, GDirChng) <-goal(null). // vice versa +goal(null) <-goal(GDist, GDir, GDistChng, GDirChng). Time Comparison Jason Implementation vs Krislet Time(ms) for first goal in each Trial Run Jason Implementation vs Krislet 1200 SoccerPlayer 539 927 553 976 455 960 447 955 452 1019 465 967 1000 800 Time in ms Krislet 600 400 200 522 915 486 1014 0 1 507 975 514 1047 2 3 4 5 Trial Run SoccerPlayer 6 Krislet 7 8 9 10 BDI Programming System Requirements • The programming language has to be expressive – Able to describe the agent behavior without regarding how agent is implemented. • Reasoning of system has to be flexible – Able to decide, moment by moment, which action to perform in the furtherance of its goals. • Has to be responsive to the environment – Interpreter must be fast. – Must have correct response to all situations. Expressive: AgentSpeak(L) describe agent using abstract notions. Checking(ball) ba ll( D is t nu ll) 0, 0 ) Dist>1 Dash(25*Dist) e ba ll. Found(ball) Di st // Turn if the agent do not see the goal. +!kick(goal): goal(null) & checking(goal) <- turn(40). ,D ir, ba ll ( an Di ce f st ro > m 1 th kickoff :d idle ball(null) to the goal GDir - Direction kick(GDir, 100) // Kick if the agent see the goal. +!kick(goal): goal(GDist, GDir, GDistChng, GDirChng) & checking(goal) <- kick(100, GDir); -goal(GDist, GDir, GDistChng, GDirChng); -checking(goal); +checking(ball). ball(null) turn(20) ist // FOUND BALL: The ball Dir is correct and dist is okay. Search for the goal +ball(Dist, Dir, DistChng, DirChng) : Dist <= 1 <- +checking(goal); !kick(goal); -ball(null). Checking(goal) Dir <> 0 turn(Dir) = t< is D 1 Goal(null) turn(20) Flexibility : Deliberate to Select Achievable Option. // Option 1: If the ball is in range, kick the ball +ball(Dist, Dir, DistChng, DirChng) : Dist <= 1 <- +checking(goal); !kick(goal); -ball(null). • The following perceptions are added – – • There are two options that could be triggered. – // Option 2: If the ball is in range, find goal +ball(Dist, Dir, DistChng, DirChng) : Dist <= 1 <- +checking(goal); !check(goal); -ball(null). // SubGoal 1: Kick ball to goal +!kick(goal): goal(GDist, GDir, GDistChng, GDirChng) & checking(goal) <- kick(100, GDir); -goal(GDist, GDir, GDistChng, GDirChng); -checking(goal). – • • Option 1 has an unachievable sub goal (!kick(goal)) which required the goal location is known. Option 2 has achievable sub-goal. (!check(goal)). The interpreter should pick option 2. However, Jason pick option 1 and generate the following error. – – – – // SubGoal 2: Check the goal location +!check(goal): goal(null) & checking(goal) <- turn(40). +ball(0.5, 0, 0, 0) +goal(null) [test1] Found a goal for which there is no applicable plan: +!kick(goal) @l__4[source(self)] +ball(Dist,Dir,DistChng,DirChng)[source(percept )] : (Dist <= 1) <- !kick(goal); -ball(null). : {Dist=1, Dir=0, DirChng=0, DistChng=0} [test1] No fail event was generated for +!kick(goal) Flexibility (cont’) • // REACHBALL: The ball Dir is correct and dist is okay. Search for the goal +ball(Dist, Dir, DistChng, DirChng) : Dist <= 1 <- +checking(goal); !kick(goal); -ball(null). // SubGoal 1: kick ball to goal +!kick(goal): goal(GDist, GDir, GDistChng, GDirChng) & checking(goal) <- kick(100, GDir); -goal(GDist, GDir, GDistChng, GDirChng); -checking(goal). // SubGoal 2: check goal location +!kick(goal): goal(null) & checking(goal) <- turn(40). Jason was successful in picking the achievable plan if the condition is specified in the context part of the plan. Responsive to the Environment // If ball is out of reach, run toward it. +ball(Dist, Dir, DistChang, DirChng) : Dist > 1 <- -ball(null); -ball(Dist, Dir, DistChang, DirChng); dash(Dist * 25). RobuCup Send Perception Action Processing Jason Send Command Before Kick-Off ball(20, 10, 0, 0) dash(500) Dash(500) and failed ball(20, 10, 0, 0) No response to the old perception • Jason handled goal as event. • When event occurs, it triggers plans. • Advantage: responds quickly to the environment. It behaves like reflex action. • Disadvantage: there is no check whether the goal is accomplished or not. • Jason does not respond to incomplete goal. Conclusions • Successfully implement soccer player in RoboCUP using BDI development framework. • Noticeable performance difference in terms of speed between the Java code implementation of Krislet and the Jason version; • Agent Speak(L) can express agent behavior using abstract notions; • Jason BDI reasoning engine is not flexible with the option deliberation; • Jason has no verification whether the goal has been accomplished; Backup slide: Jason Environment Player Actions Soccer Field Visual Info RoboCup Server Jason Environoment Intension Perceptions Intention Selection BDI Engine Belief Base Plan Library Actions Backup slide: An interpretation cycle of an AgentSpeak(L) program