...
...
...
...
...
...
...
...
...
...
...
...
Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Dialogflow
Tip |
---|
Before you start: make sure your MARBEL agent is connected to your Dialogflow agent and you completed the Getting Your Conversational Agent Up and Running step. |
Noteinfo |
---|
Read more about creating intents and entities before you start on the DialogFlow: Create an Agent, Dialogflow: Creating Intents and Entities page. |
Creating a
...
greeting intent
You will need to create intents for your Dialogflow agent. The first intent we want to create is a greeting intent. When you inspect your Dialogflow agent’s intents, you will see there already is an intent called Default Welcome Intent. As we want you to create your own greeting (or welcoming) intent for your agent, you should remove this intent first. Before you do so, you can still check out the Training Phrases for this intent which you could reuse for creating your own greeting intent.
Delete the Default Welcome Intent in your Dialogflow agent.
Create a new intent called greeting.
Add Training Phrases: Add a number of several expressions (at least 10) as examples of how a user might greet your agent. Be thorough and try to cover as many phrases as you can come up with. For inspiration, you can do a Google search for greeting phrases. You may find, for example, useful phrases here: 20 Greetings in English. You can also ask ChatGPT to generate example phrases.
Under Action and parameters make sure the box above the table is filled in with the name of your intent as shown in the image below.
...
Note |
---|
Don’t forget to press SAVE! |
Tipwarning |
---|
Check Test that your greeting intent is working by using the microphone button in the test console on the DIalogflow 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 what a typical greeting pattern looks like. When the agent does not introduce itself, a very common greeting pattern could like look this:
...
In this example conversation, we see that agent A greets the user, and the user U greets the agent in return. We will now try to capture this pattern using the intent we just defined in Dialogflow.
To capture the example pattern, we will use the Prolog predicate pattern([PatternID | Sequence])
. Note that this predicate only takes a single list argument, but this list should always have the same structure: the first item in the list should be a PatternID
or name of the pattern, followed by a sequence of dialog moves or actor-intent pairs (more on this below).
...
The second part of the list we need to add as an argument when creating a pattern/1
fact consists of the sequence of dialog moves the pattern itself consists of. A dialog move has two parts: first, we need to specify who makes the move (in our case, the agent
or the user
); second, we need to specify the type of move made by either actor. As we will classify what agents and users say as intents, we will use intent labels for representing dialog move types. A dialog move then can be represented as a two-element list [Actor, Intent]
, where the first element Actor
is the dialog actor doing the talking (either the user
or the agent
) and the second element Intent
is the intent representing the dialog move type. The first move in our greeting pattern example above thus can be represented by [agent, greeting]
and the second move by [user, greeting]
. Combining this with the pattern ID c10
, the simple and most basic greeting pattern of our example can be represented by the following fact:
...
We have used the same name or label greeting
that we used for the user’s move and 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 user move’s intent and make making 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 responseresponses.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.
Greeting with self-introduction
Pattern C1.1: Opening Self-Identification (Agent)
Example:
A: hello
A: I'm _____
U: hi
This pattern will be quite similar to the one above, but should include the intent label 'selfIdentification'. Add a list [_,_]
predicate in the pattern list above for the new rule that tells the agent to self-identify. Also, note that the agent must have a name in order to self-identify.
...
Specifying the agent’s greeting
In the Prolog file responses.pl
, we determine how what exactly the agent will say to initiate a move in the conversation or how it will respond to something a user said, using the intent label from a pattern that indicates what type of response the agent should give. This is done using . 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…!
We will use the predicate text(Intent, Text)
to specify how the agent will greet a user. The first argument Intent
of the text/2
predicate should be instantiated with an intent label in a dialog move of the agent, and the second argument Text
should be a string atom with the text you want your agent to say. So, for example, in the case of the c10
pattern, we use the agent intent used in the pattern 'greeting' pattern([c10, [agent, greeting], ___])
. Add the new For the greeting
intent we thus need to specify at least one phrase by adding a text(greeting, "YOUR PHRASE HERE")
fact to the responses.pl
file. Now add such a text/2
fact for the intent label greeting
under the % Intent: greeting
comment. An example fact that you can add. for example, is text(greeting, "hi").
Next, we need to build the rule for selfIdentification.
The head of the rule should be as follows: text(selfIdentification, Txt) :-
Place it under % Intent: self-identification in responses.pl
This rule should produce a response that is returned as Txt and should include the agent's name.
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 Finally, you will not yet be able to respond with a greeting yourself without a welcoming page (see Visuals section below). This page should display a microphone icon that you will need to start talking back to the agent. |
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')
.
First, we need to define the agent name so we can access it later. The agent’s name is initialized at the start of the session. Find where you need to define the agent name somewhere in a .mod2g file.
Once you have defined your agent you can utilize the predicate that you inserted into its memory.
You should then return a sentence including the agent’s name as Txt.
Visuals
...
Now your agent has a name, we would also like the agent to self-identify and be able to use the following greeting pattern:
Pattern C1.1: Opening Self-Identification (Agent)
Example:
A: Hello.
A: My name is _____*.
U: Hi!
* insert your agent’s name here
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 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. Additionally, the new page provides the user with the ability to start talking 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)
. We advise you to reuse the same overall structure for the Prolog rule as for the Start page you created in the html.pl
file. Add your rule for the welcoming page also to the html.pl
file.
The main requirement for this page is that it shows a microphone icon that the user can use to start talking to the agent. All you need to complete has been provided. This page should show your agent’s greeting, to do for this is to create a page with a header. A second requirement is that your page should not have a button for moving on to the next page! Progress should be made by talking from now on! Ideas for this page could be to show a greeting and introduce your agent by saying showing its name!
...
. Next, we provide some suggestions on how you could proceed with creating the welcoming page for your agent:
As a start, consider the condition that needs to succeed when you generate this page (is generated. Hint: look at the start page rule body and rule for the Start page and check out how the first parameter argument of the
page/3
predicate is used in that rule) head of this rule is reused for defining the condition for showing the page.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!
Warning |
---|
To test, go to |
...
the design of your welcoming page. What should the page look like? You can show text that introduces your agent somewhere, using the
agentName(Name)
fact to retrieve its name, for example (if you do, also take into account what should happen if the agent has no name!). You can use https://www.w3schools.com/bootstrap4/bootstrap_jumbotron.asp, https://www.w3schools.com/bootstrap4/bootstrap_alerts.asp, or other Bootstrap components to display the text. You can add other visual elements using images, or add more advanced layouts for your page. Check out the Visual Support Guide for more on how to use these components.As before, try to organize the structure of your page into several segments or rows and organize the code for generating HTML in your rule to reflect this same structure. Then piece together the various parts of the page as you have seen before (if you have more than one part) and, finally, as a last step, use the
html/4
predicate to generate the content for the body of your HTML webpage.
Whether you followed our suggestions above or not, make sure your welcoming page looks inviting!
Run It!
Make sure you have added the c10
pattern to the agent’s agenda in the dialog_init.mod2g
file.
Test: Greet your agent
Test your agent by launching your MARBEL agent in Debug mode. 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 (only needed once every time you restart the browser when you launch the SIC server), 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 as a greeting intent by inspecting the terminal in which you launched the SIC server:
...
Also, pause the MARBEL agent and inspect the session/1
fact. You see that the greeting pattern has been completed and a new empty sequence has been added at the head of the session history (list).
Test: Respond with something different than a greeting
Terminate the MARBEL agent and restart it in Debug mode again. Repeat the interaction but this time, when it is your turn to speak, say something that is not remotely close to a greeting instead. Check out the terminal again to see how Dialogflow classified what you said. Pause the MARBEL agent and again inspect the session/1
fact. What is different, and what is the same? To understand what happened, check out the Session updating part at the top of the dialog_update.mod2g
file.
Check out Dialogflow’s Traning Tool
Throughout the development of your agent, it will be useful to (re)visit the Training tool of your Dialogflow agent: https://cloud.google.com/dialogflow/es/docs/training. Simply click Training in the left sidebar menu:
...
Click on some of the conversation phrases that you see listed in the Training view and inspect what intent (if any) the phrase was assigned to.
During the project, try to follow these Training | Dialogflow ES | Google Cloud | Best practices.
Info |
---|
All done? |
Proceed with https://socialrobotics.atlassian.net/wiki/spaces/PM2/pages/2216001572/ |