When we first released, we had added a set of demo skills that could be written in C# and invoked within AIML files. While it was powerful, it wasn’t particularly easy to develop and deploy new skills without recompiling the entire application.

In this release, we solve that. You can now write skills in your favorite (scripting) language and invoke within your AIML files without having to recompile the application. We haven’t officially released this feature just yet but if you compile the application from source on the master branch, you will get the ability to write Dynamic Skills. So how does it work? Read on.

Introducing “Scripted Skill”

As the name suggests, this skill invokes a third-party script (that you write) and mashes the results into your AIML template response. Take a look at an example AIML below.

<?xml version="1.0" encoding="UTF-8"?>

<aiml version="1.0">



<category><pattern>* PLUS *</pattern>

<template>{{skill:scriptedskill,interpreter:node,scriptname:math.js,args:<star/> + <star index="2"/>}}<star index="2"/> plus <star index="1"/> is {{key:Result}}</template>

</category>



</aiml>

The pattern * PLUS * handles incoming utterances like 4 plus 3. This should produce a response like 4 plus 3 is 7. Now let us look at what is happening inside the template response.

{{skill:scriptedskill,interpreter:node,scriptname:math.js,args:<star/> + <star index="2"/>}}

This is the meat of the technique. Double curly brackets are unique to Karmaloop AIML Bot Server and do not form a part of AIML specifications. {{skill: lets the server know that a skill needs to be invoked before the final output utterance is formed. To invoke a scripted skill, we write skill:scriptedskill, then pass additional information like what kind of interpreter needs to be invoked (NodeJS in this case) and the name of the script along with the arguments that the script needs to execute. If I was to invoke the script in the AIML above as a terminal command, it would look something like this.

$ node math.js 4 + 3

So basically this invokes your scripts and passes information onto your skill script to process further. Now the question is what should the script return and how does the response utterance mash it?

Every scripted skill should simply print a standard JSON to the console which then gets parsed into a key value pair dictionary. You can then use those keys to mash their values into response utterance via {{key:MyKeyName}} where MyKeyName is the key you returned from your skill.

Your skill script MUST respond in this JSON format:

{
message: <Message string (optional)>,
keyvalues: [
{key: ‘my_key_name’, value: <my_value>},
{key: ‘my_key_name_2’, value: <my_value_2>}
]
}

You can now mash the key values into your response as {{key:my_key_name}}

OK so that is about it for building scripted skills! Now you can knock yourself out and build a super bot with skills written in your favorite language 🙂


Leave a Reply

Your email address will not be published. Required fields are marked *