1 Welcome to CSE41MAS MultiAgent Systems LAB 4
Objectives Demonstration of how to implement agents using JACK 2
Contents A brief introduction to JACK and how to implement agents in JACK Examples 3
4 JACK Java Agent Compiler & Kernel
5 JACK JACK is an environment for developing agent-oriented systems. JACK is built on top of and fully integrated with the Java programming language. JACK is a product of Agent Oriented Software (AOS) Group. Download JACK for 60-day trial personal use:
6 Components of JACK The JACK Agent Language –Used to develop agent-oriented systems. It is a ‘super-set’ of Java, extending it with agent-oriented constructs. The JACK Agent Compiler –Debugs and converts JACK files into Java files. The JACK Agent Kernel –Runtime engine for JACK based agents. The JACK Development Environment (JDE) –A graphical development environment that can be used to develop JACK based applications. (not covered in this course)
Three basic files to constitute an agent in JACK The.agent file (The file extension is ‘.agent’, e.g., VacuumAgent.agent) –Specifies the agent’s name, the events the agent can handle, and the plans the agent uses to react to these events… The.event file (The file extension is ‘.event’, e.g., VacuumEvent.event) –Declare events an agent can handle The.plan file (The file extension is ‘.plan’, e.g., VacuumPlan.plan) –Describes a sequence of actions that an agent can take when an event occurs 7
8 Event template event SomeEvent extends Event { //Events are originators of all activity within JACK int count; //It is necessary to specify at least one posting method for the event #posted as go(int cnt) { count = cnt; }
9 Plan template plan SomePlan extends Plan { //Plan describes a sequence of actions that // an agent can take when an event occurs. #handles event SomeEvent e; //Each plan is capable of handling a single event. body() { //Actual steps performed when plan is executed. //… maybe do some actions here if( /*some condition*/) another event*/); //issue another event to keep the //agent working if not finish its tasks } //… maybe do some actions here }
10 Agent template agent Robot extends Agent [implements SomeInterface] { //The agent handles events of SomeEvent #handles event SomeEvent; //The agent uses a plan of SomePlan #uses plan SomePlan; //The agent posts events of SomeEvent #posts event SomeEvent ev; public Robot(String name) { super(name);//give a name for the agent postEvent( ev.go(99) ); //issue an event to start the agent }
Compilation In your current directory containing your source code, use the command: java aos.main.JackBuild 11.. Robot.agent SomeEvent.event SomePlan.plan Before compilation.. Robot.agent Robot.java Robot.class SomeEvent.event SomeEvent.java SomeEvent.class SomePlan.plan SomePlan.java SomePlan.class After successful compilation compile You need to correct your source code until so see [JackBuild Done] on the screen after compiling
How to make use of an agent Two ways: 1.Create an agent which can run by itself 2.Instantiate an agent inside another java class 12
Create a runnable agent Like a normal agent, but implementing the method called ‘main’ inside the file.agent, e.g.: … public static void main(String[] args) { … Robot robot = new Robot(“My Robot”); … } … 13
Instantiate an agent inside another class Create a java class, e.g., AgentSystem.java Implement the ‘main’ method inside this class, e.g.: … public static void main(java.lang.String[] args){ … Robot robot= new Robot(“My Robot”); … } … 14
Examples Implement an agent which autonomously counts integer numbers from 1 to 10 Download this example from: 15
16 CounterEvent.event file event CounterEvent extends Event { public int someNumber; #posted as doCount(int number) { someNumber = number; System.out.println(“The event occurs…”); }
17 CounterPlan.plan file plan CounterPlan extends Plan { #handles event CounterEvent e; body() { System.out.println(“Current number is ” + for 2 seconds if(e.someNumber == 10){ System.out.println(“Count to 10! The agent finished its job!”); System.exit(0); + 1)); }
18 CounterAgent.agent file agent CounterAgent extends Agent { #handles event CounterEvent; #uses plan CounterPlan; #posts event CounterEvent ev; public CounterAgent(String name){ super(name); //give a name for the agent postEvent( ev.doCount(1) ); //fire an event for starting to count } public static void main(String[] args){ CounterAgent counterAgent = new CounterAgent(“My Counter Agent”); }
19 Reading JACK TM Intelligent Agents Agent Manual ( dex.html)