Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Dialogflow
Tip |
---|
Before you start: make sure your MARBEL agent is connected to Dialogflow. |
Note |
---|
Read more about creating intents and entities before you start on the DialogFlow: Create an Agent, Intents and Entities page. |
Creating a Greeting Intent
Create an intent called greeting in your Dialogflow agent.
...
Tip |
---|
Check that your greeting intent is working by using the microphone button in the test console on the DIalogflow console page. Try various phrases also using the test console and check whether what you say is recognized as a greeting intent. |
Prolog and Patterns
Greeting pattern without self-identification
We shall start by considering how a typical greeting pattern looks like. When the agent does not introduce itself, a very common greeting pattern could like look this:
...
We have used the same name or label greeting
that we used for the user’s move also for the agent’s move in the pattern that we defined. This makes sense conceptually because the moves are the same type of move, i.e. a greeting from one actor to another. The same intent label, however, should be handled very differently for the agent than for a user. Dialogflow should handle the natural language understanding (NLU) of a user’s move first by (transcribing the speech and then) classifying the move as an intent. In contrast, the MARBEL agent should handle the agent intent and make sure the agent generates natural language (NLG) text as output for a speech synthesizer. A user’s intent thus can be viewed as an input label whereas agent intents can be viewed as output or response labels. Below, we will see how we can provide texts for the agent to make its move in the responses.pl
file. Because the same intent label for a user and for an agent are handled in very different places, there is no harm in using the same label either, and we can keep things conceptually simple.
Specifying the agent’s greeting
In the Prolog file responses.pl
we determine what exactly the agent will say to initiate a move in the conversation or how it will respond to something a user said. The basic idea is to add natural language phrases, sentences, or text for each type of move the agent can make. In other words, we need to specify phrases for all the intent labels that occur in dialog moves in all patterns that are made by the agent. If there is no phrase specified at all for one of the agent’s possible dialog moves, the agent will not be able to perform that move…!
...
Info |
---|
If you add only one |
Hear your agent say its first words
Warning |
---|
To test and hear something, you still need to do one more thing: In the You can now Run your Conversational Agent again to hear your agent say its first opening words. Note that unless the corresponding |
Greeting with self-identification
You and your team should think of a name for your agent. Feel free to be creative. We need to tell our agent its name somewhere. In dialog_init.mod2g
, on line 40 you can add the name you came up with for your agent. Change the empty string in insert(agentName('')
, for example, to insert(agentName('Bellabot')
. Now your agent has a name, we would also like the agent to self-identify and be able to use the following greeting pattern:
...
This pattern is quite similar to the C1.0 pattern above, but consists of one more dialog move made by the agent. The second dialog move that is new in the C1.1 pattern we call a self-identification move. We suggest that you use the intent label selfIdentification
for this agent move. Although Moore’s classification has it that this pattern is a c11
, the difference with the c10 pattern is small and can be handled easier by our dialog manager agent if we use the same c10
label again for this only slightly different pattern. You should now be able to add another c10
pattern to the patterns.pl file which adds the self-identification move of the agent as an additional actor-intent pair. Of course, for this pattern to be selected, we should add the condition (as we did before above but now) that the agent has a name: not(agentName(''))
.
Specifying the agent’s self-identification
We still need to specify at least one phrase for the agent’s selfIdentification
intent. We can do this by simply copying the agent’s name we inserted in dialog_init.mod2g
but a more generic approach is to use the agentName(Name)
query to retrieve this name from the agent’s database. This approach will also show you how you can use facts stored in the agent’s database to create text responses for an intent. The basic idea is to introduce a rule defining text(selfIdentification, Txt)
instead of a simple text(selfIdentification, "SOME PHRASE")
fact. For the body of this Prolog rule, you need to specify a query that concatenates two strings: A string such as “My name is” and a string of the agent’s name. To specify this query, the string_concat/3
predicate will be useful. Add the rule under the comment % Intent: self-identification
in the responses.pl
file.
Warning |
---|
When you have added a name for your agent, and the new pattern and rule for generating a self-identifying phrase, you can now Run your Conversational Agent again to hear your agent self-identify itself. |
Visuals
...
Welcoming Page
When a user has visited the Start Page page and clicked on the start Start button, your agent should start by greeting its user. But we would also like to show a webpage that welcomes the user and is shown while the greeting pattern c10
is active and ongoing. A new page should be shown if only because we need to provide the user with the ability to start talking too by clicking on the microphone icon.
As before, we need to introduce a rule for generating a webpage. The head of this rule should be page(c10, _, Html)
. The main requirement for the rule you need to complete has been provided. This page should show your agent’s this page is that it shows a microphone icon that the user can use to start talking to the agent. All you need to do for this is to create a page with a header. Other ideas for this page could be to show a greeting, and introduce your agent by saying showing its name!.
Consider the condition that needs to succeed when you generate this page (Hint: look at the start page rule body and how the first parameter of the
page/3
predicate is used in that rule).Think about what you want to be on this page. It needs somewhere to show text to introduce your agent. For this, you can use a card or an alert, for example. This will be the first atom in your HTML code that we use in Step 3. The second atom should be HTML code with
text(formatted)
to introduce your agent, i.e. what you want to go on your alert or card. In Step 5 we need to format the HTML code by formating the Prolog string with ‘applyTemplate’. This means that in this second atom there should be a placeholder for the variable with the name of the agent. Read the Visual Support Guide for hints on how to do that.Use a predicate to combine the first atom and second atom you created in the previous step (check out the Visuals Guide for how to do this). What we created in HTML above is our template, and the predicate should return the variable
Template
.Now we need to get the agent's name in order to add it to our text. This knowledge should be somewhere in the agent's memory. Hint: Look at line 40 in
dialog_init
for the applicable predicate. Retrieve the name of the agent in a variable.Next, you should use the
applyTemplate/3
predicate to add the agent’s name to our HTML code atom (which is also explained in the Visual Support Guide).Lastly, you should use the last variable that you used in the
applyTemplate/3
predicate and use thehtml/2
predicate to convert your code snippet into a completed HTML page. This can be done by usinghtml(YourCompleteHTMLCodeVariableHere, Html)
.Html
is the variable that returns the page as you can see in the head of the rule.
Run It!
Add Make sure you have added the c10
pattern to the agent’s agenda in the dialog_init.mod2g
file. If Then test your agent. When you run your conversational agent, you should:
hit your
...
Start page,
be able to press the Start button,
and
...
after you do so, your agent should introduce itself
...
;
then you should be able to unmute yourself by clicking the microphone icon in the top left corner,
give Google Chrome permission to use your microphone, and
return the greeting, by saying hello or anything else you come up with that sounds like a greeting.
Check if whether your Dialogflow agent understood what you said and classified what you said into a greeting intent by inspecting the terminal in which you launched the SIC server:
...