Actuator

From Agent Factory

Jump to: navigation, search

Contents

Editorial History

19/12/08 (Version 2): Fixed Structure of page to match that the Perceptor page.

23/12/08 (Version 3): Added sections on how to work with Modules and Platform Services.

Introduction

Actuator units are the Java classes that implement the primitive Actions that an agent can perform. Actuators are associated with agents via the ACTION Construct of AFAPL2, and are ultimately invoked in response to the agents attempts to realise its Commitments.

Writing an Actuator

To create an actuator, you must extend the com.agentfactory.logic.agent.Actuator abstract base class and implement the act(...) method.

For example, an actuator that prints "hello world" to the console would take the form:

 package actuator;
 
 import com.agentfactory.logic.agent.Actuator;
 import com.agentfactory.logic.lang.FOS;
 
 public class HelloWorld extends Actuator {
   public boolean act(FOS action) {
     System.out.println("hello world");
     return true;
   }
 }

What support fields / methods are provided?

To support the implementation of the act(...) method, a number of helper methods have been provided by the Actuator base class, these include:

  • getModuleByName(String name): Returns a reference to the Module of the given name.
  • getModuleByClass(String className): Returns a reference to the first Module found with the given class name.
  • getModulesByClass(String className): Returns an array of references to the all the Modules with the given class name.
  • adoptBelief(String belief): Adopts the given Belief at the start of the next iteration of the agent interpreter cycle.
  • retractBelief(String belief): Retracts the given Temporal Belief immediately.
  • getService(String id): Returns a reference to the specified Platform Service.
  • getConfiguration(): Returns a reference to a Map containing the current configuration of the actuator.

Finally, the base class also provides a reference to the agent object that the actuator is associated with.

Linking an Actuator to an Action in AFAPL2

Creating the Java class is only part of the story. For an agent to use the actuator, it must be declared within the corresponding agent program. Here, we will focus on the AFAPL2 language, but actuators may also be used in AFAPL or any other logical language that is implemented using Agent Factory.

AFAPL2 programs are written in text files that have a ".afapl2" extension. In this file, perceptors are declared via a ACTION statement of the form:

 ACTION helloWorld {
     PRECONDITION BELIEF(true);
     POSTCONDITION BELIEF(true);

     CLASS actuator.HelloWorld;
 }

Basically, this statement declares that the agent will have an action called "helloWorld" whose implementation is realised via the actuator.HelloWorld Java class. The name of the `actuator is used in Commitments to specify which action the agent may perform. Also, as with perceptors, AFAPL2 supports configurable actuators (i.e. configurations can be passed into an actuator allowing the same implementation to be reused for multiple cases).

More information on this can be found on the actions page or in the AFAPL2 Programmers Guide.


Accessing a Platform Service from an Actuator

T.B.C.

Adding a Configuration to an Actuator

We can implement more generic actuators that allow us to configure the state as follows by making use of the configuration feature that is built into AFAPL2. To do this, we need to follow two basic steps:

1. Update the Action Declaration to pass a configuration:

This is done by augmenting the CLASS parameter of the ACTION statement:

 ACTION helloWorld {
     PRECONDITION BELIEF(true);
     POSTCONDITION BELIEF(true);

     CLASS actuator.HelloWorld {
         message=brave;
     }
 }

2. Modify the Actuator implementation to make use of the configuration:

This is done by invoking the getConfiguration() method:

 package actuator;
 
 import com.agentfactory.logic.agent.Actuator;
 import com.agentfactory.logic.lang.FOS;
 
 public class HelloWorld extends Actuator {
   public boolean act(FOS action) {
     System.out.println("hello " + getConfiguration().get("message") + " world");
     return true;
   }
 }

Now, we can create a second Action, say called "horribleWorld" that uses the same implementation:

 ACTION horribleWorld {
     PRECONDITION BELIEF(true);
     POSTCONDITION BELIEF(true);

     CLASS actuator.HelloWorld {
         message=horrible;
     }
 }


For a detailed treatment of actuators, please read the AFAPL2 Programmers Guide.