Integrating xAPI into a Rasa Educational Chatbot: Part 1
To evaluate the effectiveness of an educational chatbot, stakeholders need to have access to data about activity within the bot. Many edtech tools do not make data available. More open tools often have a high learning curve to set up sufficient data collection and analytics reporting. However, while data availability is critical, consistency in the data is also important. Chatbots, in particular, are often tools in a broader system that students, instructors, and other stakeholders interact with. As mentioned in the previous blog post, xAPI can be a useful way for chatbots to make data available and align with other tools in a learning environment.
Rasa, an open-source conversational AI platform, is a good development platform for educational chatbot projects that will use xAPI. As an open-source platform, Rasa gives full access to its code. That lets you change it or add in capabilities with relative ease compared to other closed, proprietary systems. Many fields use Rasa for chatbot projects, not just the field of education. Because Rasa is open source, it allows one to add features necessary in an educational environment, such as xAPI. Additionally, Rasa gives full control over how you set up xAPI. While this setup will involve a significant amount of work, you will be able to craft statements that actually fit your organization’s needs.
In this short series, we will cover how to integrate xAPI into a Rasa project. Part 1, this article, will focus on building the foundation, including setting up an LRS, setting up the xAPI library, and testing the connection between xAPI and the LRS. In Part 2, we will actually build a system to report custom statements about the activity that takes place in a math quiz bot.
Setting Up the Project
The project we will be using is a math quiz chatbot. Download the source code for the project if you would like to follow along. At the end of the article, there is another link to the updated code if you’d just like to read the article.
This tutorial assumes you have the project set up and are using an environment compatible with Rasa 2. Additionally, you should be using Python 3.6. Each code repository includes a pre-trained model, so you only need to run rasa shell to start it up. If you haven’t used Rasa before, you might find this blog post and series useful.
Once you have set up the project, you should be able to have a conversation like this.
Setting Up the LRS
Learning record stores (LRS) validate and store xAPI statements. While many LRSs are available, we will use Veracity Learning’s LRS. It’s pretty simple to get started with and has a free offering.
Go to https://lrs.io/ui/users/login/. If you already have a Veracity account, log in. Otherwise, click Create an account.
Fill out the information for your account. Click Create Account.
Once you have logged in, click CREATE AN LRS.
Fill out the LRS information. The “LRS Name” becomes part of the URL used to receive statements. The “Display Name” shows up in the UI of your LRS pages. API Mode and Verbose Logs are probably best left to the default settings. You can change all of these settings later. Click Create.
For our chatbot to access the LRS, we need to create an access key. This key will have a username and password the bot can use to connect to the LRS when sending an activity statement. Click Manage Access Keys.
Click Create Access Key.
The default settings should work fine. However, you can make any adjustments you feel necessary. In the key name field, though, you should write a descriptive name related to what will use the key. This lets you use different keys for different applications and keep track of those keys easily. For our application, we will integrate xAPI into a chatbot that serves math quizzes, so “Rasa Math Quiz” might be a good name.
Be sure to write down the username and password. Then, click Create.
Click Home.
Under the LRS you created, you should see a URL. It should be in the format of https://{LRS name}.lrs.io/xapi/. To forward data to this LRS, though, you need to add port 443. The URL we need to put into our chatbot is https://{LRS name}.lrs.io:443/xapi/. Make a note of that URL since we will use it later.
At this point, you should have a username, password, and URL for the LRS instance. We will use these to connect our educational chatbot to the LRS after we set up xAPI.
Setting Up xAPI in the Application
With the LRS ready to receive our statements, we need to add xAPI to the Rasa math quiz project. We will integrate xAPI into the chatbot’s actions component, which uses Python. Rustici Software, the company responsible for developing xAPI’s initial release, has a Python library for xAPI. That’s great because we don’t have to develop everything from scratch!
Navigate to the TinCanPython repository. Click Code.
Click Download ZIP.
Unpack the contents of the ZIP into the main folder of the application. You should have a new folder called something like TinCanPython-3.x.
This folder contains all the necessary scripts for you to make and work with xAPI statements. The tincan subfolder contains premade scripts to help you make valid components for a statement. The docs folder has code to autogenerate documentation. The examples folder provides a sample script that builds a statement piece by piece and then interacts with the statement in a variety of ways, including saving the statement to an LRS. The test folder has similar files as the previous folders, but this folder is for running tests. For our purposes, we won’t use all the capabilities this library gives us, but it’s great to have these available for your projects.
Testing the xAPI Package
Before you can run a test, though, you need to install some dependencies. Depending on your environment and how you install dependencies, the command you use might change. However, I used Anaconda Prompt, so I installed these dependencies with the following command:
conda install aniso8601, pytz
Now, xAPI needs the access key information from earlier to connect to the LRS. In the TinCanPython-3.x folder, navigate to the resources folder (TinCanPython-3.x > TinCanPython-3.x > test > resources). Copy lrs_properties.py.template to a new file called lrs_properties.py.
Fill in the configuration information. The endpoint should use the URL you created earlier (ie., https://{LRS name}.lrs.io:443/xapi/). The username and password may look quite different from the example, but you should just use the information you collected earlier from the LRS. For the version, you can use “1.0.3.”
With the credentials set, you can use the tests to actually interact with the LRS. Open a terminal and navigate to TinCanPython-3.x > test. Enter python main.py.
As the tests execute, they will save some sample statements to your LRS. Some of the tests might fail, but that is fine. Our goal is just to make sure that xAPI can run instead of completely fail.
Back in your LRS, you can view the data the test scripts sent by going to xAPI Data > Statements. The Statements page should have a list of condensed statements. To see the statements in full, click on the arrow in the Icons column next to the statement you want to view. These samples are helpful models to use when building your own statements.
The Statements page does not update with new data automatically. You need to refresh the page before seeing updates. As you test out reporting you’ve added to various parts of a chatbot project, it is more convenient to have Veracity do this page refresh for you every few seconds. Click Options. Then, click Auto Refresh.
So far, we have built a foundation for recording how users interact with the chatbot. We have set up the math chatbot project, made an LRS, and added xAPI to the project. We’ve tested out the connection between the xAPI Python library and the LRS. The library can send statements, and the LRS will store them.
Here is a link to a repository with the code so far.
In the next article, we finish setting up the ability for the Rasa chatbot to report custom statements based on user interactions. The bot will collect descriptive information, build an xAPI statement, and send it to the LRS.