Your MARBEL Agent
Here is an overview of how to implement your MARBEL agent step by step.
- 1 1. Getting Started with your MARBEL Agent
- 2 2. Greet, and Self-Identify
- 3 3. Request a Random Recipe Recommendation
- 4 4. Select Recipes by Name
- 5 5. Filter Recipes by Inclusion
- 6 6. Connecting Your Entire Pipeline
- 7 7. Unexpected Intents
- 8 8. Confirm the Chosen Recipe
- 9 9. Removing Filters and Showing Recipes on Demand
A lot of string matching was done in this project. Thus you need to make sure that across Dialogflow, your intent + slot classifier, and this dialogue manager that all naming is identical. Due to a combination of factors, it could be that our naming does not match up (we have multiple versions etc.) so please check for yourself all naming!
1. Getting Started with your MARBEL Agent
Summary Description
The first step is to get your conversational agent up and running. There is one ingredient that is still missing, but required before you can run the code provided to you. You need to create your own Dialogflow agent that you will use throughout the project and connect it to the MARBEL agent that manages the dialog (or conversation) between a user and your agent. When you have created this agent, you will be able to run your agent. Next, you will also be asked to put something in the agenda of the MARBEL agent to get things going. And, last but not least, you need to add code for creating an initial start screen (a simple webpage). When you have done this too, you can run your conversational agent and should see the start webpage that you created. Your agent won’t do any talking yet, though. It is just a first step.
Implementation Tasks Overview
Set Up Dialogflow Agent
Create a Dialogflow agent with default settings (English as the language).
Share it with team members by assigning the Developer role.
Import the provided zip file for basic setup.
Integrate Dialogflow with MARBEL
Download the JSON key file for Dialogflow and add it to the
agent
folder in your repository.
Initialize MARBEL Agenda
Replace the empty agenda in the
dialog_init.mod2g
file with the start pattern (agenda([start])
).
See the Start Page
Run and Debug the Agent
Test the integration by running the MARBEL agent and verifying state changes in Eclipse’s Debug perspective.
Instructions
Getting Started with your MARBEL Agent
2. Greet, and Self-Identify
Summary Description
Natural conversations are typically opened. Our agent should not just straight away embark on the task of recommending a recipe. It should first secure the attention of its user. Opening a conversation is a basic conversational competence. A common way of opening a conversation is by greeting each other. You should provide your agent with this basic conversational competence too. It should, moreover, be able to introduce itself to its user as in the following conversational pattern. A welcoming webpage should also be created.
A: Hello.
A: My name is ____*.
U: Hi!
*insert your agent’s name here
Implementation Tasks Overview
Tasks Focused on Dialogue Patterns
Implement Basic Greeting Pattern
Define the
c10
pattern inpatterns.pl
for the greeting exchange:[agent, greeting]
and[user, greeting]
.Add the condition
agentName('')
to ensure it is used only when the agent has no name.
Add Self-Identification Pattern
Extend
c10
inpatterns.pl
to include[agent, selfIdentification]
.Add
not(agentName(''))
to ensure it is used only when the agent has a name.
Specify Agent Responses
Add phrases for
greeting
andselfIdentification
intents inresponses.pl
.Dynamically retrieve the agent’s name using
agentName(Name)
to generate self-identification responses.
Add Patterns to the Agenda
Update
dialog_init.mod2g
to includec10
in the agenda afterstart
.
Tasks Focused on Visual Support
Create a Welcoming Page.
Tasks Focused on Debugging and Testing
Test Greeting Patterns
Test the basic greeting pattern by running the agent and initiating interaction from the Start page.
Set the agent’s name in
dialog_init.mod2g
and verify self-identification functionality.
Test User Response Variations
Provide non-greeting inputs to test the agent’s response and inspect session updates in Debug mode.
Instructions
3. Request a Random Recipe Recommendation
Summary Description
The second capability will enable the agent to recommend a recipe when a user does not care (to refine) what kind of recipe they are looking for (see the example conversational pattern below). A new pattern will be introduced to this purpose for selecting a recipe, and a new intent should be added to your Dialogflow agent to enable understanding user requests for recommending “just some recipe”. Quite some work will need to be done for introducing the first code needed for retrieving recipes from the recipe database. The first versions of two new pages will also need to be created. One page for making clear to the user that they should inform the agent about features of recipes that help refine the selection of recipes and clarify what the user is looking for. Another page for asking a user to (dis)confirm that the recipe that the agent has selected and recommends to the user is what the user is looking for.
A: What recipe would you like to cook?
U: Please, just recommend me something.
A: What about ___*?
insert a recipe name here (from the agent’s database)
Implementation Tasks Overview
Tasks Focused on Dialogue Patterns
Implement Recipe Selection Pattern
Define the
a50recipeSelect
pattern inpatterns.pl
with these moves:[agent, specifyGoal]
: Agent asks the user what recipe they want.[user, requestRecommendation]
: User requests a random recipe.[agent, recommend]
: Agent suggests a recipe.
Add
[agent, insert(a50recipeConfirm)]
to direct the agent to the recipe confirmation pattern.
Implement Recipe Confirmation Pattern
Define the
a50recipeConfirm
pattern inpatterns.pl
to allow users to confirm or disconfirm a recipe.
Specify Agent Responses
Add responses in
responses.pl
:text(specifyGoal, "...")
: Agent asks about recipe preferences.text(recommend, "...")
: Agent suggests a random recipe.
Tasks Focused on Recipe Filtering
Add Recipes to the Database
Each team member adds one favorite recipe to
recipe_database.pl
, ensuring unique recipe IDs and consistent ingredient names.
Implement Recipe Selection Logic
Add rules in
recipe_selection.pl
:currentRecipe(RecipeID)
: Retrieves the selected recipe from memory.recipeIDs(RecipeIDs)
: Collects all recipe IDs from the database.recipesFiltered(RecipeIDs)
: Filters recipes based on user preferences or constraints.
Update Conversational Memory
Add a rule in
dialog_update.mod2g
to update the memory with the randomly selected recipe when a user requests a recommendation.
Tasks Focused on Visual Support
Design Recipe Overview 1 Page
Design Recipe Confirmation Page
Tasks Focused on Debugging and Testing
Test Recipe Recommendation
Add
a50recipeSelect
to the agenda indialog_init.mod2g
and verify the agent's ability to:Ask for recipe preferences.
Respond with a random recipe recommendation.
Test Recipe Confirmation
Ensure the agent correctly displays the recommended recipe and allows user confirmation.
Instructions
4. Select Recipes by Name
Summary Description
Instead of leaving it up to the agent to suggest a recipe and choose one out of all remaining recipes, a user also can mention a specific recipe themselves and ask the agent to present that. This means that the Dialogflow agent should have knowledge of all of the recipes that are in the database too. We will make this available to that agent by adding a recipe entity (type). That will also enable the agent to recognize these recipes in user expressions.
Implementation Tasks Overview
Tasks Focused on Dialogue Patterns
Add a New Recipe Request Pattern
Define a variant of the
a50recipeSelect
pattern inpatterns.pl
with these moves:[agent, specifyGoal]
: Agent asks what recipe the user wants to cook.[user, recipeRequest]
: User requests a specific recipe by name.[agent, recipeChoiceReceipt]
: Agent acknowledges the selected recipe.[agent, insert(a50recipeConfirm)]
: Move to the confirmation phase.
Specify the Agent’s Recipe Acknowledgment Response
In
responses.pl
, define a rule fortext(recipeChoiceReceipt, Txt)
to construct the response dynamically.Retrieve the recipe name from memory using
currentRecipe/1
and construct the acknowledgment (e.g., "Artichoke and pine nut pasta is a great choice!") usingstring_concat/3
.
Tasks Focused on Visual Support
Update Visuals for Recipe Request
Tasks Focused on Debugging and Testing
Test Recipe Request Handling
Add the new pattern to the agent’s agenda in
dialog_init.mod2g
after thec10
pattern.Test the interaction flow:
Agent asks for a recipe.
User requests a specific recipe.
Agent acknowledges the recipe choice and moves to the confirmation phase.
Verify Intent Recognition
Check the Dialogflow Training Tool to confirm the
recipeRequest
intent is recognized.Verify the SIC server logs show the correct intent and transcript.
Handle ASR Failures
Use the chatbox feature to avoid ASR failures and ensure the agent can handle specific recipe requests reliably.
Instructions
5. Filter Recipes by Inclusion
Summary Description
Implementation Tasks Overview
Tasks Focused on Filtering Logic
Refine the Recipe Filtering Logic
Expand the
recipesFiltered/3
predicate to handle lists of filters.Implement recursive filtering by applying each filter to the recipe list sequentially:
Apply the first filter and pass the remaining recipes to the next recursive call.
Continue until all filters have been applied.
Define Ingredient-Based Filtering
Add rules for the
hasIngredient/2
predicate:Check if a recipe contains a specific ingredient (e.g., "ginger").
Check if a recipe uses an ingredient type (e.g., "meat") by associating it with specific examples (e.g., "chicken").
Use the
typeIngredient/2
predicate for hierarchical ingredient filtering.
Add Filtering by Cuisine and Meal Type
Extend the
applyFilter/4
predicate to include filtering by:Cuisine: Ensure recipes match a specified cuisine type (e.g., "Italian").
Meal Type: Filter recipes based on meal categories (e.g., "dessert").
Support Dietary Restrictions
Add logic for filtering recipes by dietary restrictions:
Implement the
diet/2
predicate to check if a recipe satisfies restrictions like vegetarian, vegan, gluten-free, or spicy.Use the
ingredientsMeetDiet/2
helper predicate to validate dietary restrictions for all ingredients in a recipe.
Tasks Focused on Dialogue Patterns
Enable Recipe Feature Requests
Add a new
a21featureRequest
pattern for user requests to refine filters dynamically.Design two variants of the pattern:
Recipe Selection Context: The user requests a feature during the recipe selection phase (
a50recipeSelect
).Recipe Confirmation Context: The user requests a feature while reviewing a specific recipe (
a50recipeConfirm
).
Handle Conflicting Feature Requests
Use the
removeConflicts(Params)
action to handle conflicts when a new feature request overrides an existing one.Ensure the agent acknowledges conflicts and updates filters accordingly.
Agent Responses
Implement agent intents and responses:
ackFilter
: Acknowledge successful application of filters.noRecipesLeft
: Inform the user when no recipes match their filters.featureRemovalRequest
: Prompt the user to remove conflicting filters.
Tasks Focused on Visual Support
Extend Recipe Overview Pages
Recipe Overview 1 Page:
Show user-requested filters when more than 15 recipes remain.
Display only a summary of filters to avoid overwhelming the user.
Recipe Overview 2 Page:
Display recipe titles and images when the filtered list has 15 or fewer recipes.
Use visually appealing cards to present recipe details.
Extend the Recipe Confirmation Page
Add detailed recipe information, including:
Cooking instructions.
Ingredient list with quantities.
Estimated preparation/cooking time.
Number of servings.
Optionally, include a summary of user-applied filters for context.
Tasks Focused on Debugging and Testing
Test Filtering Functionality
Test the new filtering logic with various scenarios:
Combine filters for ingredients, cuisine, and dietary restrictions.
Verify that recipes are correctly filtered and conflicts are resolved.
Validate Feature Requests
Confirm that the agent correctly handles feature requests in both
a50recipeSelect
anda50recipeConfirm
contexts.Check the agent’s responses and ensure they align with the updated logic.
Ensure Robust Filtering
Test edge cases:
Apply filters that leave no recipes (e.g., contradictory filters).
Apply multiple filters that narrow down to fewer than 16 recipes.
Instructions
6. Connecting Your Entire Pipeline
Connect MARBEL with Intent/Slot Classifier and WHISPER remove Dialogflow.
Instructions
Connecting Your Entire Pipeline
7. Unexpected Intents
Summary Description
A conversational agent should be able to handle dialog moves of users that do not necessarily fit into the currently active pattern. Such moves are “unexpected” in the sense that they do not fit into a conversational pattern, but should be expected as users will almost always slightly deviate from a rigidly framed pattern. Typical examples are expressions of appreciation and requests for information about how the agent can assist a user (a capability check). A second type of unexpected move is not due to user behavior but due to failures of speech recognition. Dialogflow will match with a so-called default fallback intent in cases where it is unable to recognize what a user says and cannot classify it as one of the (other) intents of the agent. There is another case that we will look into too where what a user says does not seem to fit into the conversational context. Again, we can capture the “unexpected” in patterns, which will enable the conversational agent to handle them:
Implementation Tasks Overview
Tasks Focused on Repair Patterns
1. Responding to Fallbacks
Scenario: When the agent cannot recognize a user’s intent (i.e., Dialogflow matches the fallback intent).
Example:
User: "Have you read The Hobbit?"
Agent: "What do you mean?"
Steps:
Add a
b12
pattern inpatterns.pl
to handle fallback intents.Define a paraphrase request (
paraphraseRequest
) as the agent’s response.Add text responses in
responses.pl
for theparaphraseRequest
intent.
2. Responding to Out-of-Context Intents
Scenario: When the agent recognizes a user’s intent but finds it irrelevant to the current conversational context.
Example:
Agent: "What recipe would you like to cook?"
User: "Hey there."
Agent: "I am not sure what that means in this context."
Steps:
Add a
b13
pattern inpatterns.pl
:First move: Any user intent.
Second move: Agent’s
contextMismatch(Intent)
response, using the intent as a parameter.
Regulate this pattern in the
updateSession.mod2g
file as the last fallback option for recognized intents.Add responses for
contextMismatch(Intent)
inresponses.pl
:Use
text/3
to customize responses based on the conversational context.Include an acknowledgment of the mismatch and provide guidance on expected user behavior.
Tasks Focused on Enhancing User Interaction
1. Handling User Appreciation
Scenario: When the user expresses gratitude.
Example:
User: "Thanks."
Agent: "You're welcome."
Steps:
Add a
b42
appreciation pattern inpatterns.pl
.Define
appreciation
(user intent) andappreciationReceipt
(agent response) intent labels.Add responses for
appreciationReceipt
inresponses.pl
.
2. Handling Capability Checks
Scenario: When the user asks what the agent can do.
Example:
User: "What can you do?"
Agent: "I can help you find recipes, filter them by preferences, and guide you through the cooking process."
Steps:
Add a
c30
capability check pattern inpatterns.pl
:Intent labels:
checkCapability
(user intent) anddescribeCapability
(agent response).
Define responses for
describeCapability
inresponses.pl
:Provide a concise, context-aware summary of the agent’s capabilities.
Use
text/3
to tailor responses based on the ongoing conversational context.
Tasks Focused on Visual Support
Update Visuals
Enhance the visuals to support the repair patterns:
Fallbacks: Display a friendly prompt asking the user to rephrase their input.
Out-of-Context Intents: Provide subtle visual feedback indicating the agent’s confusion and suggest appropriate actions.
Capability Checks: Add a visually appealing list of capabilities or icons to accompany the agent’s verbal response.
Tasks Focused on Debugging and Testing
Test Repair Patterns
Fallbacks:
Test the agent’s ability to respond with a paraphrase request when encountering unrecognized intents.
Example: Say random phrases like “the sky is blue” and verify the agent responds appropriately.
Out-of-Context Intents:
Test responses to user intents that do not align with the current context.
Example: Interrupt the recipe selection process with a greeting and ensure the agent provides context-aware feedback.
Capability Checks:
Test responses to general and context-specific capability inquiries.
Example: Ask "What can you do?" at different stages of the conversation.
Instructions
8. Confirm the Chosen Recipe
Summary Description
When users have finished their search for a nice recipe to cook, their choice should be displayed (which we already implemented for Filtering by Inclusion ) and they should be asked to check the details to confirm the recipe is indeed what they would like to cook. Of course, we need to take at least two scenarios into account: (1) a user confirms they are happy with the recipe, or (2) they indicate it is after all not quite what they were looking for. If all is fine and well, the agent should close the conversation by saying farewell. Otherwise, the conversation should move back to the recipe selection stage. The following conversational pattern needs to be implemented:
Implementation Tasks Overview
Tasks Focused on Confirming Recipe Choice
1. Implementing Recipe Confirmation Patterns
Scenario: After showing a recipe, the agent asks the user to confirm their choice.
Example:
Agent: "Can you confirm that Chicken Alfredo is the recipe you would like to cook?"
User: "Yes." (Alternatively: "No.")
Agent: "Great!" (Alternatively: "That is unfortunate. Let's pick another recipe.")
Steps:
Add three variants of the
a50recipeConfirm
pattern inpatterns.pl
:User Confirms: User says "yes" or expresses appreciation. The conversation moves to the farewell phase.
User Disconfirms: User says "no." The agent returns to the recipe selection phase (
a50recipeSelect
).Fallback Handling: Handle unrecognized or ambiguous responses gracefully (optional).
Handle appreciation as a confirmation:
In the
a50recipeConfirm
pattern, treat appreciation as equivalent to confirmation when it occurs in this context.
Add logic for what happens after confirmation:
User Confirms: Transition to the
c43
farewell pattern.User Disconfirms: Transition back to the
a50recipeSelect
pattern to allow the user to choose another recipe.
2. Agent Responses for Recipe Confirmation
Add responses for the
recipeCheck
intent inresponses.pl
:For Confirmation:
Example: "Great! I’m happy you like this recipe."
For Disconfirmation:
Example: "That’s unfortunate. Let’s pick another recipe."
Dynamically insert the recipe name into the confirmation question:
Example: "Can you confirm that Chicken Alfredo is the recipe you would like to cook?"
Tasks Focused on Saying Farewell
1. Implementing Farewell Patterns
Scenario: The agent bids farewell to conclude the conversation.
Example:
Agent: "Goodbye!"
User: "Bye."
Agent: "Feel free to start again if you’d like to find more recipes."
Steps:
Add a
c43
pattern inpatterns.pl
to model the farewell sequence:Agent Goodbye: The agent says goodbye.
User Goodbye: The user responds with a farewell.
Add a final topic check:
Before ending the conversation, the agent asks if the user wants to find another recipe.
Example:
Agent: "Is there anything else you’d like to do? Would you like to find another recipe?"
If the user confirms: Add
[agent, restart]
to the pattern to restart the conversation.
2. Agent Responses for Saying Farewell
Add responses for the
farewell
intent inresponses.pl
:Examples:
"Goodbye! Have a great day."
"Thanks for chatting! See you next time."
Add responses for the topic check if the user wants to restart:
Example: "Okay, let’s start fresh! What recipe are you looking for?"
Tasks Focused on Visual Support
1. Create a Farewell Page
Purpose: Match the top-level intent
c43
to provide a closing webpage that thanks the user and invites them to return.Content:
A warm farewell message:
Example: "Thank you for using Recipe Assistant! We hope you found something delicious."
An encouragement to return:
Example: "Feel free to start again to explore more recipes."
Design:
Simple, clean layout with visually appealing graphics (e.g., a smiling chef or a plate of food).
Prominently display a "Start Over" button (if applicable).
Tasks Focused on Debugging and Testing
1. Test Recipe Confirmation Flow
Add
a50recipeConfirm
topatterns.pl
but do not add it to the agent’s agenda:This pattern is inserted dynamically after a recipe is selected, so no need to include it in the agenda manually.
Verify:
The agent transitions to the confirmation phase after a recipe is selected.
The agent handles "yes," "no," and appreciation responses correctly.
The conversation flows back to recipe selection after disconfirmation.
2. Test Farewell Flow
Add
c43
to the agent’s agenda indialog_init.mod2g
.Verify:
The agent says goodbye and asks if the user wants to restart.
If the user confirms restarting, the conversation resets to the initial agenda.
If the user declines, the conversation ends gracefully.
Instructions
9. Removing Filters and Showing Recipes on Demand
Summary Description
The last capability on our list, before we ask you to extend the capabilities of the conversational agent using your own insights and ideas, is about allowing users to remove requests they made before and to allow them to indicate that they are done providing their preferences. You should implement the following patterns:
Implementation Tasks Overview
Tasks Focused on Allowing Users to Finalize Recipe Constraints
1. User Stops Adding Preferences
Scenario: The user indicates they do not want to add more constraints.
Example:
Agent: "Can you elaborate on what you're aiming for in your recipe?"
User: "I don't want to add anything else."
Agent:
If ≤100 recipes remain: "OK. Here is a list of recipes that you can choose from."
If >100 recipes remain: "Sorry, there are still too many recipes left to show them all. Please add more preferences."
Steps:
Implement the
a21noMoreFilters
Pattern:Two Variants:
pictureGranted
: Triggered when ≤100 recipes remain.pictureNotGranted
: Triggered when >100 recipes remain.
Agent Memory Update:
If the agent grants the user’s request, add
[agent, update(['show'='true'])]
to the pattern to update the agent’s memory.Modify the condition for showing the second recipe overview page (
html.pl
) to check for the memory key-value pair'show', 'true'
.
2. Agent Responses for Finalizing Preferences
Add responses for the
pictureGranted
andpictureNotGranted
intents inresponses.pl
:pictureGranted
:Example: "Here is a list of recipes that you can choose from."
pictureNotGranted
:Example: "Sorry, there are still too many recipes left to show them all. Please add more preferences."
Dynamically calculate the number of remaining recipes using the
recipesFiltered/1
predicate to determine which response to use.
Tasks Focused on Removing Filters
1. Completing Filter Removal Responses
Scenario: The user requests to remove filters, and the agent provides feedback based on the number of remaining recipes.
Four Cases:
Large Number of Recipes (>800):
Example: "What kind of recipe would you like?"
Moderate Number of Recipes (16–800):
Example: "What other preference would you like to add?"
Condition: Memory key-value pair
'show', 'true'
must not be set.
No Recipes Left (0):
Example: "There are no recipes, please remove more requirements."
Small Number of Recipes or Show Command (<16 or
show=true
):Example: "Here are some recipes that fit your requirements."
Steps:
Add rules for the
featureInquiry
intent inresponses.pl
:Use
recipesFiltered/1
to calculate the number of remaining recipes.Use
length/2
to count the recipes and apply appropriate conditions.
Handle the
show=true
memory key condition for small or moderate recipe sets.
2. Debugging the a21removeKeyFromMemory
Patterns
Check the existing patterns in
patterns.pl
for removing filters (a21removeKeyFromMemory
).Verify that all filter removal scenarios trigger the correct
featureInquiry
response.
Tasks Focused on Visual Support
Update Visuals for Recipe Overviews
Recipe Overview 2 to Recipe Overview 1:
When users remove filters or finalize preferences, ensure a seamless transition between pages:
Example: From showing recipe titles and images (Overview 2) to just a list of filters (Overview 1).
Use dynamic visual cues to inform users of what has changed (e.g., "Filter removed!").
Dynamic Recipe Display
Modify the second recipe overview page to account for the memory key-value pair
'show', 'true'
:Show recipes even if there are more than 15 left, provided the user requested to stop adding filters.
Tasks Focused on Debugging and Testing
1. Test Finalizing Preferences
Verify the agent correctly handles cases where the user stops adding filters:
Test with ≤100 and >100 recipes left to ensure the
pictureGranted
andpictureNotGranted
responses trigger appropriately.Confirm the memory update (
show=true
) triggers the correct recipe overview page.
2. Test Filter Removal
Test removing filters at different recipe counts:
Large Numbers: Prompt the user to add more specific preferences.
Moderate Numbers: Suggest adding more preferences unless
show=true
.No Recipes: Ask the user to remove filters.
Small Numbers or Show Command: Display the remaining recipes.
3. Test Visual Transitions
Ensure smooth transitions between Recipe Overview 1 and Recipe Overview 2:
Test with dynamic changes in recipe counts and user actions (e.g., removing filters or finalizing preferences).