Floyd is implemented as a set of Perl scripts: several libraries for generic XProcs coupled with a main program that defines the Floyd-specific behavior. The libraries themselves are intended for reusability and ease of customization. By using Perl's package support, a semi-object oriented style is supported: the agent's state is stored in global variables, but method inheritance is used for customization.
The current set of libraries have three classes of increasing specificity: a generic ccrBot that manages file channels and parsing of ccrl, a TalkBot that is capable of listening and responding to speech in an easily defined way, and a UDPBot that augments the TalkBot to also support UDP message receiving, including a primitive ping protocol shared by all UDP XProcs.
The heart of the behavior of an XProc is a loop that implements a
stimulus/response paradigm. Each line of input is treated as an
isolated event that might need a response. The Perl libraries each
implement a doInput function that parses all input, handles
messages it knows how to handle, and passes on all other input. The
generic TalkBot simply sends all Emit energies to a user-supplied
table of responses to particular speech. The table is an easily
created list of regexp
function mappings. For example,
here is a portion of Floyd's table of responses to speech he hears:
%floydTextMap = (
"^good $name" => sub { emit("Thank you, $args{Subject}")},
"^$name help" => \&printHelp,
"^$name register (\\ S+)" => sub { registerFloydCmd($1) },
"^$name who is up" => \&pingFloydNetwork,
"^$name learn from (\\ S+)" => sub { learnFromOtherFloyd($1) },
"^$name where is (\\ S+)" => sub { queryForLast($1) });
UDPBot augments the doInput method of a TalkBot by also parsing out any UDPReceives. In addition, the UDPBot code intercepts two base UDP protocol messages, bu ping and bu pong, used to check whether another UDPBot is running. By providing a generic base level protocol, standardization of UDP messages is encouraged.