Dialogflow
Before you start: make sure your MARBEL agent is connected to Dialogflow.
Read more about creating intents and entities before you start on the DialogFlow: Create an Agent, Intents and Entities page.
Creating a Greeting Intent
Make an intent called greeting.
Under `Training Phrases' add a number of expressions (at least 10) by which a user may greet - try and be thorough. For inspiration, do a Google search for `greeting phrases’. You may find, for example, useful phrases here: 20 Greetings in English.
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.
Don’t forget to SAVE!
Check that your ‘greeting’ intent is working by using the microphone button in the test console inside DIalogflow.
Prolog and Patterns
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. If you look at dialog_init.mod2g you can find on line 40 a place to define the name of your agent in a string → insert(agentName('Bellabot')
.
c10 Greeting Patterns
c10 Greeting with No Introduction
To make a pattern, you need to 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 Actor-Intent pairs (more on this below).
We shall start by considering how a greeting could go. When the agent does not introduce itself, the most common greeting pattern would look as follows:
Example:
A: hello
U: hi
In this example conversation, we see A(Agent) greets the user and U(User) greets as well. The first thing in our list within our pattern predicate is always the pattern identification code. In the case of greeting, this is c10. After this identification code, the dialogue moves in the pattern are specified consecutively . Such a move is represented as a two-element list, where the first element is the person speaking ('agent' or ‘user’) and the second element is the agent response label or the user’s intent (which should share a name with an intent on Dialogflow, be sure to communicate with your groupmates). Thus for this greeting, we reach the following rule head:
pattern([c10, [agent, greeting], [user, greeting]])
Make sure the labels (names of intents and entities) you use in your MARBEL agent code are exactly the same as the intents and entity entry names that you have specified in your Dialogflow agent! Small spelling mistakes (e.g., using capitals or not, or other misspellings) will cause issues later on! We advise using Camel case for intent and entity names, starting with a lowercase letter everywhere (except for the Training phrases that you add).
As mentioned before, this greeting should occur if the agent does not know its name. If the agent knows its name it should introduce itself.
Thus the complete rule should specify this condition, which could be done as follows:
pattern([c10, [agent, greeting], [user, greeting]]) :- not(agentName(_)).
c10 Greeting with Introduction
Pattern C10.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.
c10 responses.pl
In the Prolog file responses.pl
we determine how exactly the agent 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 predicate text(Intent, Text)
. The first argument Intent
of the text/2
predicate should be instantiated with an intent label 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 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. 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
Opening Page (visuals for the c10 pattern)
When a user has visited the Start Page and clicked on the start button, your agent should start talking. The head page(c10, _, Html)
for the rule you need to complete has been provided. This page should show your agent’s greeting, and introduce your agent by saying 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.
To test, go to dialog_init
on line 24, put c10
into the agenda, and run your agent. The line should look like this: insert(agenda([c10]))
. Note that unless the corresponding c10
pattern and response are also completed in the pattern.pl
and reponses.pl
, your code will not yet work. Therefore, check with your team members to make sure that they are done with that part.
Run It!
Add the c10
pattern to the agenda in dialog_init.mod2g
file. If you run your conversational agent, you should hit your start page, press the button, and then your agent should introduce itself. Then you should 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 your 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: