Chatterbots are 'conversational agents'. In actuality this overstates the case, since they are usually driven by fairly simple mechanisms.
There are several in existence. The first one was Eliza, which mimicked a psychotherapist. It made quite a name for itself because it succeeded in fooling some people it was a person.
For the most part, they are implemented by rules which map simple pattern matches on the left-hand side to canned responses on right-hand side.
ALICE: Artificial Linguistic Internet Computer Entity.
It won this year's Loebner Prize, which is based on the Turing Test. Alan Turing, a giant in the history of computer science, proposed in the 50's that a computer program will have acheived true 'intelligence' when a person holding a conversation with it (or at least reading messages from it on the other side of a barrier) will be unable to distinguish the source of the messages from a human.
Alice is open-source, so you can download it and play with it yourself, add it to your website and amuse your friends.
It's programmed using an XML DTD called AIML (Artificial Intelligence Markup Language) which defines tags for 'categories'.
When the user enters statements at a prompt on a webpage, Alice fits that statement to the most 'specific' category it can find, and returns the response associated with that category.
There are tools available to the 'botmaster' which show the recent message traffic, and allow him/her to write new categories.
At present, there are some 16,000 categories encoded for the occupant of alicebot.org.
[ Up to ALICE]
Typical Alice category tags have two component tags.
A pattern, eg: <pattern> I HAVE A * <pattern>
A template, eg:<template>Where did you get it?<template>
In the template, there are also ways that you can set and access the values of variables (such as 'it'), so that other categories can refer back to them when they fire. There's a tag <star/> which allows you to refer to the '*' part of the pattern. So a more elaborate template than the one above might be:
<template>Where did you get <set_it><star/></set_it></template>
Templates can also provide a listing of responses to be chosen at random.
Categories are chosen on the basis of most specific match. Specificity is basically determined by the number of tokens in the pattern.
Here's a sample of some AIML declarations.
Alice's results are actually quite impressive, because there are so many categories defined. This is an example of a simple implementation of Case-Based Reasoning (CBR), which stores up a large database of actually encountered cases. CBR systems try to find ways of matching relevant cases to the current situation, and using them as resources. Recall that this is the approach used in Machine Translation with Bilingual corpora, though the pattern matching scheme must certainly be more sophisticated than Alice,s
[ Up to ALICE]
Alice patterns try to be simple, so you can only have one asterisk per pattern.
However, you can recursively call other patterns within a template, using a tag called <srai>, stripping away each statement from the outside in: