Writing a simple agent in Genius

Genius provides a sophisticated platform to create and simulate your brand new and genius negotiation strategies against the existing literature. Sequel to my previous post on the intro to Genius, this write up extends the flow of writing a new bargaining agent code and running it on the platform.

There are two ways of integrating a new agent to the Genius. If you have access to the Genius source code, you can write your code right inside the Agents repository and use ant build to rebuild the final package. This approach gives access to reuse the duplicating methods inside other agents straight away and also to repackage the final product with any third party library you will be using. Secondly, you can write your code simply as a new project and include the .class file as a new agent after running the existing distribution. Even though the latter has a lesser pain, it limits your scope of the project. However, I will cover latter approach from this tutorial (will cover the former approach in another, hopefully) and especially necessary programmatical steps in writing a simple agent code.

In Genius platform, any class that is an instance of the negotiator.Agent class will be treated as an Agent instance and inherits the relevant attributes. Hence, we need to extend any agent code using the Agent parent class.

  1. Start a new Java project on your favourite IDE (Mine is Intellij IDEA)
  2. Add downloaded negosimulator.jar to the project classpath. In “Idea” you can do that by adding it as a library in Module settings (Figure 1).
  3. Create a new class called SimpleAgent.java and then extend it from the negotiator.Agent class and implement the abstract method called chooseAction(). This method is called whenever our agent needs to perform an action. (i.e.: When the opponent has proposed a bid to the negotiation space, and it’s the turn of our SimpleAgent to either accept it or propose a new bid, then this method will be called.)
Figure 1 : Add negosimulator.jar to the module settings

Please refer the code snippet for SimpleAgent below. Yes, the code might look a bit lengthy, still you will find operations for all the phases of the bargaining life cycle of an agent there.

For the simplicity, I will summarize the rationale behind each agent operation below.

enum ActionType : This enum can be used to store and map the different actions of the opponent referred by the getAction() method.

init() : This method will be called at the initiation of the agent and can be used to initialize the variables to be used during the runtime.

getVersion() : This simply overrides the getVersion() of the parent class and sole use is to store the version of your code.

recieveMessage() : This method will be called everytime our agent is invoked with reference to the opponent’s action in the negotiation space.

chooseAction() : This method is called whenever our agent needs to perform an action. (i.e.: When the opponent has proposed a bid to the negotiation space, and it’s the turn of our SimpleAgent to either accept it or propose a new bid, then this method will be called.). Based on the state of previous offers made by both agents, we can map our operations logic inside this method. For an instance, In case of an OFFER from the opponent and if our previous action is null (means this is round two and opponent has already made the starting offer), we have a choice between either accepting his OFFER or to generate our initial offer (Line 68). Similarly, if the previous action of both the agents are null, we can conclude it’s our opportunity to start and made our initial offer. Otherwise, we can either accept opponent’s offer if it meets our constraints or else to generate a counter offer.

Please note, here I have not done any evaluations to the opponent’s offer nor the state rather than generating a random bid for every occasion.

Then compile the project and locate SimpleAgent.class file. Run the negosimulator.jar file using java -jar negosimulator.jar and add the agent using the class file as follows.

Adding SimpleAgent by the class file

If our agent is added successfully, you will be able to see it at the bottom left hand side pane. Then create a new bargaining scenario using our agent and start it. If you use SimpleAgent against another SimpleAgent instance, you will be able to see any flaws during the complete flow.

If you are lucky enough, one of our agents will accept the random bid of the opponent to reach an equilibria.

Cheers!