PowerWheel Ep2 - Virtual Agent and AI Builder

AI Builder is one of my favourite announcements in June. It brings the power of AI technology to all users. Just in a few clicks, you can build and train complex AI model and then later use it in your application. Just as easy with new Virtual Agent you can setup bot that can leverage really complicated scenarios. And next thing what we should do is obvious - we need to integrate them!

Let’s start with the AI Model itself. Right now we have 4 options available for us: Binary Classification, From Processing, Object Detection and Text Classification. In this example, I will use my prebuilt Text Classification model. It uses the simplest form of classification and divides text on Positive and Negative. Because of the simplicity of the input data, I don’t have a really high score, but it will do it for us. If you want to know more about building your text classification model please visit official docs.

AI Model

When you have your model we need to create a flow that our Virtual Agent Bot will call. You need to create your Flow inside the solution because right now Bot can call just solution aware Flows. Triggering step should be HTTP request (When a HTTP request is received). As Request Body JSON schema put the next JSON:

{
    "type": "object",
    "properties": {
        "text": {
            "type": "string"
        }
    }
}

Trigger Step

Then I will initialize two variables: Tag (text) and Score (Float). We will use them to contain our results.

Init Variables

Next, we will use Predict step - this is a new CDS step that allows you to use your AI Model inside the flow. Choose your model (Sentiment Scoring in my case). And inside Request Payload put an object with text property and input text (see image below).

Predict Step

Now we need to parse JSON. Select Parse JSON step and put Response Payload as Content and next JSON as schema:

{
    "type": "object",
    "properties": {
        "predictionOutput": {
            "type": "object",
            "properties": {
                "results": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "type": {
                                "type": "string"
                            },
                            "score": {
                                "type": "number"
                            }
                        },
                        "required": [
                            "type",
                            "score"
                        ]
                    }
                }
            }
        },
        "operationStatus": {
            "type": "string"
        },
        "error": {}
    }
}

Parse JSON

Now the last step is to set our results into our variables. Because our results will be an array (that contains just one value) we will need to use Apply to each control. Put results from our previous step there. Now we will need to set our Tag and Score variables (see picture below).

Set Variables

Great, let’s return our results. Select Response and return an object with Tag and Score property (don’t forget to fill Response Body JSON Schema with correct data).

Response

Now when our Flow is ready we need to go to our Bot. Create a new Topic (Sentiment in my case). Add User response and output it to a variable (SampleText in my case).

User Response

Then add Action and select your Flow (Get Sentiment). Put SampleText as input for a Flow. And then output received results.

Flow Action

That’s it. You can see how it works in a gif below.

PW Ep2

I hope you found this article useful. Next time I will talk about the Portals.

PW Ep2 Wheel

Oleksandr Olashyn

Oleksandr Olashyn

My name is Oleksandr Olashyn. I’m a Dynamics 365 Developer located in Kyiv, Ukraine.