CLF::Core API

From Agent Factory

Jump to: navigation, search

This library is provided by default for all agents that are implemented using a language that is based on the Common Language Framework. All of the examples provided on this page are based on AF-AgentSpeak. Details of other libraries provided with the Common Language Framework can be found here.

Actions

Some actions provide the kind of basic mechanisms you would expect of any programming language (e.g. .print(...), .println(...)), while others offer performance improvements (.adopt(...), .replace(...), .abolish(...)).

Action Description

.abolish(?belief)

Removes the specified belief from the belief set. If the belief contains variables, then all matching beliefs are removed from the belief set.
Example:

#agent example

fact(a);
fact(b);
fact(c);

+initialized : true <-
    .abolish(fact(?x));

All the fact(...) beliefs are dropped.

.println(?string)

Prints out whatever argument is passed to it to the console (and starts a new line).
Example:

#agent example

+initialized : true <-
    .println("Hello World");

Prints out "Hello World".

.print(?string)

Prints out whatever argument is passed to it to the console (but no new line).
Example:

#agent example

+initialized : true <-
    .print("Hello"),
    .print(" "),
    .print("World");

Prints out "Hello World".

.replace(?old, ?new)

Removes the old belief from the belief set and adds the new belief in one iteration.
Example:

#agent example

set(a);

+set(a) : true <-
    .replace(set(a), set(b));

+set(b) : true <-
    .replace(set(b), set(c));

+set(c) : true <-
    .replace(set(c), set(a));

The agent believes set(a) then set(b) then set(c) then set(a) ...

.adopt(?list)

Adds all the beliefs in the list (denoted [...]) in a single iteration.
Example:

#agent example

+initialized : true <-
    .adopt([fact(a), fact(b), fact(c)]);

The agent adopts fact(a), fact(b), fact(c) in a single iteration.

.drop(?list)

Removes all the beliefs in the list (denoted [...]) in a single iteration.
Example:

#agent example

fact(a);
fact(b);
fact(c);

+initialized : true <-
    .drop([fact(a), fact(b), fact(c)]);

The agent removes the initially adopted beliefs fact(a), fact(b), fact(c) in a single iteration.

.send(?performative, ?receiver, ?content)

Send a message to another agent - the message structure is based on FIPA ACL (as implemented in the AFSE Run Time Environment).
Example:

#agent example

+initialized : true <-
    .send(request, agentID(pong, addresses("local:localhost")), ping);

The agent sends a request to agent "pong" who is on the same agent platform asking it to perform the ping action.
More information on agent interaction can be found in the relevant language guides.

.fail

This action always fails and will cause the interpreter to enter "failure handling mode" if such a mode exists.
Example:

#agent example

+initialized : true <-
    .println("you see this"),
    .fail,
    .println("you do not see this");

Only the first .println(...) action is performed as the plan fails on the .fail action.
How the agent handles this failure (if it does) depends on the language used. Details of the corresponding failure handling mechanism can be found in the relevant language guide.

.nil

Does nothing.
Example:

#agent example

+initialized : true <-
    .nil;

The plan is performed but nothing happens.

.sleep(?time)

Makes the agent go to sleep for the specified time (time is specified in milliseconds). The action is blocking, so the agent will stop executing until the specified time elapses. Depending on the scheduler used, this may also block all the other agents on the platform. If you do not wish the action to block the other agents, you should use a multi-threaded scheduler. If you do not wish the action to completely stop the execution of the agent, you should combine this action with the durative(...) plan operator
Example:

#agent example

+initialized : true <-
    .sleep(2000),
    .println("hello");

The agents execution is blocked for 2 seconds, and then "hello" is printed to the console.

.bind(?id)

Causes the agent to be bound to the platform service identified by the id parameter.
Example:

#agent example

+initialized : true <-
    .bind(fipa.df);

The agent is bound to the FIPA Directory Facilitator service.

.installLibrary(?id, ?class)

The library corresponding to the Java class ?class is loaded at run-time and associated with the identifier ?id.
Example:

#agent example

+initialized : true <-
    .installLibrary(stacks, "com.agentfactory.clf.library.StackLibrary");

The stack library module is loaded (if it exists).

Sensors

Sensors provide beliefs that the agent can use to make decisions about how best to act. The Core API comes with a number of default sensors that are listed below.

Action Generates Description

.inbox

message(?performative, ?receiver, ?content)

Generates beliefs about messages that are received by the agent.
Example:

#agent example

+message(request, ?agentID, ping) : true <-
    .send(inform, ?agentID, pong);

Handles the receipt of a ping request message by sending a "pong" inform message back to the requester (see .send(...) action above for the requester code).

.services

service(?id)

Generates beliefs about the platform services that the agent is bound to.
Example:

#agent example

+initialized : true <-
    .bind(fipa.df);

+service(fipa.df) : true <-
    .println("bound to fipa.df service");

The agent binds itself to the fipa.df platform service, and prints out a belief to this effect when it beliefs that it has been bound to the service.

.self

name(?name)
agentID(?name, ?addresses)
time(?h, ?m, ?s)

Generates beliefs that are useful to know: the agents name, its agent identifier, and the current time.
Example:

#agent example

+time(12, 00, 00) : name(?name) <-
    .println(?name + "says that it is lunchtime");

Prints the string "XXX says that it is lunchtime" to the console at 12:00:00 (where XXX is the name of the agent).

Examples

Please read the Introductory Lesson of the AF-AgentSpeak language guide for basic examples on using this library.