What's new in AIML 2.0
Bot Libre now supports the AIML 2.0 draft specification. AIML 2.0 is the second release of a standard XML specification designed for scripting chat bot responses. The AIML 2.0 draft was released in 2013, and last updated in 2014. AIML is supported by many different chat bot programs and hosting services. Bot Libre supports all of the AIML 2.0 draft tags and a few common extensions.
About AIMLAIML 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:
For more information on AIML 1.0 see Scripting your bot with AIML
What's new in AIML 2.0
AIML 2.0 defines many new template tags, as well as now allowing some tags to be used in patterns. AIML 2.0 also adds new pattern wildcards, and some different element usages.
Here is the list of new AIML 2.0 features.
AIML 2.0 Patterns
AIML 2.0 adds new wildcards, special characters, and now allows the usage of some tags inside patterns.
Patterns in AIML are normally defined as all uppercase, but Bot Libre automatically ignores case, so patterns can be defined as lowercase or mixed. Bot Libre also allows for special characters in patterns such as +, %, ?, etc.
^ and # WildcardsNew ^ and # pattern wildcards that match zero or more words. This makes it easy to define keyword patterns such as:
The new $ pattern marker can be used to make a pattern word match highest priority. The main purpose of this is to allow patterns to take priority over _ and # wildcards. _ and # have odd semantics and should normally be avoided as they can easily lead to loops and block other patterns. _ and # can be useful for things like profanity filters:
() and  ListsList support is not part of AIML 2.0. But Bot Libre now supports some syntax from ChatScript. Brackets can be used in a pattern to define a required set of words, or optional set of words. (round) brackets are used to define an optional set of words, and [square] brackets are used to define a required set of words.
The new <set> pattern tag can be used to match a word from a predefined set of words. This allows wildcards to be defined for specific types, such as numbers, verbs, places, animals, etc.
In Bot Libre sets are not stored in files like other AIML implementations. AIML is a text processing language, but Bot Libre is object, or knowledge oriented. Each bot has its own object oriented knowledge base that stores all of its responses, and knowledge. Each word is represented by a meaning knowledge object in the bot's knowledge base. Knowledge objects can have relationships to any other knowledge objects, including their classification types. A word's meaning is defined through the #meaning relationship, and a knowledge object's type is defined through the #instantiation relationship.
The set operation in Bot Libre basically checks if the type of the word's knowledge object matches the set value. This allows for a knowledge object to be added to any set through setting its #instantiation relationship. This can be done using Self scripts, the AIML map tag, and is done automatically for numbers, basic types, and words or data loaded from Wiktionary, Wikidata, or Freebase.
Response list script to set a knowledge object's type:
AIML template to set a knowledge object's type:
Tags such as <bot> can now be used in patterns. AIML 2.0 only requires some tags be usable in patterns, but Bot Libre allows most tags to be used. Using tags in patterns lets you define some pretty creative patterns.
AIML 2.0 Templates
AIML 2.0 adds many new tags, and some new semantics that let you do some pretty powerful things.
Attributes as elements
Tag attributes such as name, value or index on tags like bot, get, set, or condition, can now be defined as XML sub-elements instead of XML attributes.
This may not seem like a big difference, but it allows for other AIML tags to be evaluated inside the attributes. This is a very powerful feature, and lets you define much more dynamic AIML.
The new <map> tag can be used to lookup the value for a word in a predefined mapping. This allows for easy mapping between values.
In Bot Libre maps are not stored in files like other AIML implementations. AIML is a text processing language, but Bot Libre is object, or knowledge oriented. Each bot has its own object oriented knowledge base that stores all of its responses, and knowledge. Each word is represented by a knowledge object in the bot's knowledge base. Knowledge objects can have relationships to any other knowledge objects. The map operation in Bot Libre basically looks up the relationship on the knowledge object.
Bot Libre extends the map operation to also allow setting the map value. This will set the value of a relationship on the knowledge object.
Conditions and Loops
Conditions now allows values to use patterns. This makes it easy to define default cases.
The new <loop> tag can be used to loop a conditional block. This allows for programmatic scripts to be defined similar to a programming language. This lets you do some pretty powerful things, even mathematics. However, XML is not an ideal programming language, on Bot Libre if you are using complex conditions and loops, it is normally better to use Self scripting, instead of AIML, as Self has similar syntax to other programming languages.
The new <learn> and <learnf> tags allow the bot to learn new response. The difference between the two is that for learn the new response is only remembered for the conversation, and for learnf the new response will be remembered persistently. However, in Bot Libre everything is always persistent, so both tag will learn persistently.
The learn tag takes a new <category> element as its content. The category can contain a <pattern>, <template>, <that>, and <topic> element. learn uses the <eval> tag to distinguish between tags that should be evaluated, and tags that should be part of the new category elements.
The new <sraix> tags allow the bot perform a remote request of another bot or service. sraix is similar to the srai tag that recursively evaluates the element text as if it were a question. However, sraix does not have the bot evaluate the question locally, but instead asks another bot or service the question. This is probably the coolest new feature of AIML 2.0, and opens up the whole chat bot world. Bots can now talk to other bots, and find things through web services.
sraix is a very cool feature, but not very useful on its own, as you need other bots to talk to, and services to make use of. Unfortunately AIML only defines the tag, it does not define a standard web API for requests, or define a standard set of services. Fortunately Program AB the AIML 2.0 reference implementation does define a sraix web API. Bot Libre supports both calling this API, and supports this API on our servers. So you can now sraix any Program AB web API compatible bot or service, and any Program AB web API compatible bot or service can request any Bot Libre bot.
AIML 2.0 defines the Pannous service as being the default for any sraix request. Pannous is a virtual assistant service that can answer a wide variety of questions, such as weather, definitions, math, and much more.
Bot Libre also provides several other services:
sraix supports several attributes to define the bot or service request:
sraix opens the door to the world, but be careful with your usage. Do not spam another bot with requests, or make use of any service that violates it terms of service, and use an API key when required.
Out of bound tags
Out of band tags let you pass tags or commands to the bot client. The client could make use of the tags to control its avatar, or execute services on a phone or mobile device.
Bot Libre's web and mobile SDKs do not currently support oob tags, so oob tags are not currently supported.
For reference, here is the complete set of AIML category tags.
For reference, here is the complete set of AIML patterns tags and characters.
For reference, here is the complete set of AIML template tags.
AIML in Bot LibreBOT 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 Scripts page. You can import and order the script with respect to your other scripts files. Scripts can be defined in either AIML or Self.
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 training, 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 using a heuristic algorithm. 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 frees you from having to write a pattern for every possible phrase, by just letting the bot figure it out.
Using AIML in Twitter, Facebook, Email, and IRC BotsAIML can be used to script Twitter, Facebook, Email, 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.
Bot Libre's AIML 2.0 support is implemented by translating AIML into Self. Self 2.0 provides many new extensions to support the AIML 2.0 feature set, as well as a lot more functionality than is not available in AIML.
AIML ResourcesOne 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.
AIML 2 DemoTo see what AIML 2.0 is capable of, try out the AIML 2 Bot on BOT libre.