Table of Contents
This example shows the following features:
Reactive tasks (receiving messages)
Requesting a collection of agents present
Task scheduling
Agent parameters in habitat xml file
Creating Agents
Carefully review the source files found in src/tryllian/scenarios/chat1. This directory contains the following files:
ChatTask.java (Task which sends chat messages) ChatterAgent1.java (The agent) CreateCopiesTask.java (Task which handles the a new ChatterAgent1) ListenToChatterTask.java Task which receives chat messages
Build the example by typing in the scenarios directory:
build chat1
Run the example:
habitat chat1.xml
It shows agents chatting to each other.
The ListenToChatterTask is an example of a ReactiveTask; a task that does nothing until it receives a message. It has a MessageFilter to filter the messages it wants to receive. When a message is accepted by the MessageFilter, the method handleMessage() is called. This method prints a message.
ChatTask sends messages to other agents using SendMessageTask. (tryllian.afc.task.interaction.SendMessageTask)
The ChatTask uses the tryllian.afc.task.find.Directory that it got using the tryllian.afc.task.AgentContext.getDirectory() to ask the system for all agents in the habitat.
Tasks can be scheduled in a particular order (normally, they will be executed in parallel) by adding them to a Task Scheduler (tryllian.afc.task.TaskScheduler).
Edit the chat1.xml file. After the following line,
<arg value="Mark"/>
add an extra argument to the second agent:
<arg value="3"/>
The arguments specified in the xml file are passed in a String[] to the constructor of the agent. The first argument refers to the name of the agent, the second argument specifies the number of extra agents to create. The agent creates other agents, by using tryllian.afc.task.standard.CreateAgentTask. Run the chat1 example again by typing
habitat chat1.xml
Watch the extra agents chatting.