The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Agent - the Transportable Agent Perl module


  use Agent;

  my $a = new Agent( Name => '', %args );



Agent Perl is meant to be a multi-platform interface for writing and using transportable perl agents.

A Perl Agent

Is any chunk of Perl code that can accomplish some user-defined objective by communicating with other agents, and manipulating any data it obtains.

A Perl Agent consists of a knowledge base (variables), a reasoning procedure (code), and access to one or more languages coupled with methods of communication. These languages remain largely undefined, or rather, user-defined; support for KQML/KIF is under development.

Developing An Agent

Note that the developer must devise the reasoning procedure and knowledge base described above. Agent Perl does not place any restrictions on what you may do; it only tries to make the 'doing' part easier.

An agent is written as an inheriting sub-class of Agent. Each agent's class should be stored in a '.pa' file (perl agent), and must contain an agent_main() method. All agents are objects. See the examples for more details, and learn how works so you won't step on its toes!


Arguments to subroutines are passed in hashes unless otherwise noted.

Capital-a Agent refers to unless the context is obvious. Lowercase agent refers to an agent.



Creates a new agent object. You must tell new() where to get the agent by passing in one of the following arguments (in a hash):

Stored: The agent stored in a Tom object.

File: An IO::Handle (or any subclass) file handle from which the agent can be read.

Name: The agent's name. This prompts new to search @INC and './' for the agent's '.pa' source file.

Code: The agent's source code.

These are listed in order of precedence. To handle security issues, new() also groks this argument:

Compartment: A Safe Compartment within which the agent will be registered, and later executed. See the Safe pod for details.

Developers should note that these keywords are reserved. Any additional arguments are passed to the agent being created.



Returns the agent object in stringified form, suitable for network transfer or storage.


Executes the agent. If the Thread argument is passed and your system has, run() tries to execute the agent in an asynchronous thread via Thread's async() command (see the Thread pod for more details). Additional arguments are passed to the agent being run.


Returns a unique string identifying the agent in its present state.


Agent::Message and Agent::Transport for agent developers.


Steve Purkis <>


Copyright (c) 1997, 1998 Steve Purkis. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


James Duncan for the Tom module and many ideas; the people of the Perl5-Agents mailing list for their support.