Labeling support tickets with Robocorp tools
Last updated
Last updated
In this tutorial, you will learn how to use aito.ai with the Robocorp tools and run intelligent workflows in the cloud.
This tutorial expects you to be familiar with both Python and Robot Framework at least on a novice level.
If you want to follow along with this tutorial, get your own free aito.ai instance from the Console.
Sign in or create an account, if you haven't got one already.
In the Console go to the instances page and click the "Create an instance" button.
Select the instance type you want to create and fill in needed fields, Sandbox is the free instance for testing and small projects. Visit our pricing page, to learn more about the aito.ai instance types.
Click "Create instance" and wait for a moment while your instance is created, you will receive an email once your instance is ready.
After the instance creation is ready, you can access the URL and API keys of the instance by
Log in to Console
Click on the instance your created
Go to the overview page. You can copy the API keys after clicking the eye icon.
For this tutorial you will need to install and have access to the Robocorp Lab and Cloud. Robocorp provides you with good instructions on how to get access to their products in their docs.
How to install and setup Robocorp Lab & Cloud
Most companies nowadays have a ticketing system in use. Whether it be internal development or external customer support, usually everything has to have a ticket. To keep track of which tickets are important and relate to which team the ticket task belongs to, the tickets need to be labeled. The person labeling the tickets needs to read through the whole ticket before they can decide which class the ticket belongs, or how urgently it needs to be addressed. With many incoming tickets, this task takes a lot of time and isn't that motivating for the employees.
This is where aito.ai comes along and gives out the helping hand. aito.ai just needs the historical data on how have the tickets been labeled in the past and it can deduce how the new incoming tickets should be labeled.
aito.ai also gives a probability for the predicted label, so the employee can manually check those cases in which aito.ai wasn't entirely sure about the label. So instead of going through 50 tickets per day, the employee only has to check the more tricky ones. By using Robocorp you can create the whole infrastructure in a flash and have the whole process running in the cloud as a scheduled task.
The data used in this tutorial is gotten from Kaggle's ticket classification. The data comprises of anonymized labeled support tickets with original messages from users. There are two datasets. One is used as training data, so it is already labeled (category column) and includes also subcategory columns. Testing testing data does not have the labeling information (category) and the subcategories.
hi since recruiter lead permission approve requisitions makes please make thanks recruiter
1
4
2
21
71
3
4
connection with icon
icon dear please setup icon per icon engineers please let other details needed thanks lead
1
6
22
7
26
3
4
Setup Robocorp lab
Creating the ticket labeling robot
Running your robot in the Robocorp cloud
If you followed the instructions in chapter "Before you begin", you should now have an aito.ai instance, access to Robocorp cloud and Robocorp Lab installed.
First you will have to plan the workflow you want the robot to do. Where does the data come from? How to get it to aito.ai? What do I want to achieve with the classification? Where do I want to store the results?
To make things a bit easier for you, we have planned a workflow for the robot.
Download the training and test data CSV
Upload the training data to aito.ai
Create an output for the results that have a probability over a threshold
Create an output for the results below a threshold
Label the tickets defined in the test data
Add the good results to aito.ai as more training data
The idea behind the workflow is that we trust aito.ai to label the tickets correctly when the probability of the label is high enough, i.e. over a defined threshold, but if the probability is lower than the set threshold we want a human to check the results and fix them accordingly.
In the example workflow we add the results back to aito.ai which aito.ai has given high enough probability, just to show that training data can be easily added to aito.ai without any extra retraining steps. In reality you shouldn't add the results which are already good by aito.ai but the results the user has manually curated as then you'll train aito.ai to label the tricky ones better next time aito.ai is used to label tickets.
You can easily add python scripts in the Robocode lab template. Just add the python file to the root directory. Create a file called AitoRFHelper.py
to the root directory.
In the AitoRFHelper.py
you will write helper functions to transform the data, predict with aito.ai, create output files and write data to the outputs. Our Python SDK exists to make the integration of aito.ai easier to Python based systems. You can leave the AitoRFHelper.py
file empty for now, we will get back to it when starting to create the workflow for the robot.
Credentials
In order to use your Robot Framework robot with aito.ai, you will have to give it the URL and API key of your aito.ai instance. The Robocorp platform offers you a way to handle sensitive information through their vault. In that way you can have the sensitive information defined outside your repository either in the cloud environment or on your local machine. We will go through both setups, but let's first get the robot to run locally. In order to use the vault you will have to create a vault.json
somewhere on you machine and define the URL and API key as variables for your robot to use. Here are the steps to follow:
1. Create the vault.json
file somewhere on your computer (not in the robot's directory if you're thinking to add it to git for example) and store your instance information in the file as variables.
2. Next create a directory under your robot's root directory (the directory where you created the AitoRFHelper.py) called devdata
and create a json file in the directory called env.json
. Copy the following text into the env.json
and modify the RPA_SECRET_FILE to point to the vault.json
you created in the first step.
3. Then create another directory under your robot's root directory called variables
and under it a python script called variables.py
. Copy the following script to the variables.py
.
4. Open your robot file tasks.robot
and underneath the *** Settings *** add:
5. You're now able to use the instance URL and API key in the robot script by referring the variables ${AITO_API_URL}
and ${AITO_API_KEY}
respectively.
Setup aito.ai Client
After you have setup the credentials you can define the aito.ai Client in your robot file. In order to have all the necessary keywords at your disposal, you will also have to setup the aito.ai API. Just add the setup for the client and aito.ai API to your robot's settings as follows.
Now you're all set to start working on your robot!
The file in which the robot will be written exists in tasks/robot.robot
it is created by Robocode lab. Let's start going through the workflow step by step.
You will add the Keywords foŕ the workflow to the *** Tasks *** cell of the robot file. Add a keyword Download Ticket Data
to the tasks.
Next you will have to define what the keyword means. Add a *** Keywords *** cell and name the keyword as Download Ticket Data
. It's a good practice to add each new keyword as a new cell for the robot as it will allow you to run just a single keyword at a time. The library RPA.HTTP
includes a Download
keyword that can be used for downloading files from URLs. For this tutorial the data files have been uploaded to S3, you can use those URLs for your robot. Set the variable overwrite
to be True
, so that when the robot is run it will download new files and overwrite the old ones.
The library RPA.HTTP
has to be added to the *** Settings *** cell in order for the Download
keyword to work. At this point you can also add the AitoRFHelper
that you created earlier to the ĺibraries directory.
To test how the robot now runs press the forward button on top of the script. You will be asked to restart the kernel, press restart. The whole robot file is run. You can then check the log that everything was run successfully (you can ignore the warning about the missing keywords for now). The downloaded files should appear in the robot's directory.
Next you will have to upload the training data into aito.ai. The training data includes the already labeled tickets which aito.ai can then use to deduce labels for new tickets. To use the aito.ai Client add the Get Library Instance Keyword
keyword to the tasks. Then add a new task called Upload Training Data
, it will take in the name of the training data file and table name to be created to aito.ai as arguments. The tasks section should now look like the following.
You will also need to add a new library to the settings called Collections
to be able to use the Get Library Instance
keyword.
The training file and table name arguments are defined through variables, so you will need to add a new cell to the robot file called *** Variables ***.
You will also have to define the keyword Upload Training Data
as a new cell in the robot file. The Upload Training Data
keyword will only upload data into aito.ai if the table does not yet exist. The Quick Add Table
keyword, provided by the aito.api, will infer a schema from the CSV, transform the data, upload the schema and the data.
Now run your robot to check that everything works as expected.
Next create an output where you will write the results you deem have a good probability. Add a Create Output
task and define output and table name as arguments.
As output and table name are used as variables, add them to the variables as well.
Now you're missing the definition of the Create Output
so add the code that creates an output file to the AitoRFHelper.py
.
Now you can again run your robot to test that it works as intended. You should see the file output_aito_classified.csv
being created the tasks directory.
Checking the Python script
You can also test that your Python script runs by clicking on the script the same forward button as you would when running the robot.
Let's also create an output file for the results that need manual curation. Similarly as before add the Create Output
task to tasks. This tine use a different output variable for the file name.
Also remember to add the file name variable definition to variables.
You're now ready to test out this step. You should see the file output_needs_curation.csv
being created the tasks directory.
Now let's get to the real beef of this tutorial, labeling tickets using Aiaito.aito. First you can add a task that creates a simple predict and evaluate query from the uploaded data, we won't go through using the evaluate in this tutorial, but now you know how to get it. Then add a Label Tickets With Aito
task into tasks. It will take the headers of both the labeled output, the manual curation output and the predict query.
Then you can create the Label Tickets With Aito
keyword into a new cell. The keyword takes two arguments, headers for the output files. The test data is then read and formated from CSV into JSON as aito.ai queries work in JSON. The keyword Format CSV To Json
we created to the AitoRFHelper.py
previously when making the functions to add test data into aito.ai. The result is fetched separately for each row by a for loop and then the result is stored either into the labeled output or the manual curation output, depending on the probability of the result.
Add to the variables the field to be predicted as predictField
in this case it is category
and threshold you want to use for the predictions as threshold
.
If you look at the Label Tickets With Aito
a bit closer you'll notice that you still have three keywords which haven't been defined, Format CSV To Json
, Predict Row
and Append Output
. Those you will add into the AitoRFHelper.py
. The formatting of the file is needed for making the queries for aito.ai.
The query created in the predict_row
function, looks like the following (data from the first row of the test data is used as an example).
The from
clause defines the table we're using for the prediction. Resembles FROM in SQL.
The where
clause defines the prior information we have on the ticket by using propositions, e.g. "ticket_type": 0
. This information is used by aito.ai to deduce a label for the ticket.
In the predict
clause you define the column which you are trying to predict, in this case it's the category
column.
With "limit": 1
aito.ai will return only one result by default the results are ordered by highest probability to the lowest, so the first result is the one with highest probability.
Remember to also add the append_output
function to AitoRFHelper.py
before trying to run the labeling task.
Now you're ready to test how aito.ai makes predictions! Press the forward button in the robot script and see aito.ai in action. After running the robot you should now have content in the labeled output or the manual curation output files. It works, yay!
Now you have only one step left, adding more training data to aito.ai. Note that normally you should add the manually curated data into aito.ai as those tickets are the ones that are harder for aito.ai so it needs more data in order to do better labeling. Adding the results aito.ai gives can skew the accuracy of the predictions.
In this tutorial we use the data aito.ai has been sure about to add as training data, just to show how easy it is to add more training data into aito.ai (without any additional retraining steps!). Add a keyword Upload Data
to tasks.
Then add the Upload Data
keyword as follows. The data has to first be transformed into the JSON format (function was defined in the AitoRFHelper.py
) and then the Upload Entries
can be used to upload the data into aito.ai.
When you now run the robot, after labeling the data the robot will add the newly labeled data into aito.ai. And you're done building your robot! Next let's go through how to run the robot in the Robocorp Cloud.
The full robot can be foud as an attachment in this article, in case you just want to test running the robot in the Robocorp cloud.
Set up your robot in Robocorp cloud:
Click on your example organization (or use some existing organization, no need to create a new one if you don't want to)
Click on the "New Process" button
Give a name to the process e.g. "Ticket labeler"
Go to the "Robots" tab and click "New Robot"
Give the robot a name, e.g. "Ticket Labeling Robot" (otherwise use the default options)
Now open up your robot code in the Robocode Lab (robot.robot file)
Click the "Publish to Robocorp Cloud" button in the upper right corner
Select the correct Organization (your example organization), Process (Ticket labeler) and Robot (Ticket Labeling Robot) and click "".
Wait for the process to finish, you'll see a note in the bottom of the IDE that says "The robot was successfully pushed to Robocorp Cloud." when finished.
Click yourself to the "Ticket labeler" process and click "Add Step"
Select the "Ticket Labeling Robot" and press "Add to process"
Go to the tab "Vault" and press "Add"
Give the name "credentials" to the secret and click twice the "Add item" button
Now you're ready to run your robot in the cloud! Go back to the "Processes" tab and click "Ticket labeler", you should see a "Run Process" button, click it and the robot will start running.
Now that you have the robot up and about you could integrate it with your ticketing system. For example, you could choose tickets from a certain time period and upload them to aito.ai as training data. Then schedule the robot to be run on a certain day to get new unlabeled tickets from the ticketing system and use aito.ai to label them and write the labels back to the ticketing system. The tickets that need manual curation could be sent to the employee via email and he could then send the curated file to an email owned by another robot, which would be triggered by the email to store the data into the ticketing system and aito.ai as additional training data.
Open Robocorp Lab and click "Create new robot".
Name the robot e.g. "Ticket Classifier".
After the robot template has been created open the conda.yaml. In the conda.yaml, you can add all the different RF and Python libraries you need in order to create your robot. Under pip add aitoai==0.4.0
. The following configurations were used when this tutorial was created, use newer package versions at your own risk.
Define aito_api_url
and aito_api_key
to the keys section (use the read/write API key value) and click "Confirm". You can get your instance information through the Console.