Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
Dialogflow
As a first step towards recipe recommendation, we want a user to be able to ask for a random recipe recommendation. The idea is that the agent would randomly select one of the recipes from its database and recommend that to its user. This may not seem particularly useful at this stage, when you only have implemented Capability 1: Greet, and Self-Identify, as a user cannot yet have made any requests for specific features of a recipe. However, at a later stage, when a user can also already have made such specific feature requests, using this capability makes more sense. In these cases, a user simply may not want to add any other feature requests and ask the agent to recommend an arbitrary recipe from those that satisfy the requests they have made thus far. We want to prepare the agent for doing just that already now. The first thing to do to enable this is to create another intent in your Dialogflow agent for requesting a (random) recipe recommendation. To create such an intent, you should follow the same steps as before:
Create a new intent with a name that is indicative of its function, such as requestRecommendation.
Add Training Phrases: Add several different expressions (at least 10) as examples of how a user might ask for a recommendation for any recipe from the agent’s database. Good examples would be: “Give me a random recipe,” “Can you recommend a recipe?” and “Show me a random recipe.” Be thorough and try to cover as many phrases as you can come up with. For inspiration, you might again ask ChatGPT to generate example phrases for requesting a random recipe recommendation. But do not stop there. Also, think about what a user might say if they no longer want to add any recipe features but simply want the agent to recommend a recipe based on the conversation thus far.
Note |
---|
Refrain from including any specific recipe features in your phrases as this may later confuse your Dialogflow agent when we add intents to allow a user to ask for such features! ChatGPT will most likely come up with phrases that include such features. Although you should not add these now, they may come in handy later when you are asked to think about specific recipe features! |
Under Action and parameters make sure the box above the table is filled in with the name of your intent. You do not need to define any parameters since a recipe recommendation does not require the specification of any specific parameters. Keep the warning above in mind, however!
Note |
---|
Don’t forget to press SAVE! |
...
|
Prolog and Patterns
This section is about implementing the dialog management capabilities of the conversational agent but also about implementing the domain logic that the agent needs to be able to perform its task. As our conversational agent is a task-based agent for recipe recommendation, the conversational competence of our agent focuses on patterns and responses for recipe recommendation. The logic that we need to implement concerns the capabilities our agent needs to reason about user requests about recipes that are available in the agent’s database. We will first focus on adding some conversational capabilities for our agent to respond to a user request to provide a (random) recipe. As before, the approach to dialog management that we use here will require the definition of a pattern and the specification of a (textual) response to the user request. When we have completed that part, we will continue with the part focusing on implementing the reasoning capabilities for extracting such a recipe from the database in Prolog. This will require the definition of several rules for extracting a suitable recipe from the agent’s recipe database.
...
Warning |
---|
To test the pattern you just added, as before, you still need to do one more thing: In the You can now Run your Conversational Agent again to hear your agent ask you for your recipe preferences. Note that your team must have also added the recipe recommendation page (but not the recipe confirmation page; see Visuals section below) to enable you to respond to the agent’s inquiry. This page is needed to display a microphone icon that you will need to respond to the agent. |
...
Tip |
---|
Each team member: add one of your favorite recipes to the end of the There are two details that you should think about:
After adding your recipe to the database, commit the file to your team's git repository. You will need to merge your changes. For more on how to do that, check out the https://socialrobotics.atlassian.net/wiki/spaces/PM2/pages/22157066572709487788/2025+Project+Background+Knowledge#Git-Commands section on how to merge and resolve conflicts. (You should not have conflicts but just in case, that section should help you resolve those.) |
...
This clause specifies that if there are no filters to apply (i.e., the filter list is empty), the output of this filtering of a list of RecipeIDs
thus remains unchanged and is that same list of recipe identifiers RecipeIDs
.
Visuals
Recipe recommendation page
...
At this stage, for this capability, we will only provide code for a very basic skeleton page that provides the minimal functionality needed to implement the main requirement for this page: enable a user to talk to the agent using a microphone button. The design is kept minimal below and in the step-by-step walkthrough below we will only use a single and simple alert element to style the page. As the recipe recommendation page will be the first interaction point for users who are actually interested in finding a recipe, we leave it up to you to try and make this page more inviting and add clear and useful content that the agent will show. Note that we will also ask you to extend this page at a later stage when you are implementing Capability 5: Filter Recipes by Ingredients and Cuisine.
Step 1: Adding the head of a Prolog rule for a recipe recommendation page.
...
Implement the code for generating the HTML code for the page after the condition we just added. For now, we will just add a simple https://www.w3schools.com/bootstrap4/bootstrap_alerts.asp to the page to inform the user about the recipe recommendation task the agent and the user should engage in. We use the
div/4
predicate (see the 2025 Visual Support Guide) to add an alert class with a centered heading text. Add the following code to the rule that we are implementing:div('<center><h1>What recipe are you looking for?</h1></center>', 'alert alert-success', '', MainElementContent),
...
Warning |
---|
If your team has implemented the Dialogflow intents and patterns for this capability, you can already test the page you just implemented for the So try and Run your Conversational Agent again to see the page you just created. Also, check out the MARBEL agent’s state using the introspector. You should see that the top-level pattern that is at the front of the session is |
...
The next page that we want you to add is a recipe confirmation page. At the end of the pattern enabling a user to request a (random) recipe, the agent inserts the a50recipeConfirm
pattern ID in the agenda. No pattern has been added for this pattern ID yet, but because it will appear at the top level in the agent’s agenda, we can already create a confirmation page for the recipe that is selected. The idea is that this page allows the user to preview the recipe and indicate whether they are satisfied with the recipe (confirm) or not (disconfirm). To enable a user to make this decision, the main requirement for this page is that it shows the recipe’s name, and what the result of cooking the recipe will look like (a picture of the recipe). A second requirement is that the page shows a microphone button to enable the user to inform the agent about whether they want to (dis)confirm the recipe. Note that at a later stage, we will ask you to extend the recipe confirmation page when you implement Capability 6: Filter by Number of Ingredients & Recipe Steps https://socialrobotics.atlassian.net/wiki/pages/createpage.action?spaceKey=PM2&title=Capability%206%3A%20Filter%20by%20Number%20of%20Ingredients%20%26%20Recipe%20Steps.
For the design, a https://www.w3schools.com/bootstrap4/bootstrap_cards.asp element seems a suitable element for styling the page. We will use it below to create a first (but still simple) recipe confirmation page with a basic recipe card. We will want to generate the following HTML code for this card:
...
Before we can even begin to create the recipe card that we have in mind, we need to retrieve the ID for that recipe. So we begin by doing that. Add the following code to the rule:
currentRecipe(ID),
Now we can begin to generate the HTML code for this recipe. We first generate the code for the recipe picture and use the
picture(ID, URL)
to retrieve the URL to the recipe’s picture to fill in the...
for the src attribute in the HTML card template above and theimg/4
predicate defined inhtml.pl
for creating an image element. Add the following code to the rule:picture(ID, URL),
img(URL, 'card-img-bottom', '', ImageElement),
Next, we generate some HTML code for a card title heading. We want the recipe name to appear as the card’s title and will retrieve that using the
recipeName(ID, Title)
predicate and use the predefined to_upper_case/2 predicate (seeutils.pl
file) to make sure the recipe title starts with a capital. To fill in the recipe title in the right place in the card title heading template, we useapplyTemplate/3
to replace the placeholder~a
in a template for a card title. Add the following code to the rule:recipeName(ID, Title), to_upper_case(Title, UpperTitle),
applyTemplate('<h4 class="card-title">~a</h4>', UpperTitle, TitleHeading),
The next part that we will generate is the card body element using the
div/4
predicate. We want our card title to be the content of that element and use that as the first argument of our div/4 predicate (the first arguments of our predefined predicates by convention are the content of an element, see also the 2025 Visual Support Guide). Add the following code to the rule:div(TitleHeading, 'card-body', '', CardBodyElement),
Finally, we need to combine the card body and image elements (check for yourself to see that they are combined within the card element HTML code above) and create the card element. We use the
atomic_list_concat/2
predicate for combining the elements together and thediv/4
predicate again to create the card element. Add the following code to the rule:atomic_list_concat([CardBodyElement, ImageElement], CardContent),
div(CardContent, 'card', 'width:400px', MainElementContent),
...
If you have not yet done this, add the a50recipeSelect
pattern ID to the agent's agenda in the dialog_init.mod2g
file. When you finished implementing this capability and you Run your Conversational Agent again, you should be able to conduct the following conversational interaction and go through the following dialog moves:
...
Info |
---|
All done? Then proceed with Capability 3: Select Recipes by Name. |