Remove a Filter and See Recipes on Demand
Prolog and Patterns
We will begin with implementing a pattern for allowing a user to express they are done, and then get back to what is still missing to implement requests to remove a filter.
A user does not want to specify more recipe constraints
The pattern that we want to implement to enable a user to express they do not want to provide more information is the following:
(A: Can you elaborate on what you're aiming for in your recipe?)
U: I don't want to add anything else.
A: OK. Here is a list of recipes that you can choose from. [Alternative: Sorry, there are still too many recipes left to show them all. Please add more preferences.]
The first move has been put between brackets because, as explained above, it does not belong to the pattern that we want to implement but to the a21featureRequest
pattern. The new pattern is named a21noMoreFilters
, as it fits best in the A2 category of Request patterns in Moore and Arar’s taxonomy. It starts with a disconfirmation move of the user and continues with an agent intent that either does or does not grant the user’s request.
But what would granting the user’s request mean? The idea is to somewhat lift our previous restriction of only showing pictures of the list of filtered recipes when there are no more than 15 recipes left. The agent can, for example, show the list of filtered recipes if there are a 100 recipes or fewer left when a user indicates they do not want to provide more information. It does not seem reasonable to show many more recipes, as that does not seem to align well with the ambition to develop a conversational first agent. In other words, our agent should not grant the request if the recipe list still is more than a 100 recipes long. (The exact number, of course, is a bit arbitrary, and it is up to you if you want to argue for changing it.)
We can base the name for the agent intent on our design choice to show more recipe pictures and call the one that grants the user’s request pictureGranted
, and the one that denies the request pictureNotGranted
. Using these labels, you can implement two versions of the a21noMoreFilters
pattern in the patterns.pl
file. And don’t forget to add responses for the agent intents pictureGranted
and pictureNotGranted
to the responses.pl
file. This will require you to define two rules with a different condition on the number of recipes left. Recall that you can use the recipesFiltered/1
predicate to compute a list of the filtered recipes and use that to compute how many recipes are still left after filtering.
There is still one thing missing… Just by talking the agent will not change the page that is displayed. Recall that you have created two pages for the a50recipeSelect
pattern for Filtering by Inclusion . When the agent grants the user’s request we still need to make sure that the second recipe recommendation page showing the recipe pictures is displayed. To make that happen, we need to change the condition for showing that page. You now must find a way to pass information that the recipe overview pages should change.
Finishing the implementation for removing filters
Most of the work that needs to be done to remove filters again has already been done. Various patterns implementing the a21removeKeyFromMemory
have already been included in the patterns.pl
file (check them out to better understand the variants added for this pattern). The specification of the agent response featureInquiry
used in several of these variants, however, is still missing It is up to you to add these in the responses.pl
file. The idea is to define four different types of these responses. Each of these feature inquiry responses should be different based on how many recipes there are still left after applying all the filters, and will require you to define the conditions for when a response is available:
First Rule for Large Number of Recipes
We want to prompt the user for more specific preferences if there are many recipes left. This version of the response should be triggered when the length of the list of recipes is still large (say greater than 800):
Start with the
text/2
predicate, where the first argument isfeatureInquiry
.For the second argument you can use a response text such as "What kind of recipe would you like?".
Use the
recipesFiltered/1
predicate to get the list of recipes, thelength/2
predicate to determine the number of recipes, and add a condition that the length must be greater than 800.
Second Rule for a Moderate Number of Recipes
If there's a moderate number of recipes left (more than 15 but less than or equal to 800), we ask the user to add more preferences unless the memory key-value pair to show recipes has been set (see above):
Use a response text similar to e.g. "What other preference would you like to add?".
Add a condition to check that more than 15 but less than 800 recipes are left.
Also include a condition to check that the memory does not have the key-value pair
'show', 'true'
.
Third Rule for No Recipes
If there are no recipes left after filtering, we want to inform the user to remove some feature requests.
Use a response text similar to "There are no recipes, please remove more requirements.".
Use the
recipesFiltered/1
predicate again to check that no recipes are left.
Fourth Rule for a Small Number of Recipes or a Show Command
This rule handles two scenarios: either there's a small number of recipes, or the user has explicitly asked to show the recipes even when the number is greater than 15.
Use a response text similar to "Here are some recipes that fit your requirements.".
Use the
recipesFiltered/1
predicate to get the filtered list, and check that the length is less than 16 but more than 0, or (use a semicolon;
which represents a logical OR) check that the memory key-value pair ‘show', 'true'
is stored in the agent’s conversational memory.Note the terms used here can be used to condition the recipe overview pages in your javascript and html.
This completes the implementation of all the different cases for the agent’s response. The patterns for removing filters should now work!
Visuals
What you do visually for this capability is up to you. Think about the fact that users could end up going from Recipe Overview 2 page to Recipe Overview 1.
Test it Out
Now Run your Conversational Agent again and try to remove some of the recipe constraints after you added them.
All done?
Proceed with Excluding Features .