article by Frank Nimphius, May 2019
Sometimes a smart feature can work against you if you don't understand its default settings. For composite bag entities, bag items that use the same entity may not resolve properly. As a result you are not getting prompted for all bag items and the bag items instead share the same value. This easily can turn a 2 week vacation into a day trip 😉 In this article I explain the why, when and how to resolve and avoid the issue.
Introducing the Problem
Composite bag entities are like business domain objects and consist of multiple entities, string variables or attachments. Using composite bag entities you leverage the System.ResolveEntities and the System.CommonResponse component to display prompts to users until all entities and variables in a composite bag entity have a value. No explicit dialog flow steps need to be written for this.
The BotML code in the image above shows the definition of the travelBooking variable to be of type TravelBooking, a custom composite bag entity. The System.ResolveEntities component in the selectDestination dialog flow state renders prompts for all entities contained in the composite bag.
The TravelBooking composite bag entity contains 3 bag items. Two bag items are of an entity type DATE. So when the System.ResolveEntities component resolves the TravelBooking entity, it first asks for the "StartDate" item, then for the "TravelDestination" item and finally for the "EndDate" item. So, lets have a look at the tester.
As you can see in the screenshot above, the System.ResolveEntities component starts asking for a departure date to then ask for the destination. But this is it. It does not ask for the return date and instead simply reuses the start date as the return date. While reuse in general is a good thing in software development, in this case, it is not.
Note: This problem does not show for DATE entities only but in general whenever you have two or more bag items of the same entity type.
Its a cool feature, not a defect causing this behavior
Composite bag entities are smart by default. If a user, when prompted for a a start date types "I like to go to London on August 20 2019" , then the composite bag entity recognizes two information: the destination and the start date. The feature for this is called out of order extraction. Humans seldom answer precise to a question but usually add surrounding words and information. Now, if you said that you want to go to London on August 20 2019, why should the bot ask again.
The out of order extraction feature however does not know for which of the DATE bag items it should extract the provided DATE value. Well, at least not until you tell it. So to fix the problem with the missing return date prompt, you need to disabled or change the out of order extraction setting as shown in the images below.
Go to the bag item that does not resolve. In this example, the bag item is EndDate. Press the pencil icon to edit it
Scroll down to the Extraction Rules settings. Notice that Out of Order Extraction is enabled for the EndDate bag item
Either disable the Out of Order Extraction for this bag item or set the Extract With property to a bag item that is not of a DATE* entity. Then close the editor.
* As mentioned, this not only happens for DATE entities but for any entity that you have multiple bag items of. The composite bag entity would extract the user provided value for all items of a same entity type.
IMPORTANT:
Do the same for the StartDate because otherwise the StartDate bag item would pick up the date provided for the EndDate. Basically this means that you need to change all bag items that use the same entity type (DATE in my example). You don't need to give up on the "Out of Order Extraction" feature, but just set the "Extract with" select choice to another bag item to reduce the scope of the value extraction.
Rerunning the Sample
In the above example, I disabled the Out of Order Extraction feature for simplicity reason. So lets run the sample again using the embedded conversation tester
Related Content
TechExchange: How-to Use the System.ResolveEntities Component in Oracle Digital Assistant
TechExchange – Building Smart Value Lists from Entities