Creating your own implementation of the agent loop

Writing the Java code
In order to create your own implementation of the agent loop, you need to create a (possibly indirect) subclass of class AbstractAgent.

The documentation of the classes and methods involved in the implementation of the agent loop can be found here.

The agent loop is implemented in the agentLoop() method of your subclass. For example:

 // The agent loop for the planning agent.
public void agentLoop() throws Exception
{	ActionSequence plan;
	String goal;


	// if agent sets goal autonomously, use: getObservations() and showSelectedGoal(goal)


Observation gathering and execution of the plan should be performed by calls to method getObservationsAndGoal() (or to one of its variants), and to method performPartOfPlan(). All of these methods are defined in class AbstractAgent, and take care of the interaction with the graphical user interface.

Calls to the inference engine should be performed by calling methods computeOneTrajectory() and computeAllTrajectory(). The list of files that are required by these methods can be retrieved by applying method getFiles on fields aFiles (agent files) and dFiles (domain files) of class AbstractAgent. For example, a code fragment that computes one plan is:

		MathSet files=new MathSet();
For further details on this topic, you can look at the sources of the PlanningAgent and DiagnosticAgent classes, which are contained (after the APLAgent Manager has been started for the first time) in your home directory, in subdirectory APLAgent/AGENTS/AGENT_CLASSES.

Compiling the agent class
Agent classes are compiled by running the javac compiler and specifying the location of the APLAgent Manager jar file in the classpath option.

For example, PlanningAgent can be compiled as follows: (the instructions below assume that a Unix-like system is being used)

% cd $HOME
% javac -classpath /path/to/aplagentmgr/aplagentmgr-0.7.jar:$CLASSPATH
When you create your agent classes, keep in mind that a current restriction of the APLAgent Manager is that the compilation of the agent class must result in a single .class file. (This restriction is expected to be lifted soon.)

You completed the last section of the tutorial. Click here to go back to the main page.

For details on the agent architecture, please refer to:
Marcello Balduccini and Michael Gelfond.
The papers are available from the Papers section of the Knowledge Representation Lab web site at Texas Tech University.