An agent is implemented as an instance of a CLOS class. agent
class and script-agent
class are defined by AgenTalk. An
application program should define a class based on one of these classes.
Class: agent
agent
class provides the basic functionalities of an agent (such
as creating a new process for this agent, sending and receiving messages).
Class: script-agent
script-agent
class provides additional functionalities of an
agent which use the script facility. If an agent uses a script,
script-agent
class must be an ancestor of the agent's class.
Note that script-agent
is a subclass of agent
.
An agent has a unique name. A message can be sent by specifying the name of a receiver agent; it is not necessary to specify where the agent is.
The name of an agent is given in the form of
local-name@
location-name. Each location has a
post-office, which handles message delivery. In other words, each
post-office has a unique location-name. By registering an
agent at the post-office, an agent can receive messages from other
agents.
In the Common Lisp implmentation, each Lisp system has one post-offcie, and has a location-name. The location-name in an agent name can be omitted, if agents are in the same location (in the same Lisp system).
Note: The agent name is case-insensitive.
An agent is created using the make-instance
generic function.
The name of an agent should be specified by :name
initarg option.
Thus, :name
initarg option cannot be used by your application.
When a symbol is given as an agent name, its symbol-name is used.
Generic Function: add-agent agent &optional process-run-function &rest args
Primary Method: add-agent (agent agent
) &optional process-run-function &rest args
This function registers agent at a post-office. In
addition, a new process (thread) is created in a Lisp system for
agent. At this time, process-run-function is invoked with
arguments given by args. The default value of
process-run-function is the generic function
agent-toplevel
.
Generic Function: agent-toplevel agent &rest args
Primary Method: agent-toplevel (agent agent
) &rest ignored
Primary Method: agent-toplevel (agent script-agent
) script-name &rest args
The generic function agent-toplevel
provides a default toplevel
loop for an agent. The method for agent
repeatedly retrieves a
message from a queue associated with agent, and searches for a
message handler and invokes the message handler found.
The method for script-agent
accepts script-name as
an argument. The script with the name script-name is invoked when
this agent is started. args specifies the arguments passed to this
script invocation (see section Script).
Function: find-agent name &optional errorp
This function returns the agent whose name is given by name.
name can be a string or a symbol. When a symbol is given, its
symbol-name is used. If an agent whose name is name is not found,
an error is signaled if errorp is non-nil
, and nil
is returned if errorp is nil
(which is the default).
Function: agent-name agent
This function returns a name of agent as a string.