Scripting your bot with AIML

Bot Libre now has complete support for the Artificial Intelligence Markup Language (AIML). AIML is a standard XML specification designed for scripting chat bot responses. AIML 1.0 was released in 2001, and the current 1.0.1 release was released in 2011. AIML 2.0 is currently under development. AIML is supported by many different chat bot programs and hosting services. Bot Libre supports all of the AIML 1.0.1 tags and a few common extensions.

About AIML

AIML defines how a bot should respond to a question using <pattern> and <template> elements. A pattern represents the user's question, and the template defines the bot's response. The pattern and template elements are grouped in a category element, which can be grouped under topic elements.

Here is a simple "Hello World" AIML example:

This code will make your bot respond with "Hello to you too" to the question "Hello World".

Patterns are normally defined as all upper-case, but are case insensitive, so the case really does not matter. Punctuation is normally stripped from patterns and ignored when matching. Patterns can contain wildcards using the "*" and "_" characters. Both "*" and "_" are the same wildcard, and will match any subset of text, their difference is in only in the order they are applied ("_" patterns are matched first, and "*" patterns last).

Here is a simple wildcard example:

This code will make your bot respond with "Hello to you too" to any question containing the word "hello".

AIML supports contextual responses through the "that" element. The "that" element specifies that the pattern should only be matched if the bot's previous response matches the "that" pattern. This allows the same question to be responded to in different ways, depending on the context.

This code will make your bot respond to the question "Do you like apples or do you like oranges" with "I love apples and I love oranges".

AIML libre

Bot Libre supports both importing and exporting AIML. AIML can be imported in two different ways, either as a program script, or as a chat log.

Importing AIML as a program script is done from the Program page. You can import and order the script with respect to your other scripts files. Scripts can be defined in either AIML or Self.

When you import an AIML file, it will be converted to Self code, and stored in your bot's brain along with all of its other information. The Self syntax for AIML is a hybrid syntax that uses AIML terminology, but with the Self scripting structure. Self is a state machine oriented language defined for Bot Libre's AI Engine originally from the Open Pandora's Box pen source project. Self is very different than AIML, but can process any AIML code similar to any other AIML interpreter. AIML imported as a program script will be executed similar to any other AIML interpreter.

Here is the Self code for an imported AIML script:

Importing AIML as a chat log allows the AIML categories to be integrated into the bot's knowledgebase. The pattern/template categories from the AIML file will be merged along with the bot's other question/response pairs that it has learned through conversation, correction, or importing.

The bot will not run the AIML script as a script, it will decide for itself when to use the response. The bot will choose its response based on how well the question matches the responses question, the responses correctness, and the context. Even without a * in a pattern it still may be matched to a similar question, if it is the best match available. This gives you the freedom from having to write a pattern for every possible phrase, by just letting the bot figure it out.

Using AIML in Twitterbots and Email Bots

AIML can be used to script Twitterbots, Email bots, or IRC bots, the same as bots trained through other mechanisms. AIML templates and patterns can be used anywhere other response are. AIML can be used from the Training page, used in correction in the Chat Logs page, or used for autotweets in the Twitter page.

AIML Resources

One of the main benefits of the AIML standard, is that there are a lot of AIML resources on the Internet. The are resources for both learning AIML, and there are many freely available AIML scripts for many domains, and in many different languages.

Talk with ALICE

To see what conversations AIML is capable of, try out ALICE on Bot Libre. There are two ALICE bots on Bot Libre. ALICE is a bot that has imported most of the ALICE AIML sets from the ALICE foundation. Free bots on Bot Libre have a 100,000 neuron limit, and some of the ALICE scripts are very big, so the mp* scripts were left out, as well as a few of the other big scripts. ALICE can chat, and if you type "joke" can tell you a joke.

ALICE libre is a hybrid bot, that has imported the ALICE AIML sets as chat logs, not as scripts. This means she is free to choose her responses. She has learning, and comprehension enabled, so can also learn new things.

Sara is a Spanish language AIML bot, that has imported the Sara AIML set.