Agents

Introduction

 

Agents are service providers which may be either local or remote. They may represent files, servers, shared memory, etc...  They are self-contained entities having state and communicating using message passing. Services are invoked asynchronuously and messages may arrive in any order.

 

Since an agent's services typically interact with the environment, they may also fail (link down, reading failure...).

 

 

 

 

 

 

 

 

 

 

 

 

and at first sight similar to objects in mainstream languages. Yet, they are a different and higher level. In OO, you precise the target and the message you send to it, having a synchronous response in exchange. With agents:

  • You can send a message to precise targets or to anyone
  • You can receive a message from precise sources or anyone
  • Message passing is asynchronous
  • You have the notion of conversation
  • Usage instead of inheritance

 

 

A simple agent

 

In this example, the agent solely listens to the console which is a "native agent". Messages sent from other sources are not taken into account.

 

agent ConsoleCounter

counter := 0

<< system.console : "bump"

 counter := counter + 1

 

<< system.console : "how much?"

>> system.console : toString(counter)

 

Since it is often cumbersome to write targets and sources, the keyword 'using' indicates the default source & target:

 

agent ConsoleCounter using system.console

counter := 0

<<  "bump"

 counter := counter + 1

 

<< "how much?"

>> toString(counter)

 

Both agents are strictly equivalent.

 

 

General senders and listeners

 

Instead of specifying to whom the messages are sent, or from whom they are received, one can simply put a '?'. Let us illustrate this by an example.

 

agent Reactor

temperature := 0

<< System.Timer : MinuteElapsed

temperature := temperature + 1

if temperatur > 100

>> ? : OverheatAlert

 

<< ? : Cooldown

temperature := 0

 

agent SecuritySystem

<< ? : OverHeat

>> from : Cooldown

 

The 'from' is a special keyword indicating from whom was sent the message. Notice that you have nothing more to add, there is no need to add listeners or such, Arplan will dispatch all messages accordingly to the receiving abilities of the various agents.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Conversations & jumps

 

 

agent WhereDoYouLive using system.console

<< Console.Ready

>> "Hi!"

askContinent

>> "In what continent do you live: " ++ concat(continents) ++ "?"

<< continent

if continent in continents

askCountry

>> "In which country from: " ++ countries(continent) ++ "?"

<< country

...

else

>> "I don't know the continent " ++ continent ++"!"

goto askContinent

 

 

 

 

Sources, targets & syntactic sugar

 

Here is a short summary of how you can send or receive messages.

 

To receive a message from anyone

<< ? : message

To receive a message from a precise source

 

To r

Receiving a message from a precise source

 

<< source : message

 

Sending a message to a target

 

>> target : message

 

Sending a message to anyone

 

>> ? : message

 

 

 

Aspect oriented agents

 

 

when to << from : msg

>> logFile : toString(from) ++ " -> " ++ toString(to) ++ " : " ++ msg

 

 

Asynchronous messages

 

 

 

Creating & killing

 

 

 

The 'using' keyword