1
votes

When I was reviewing someone else's code base for a bot framework v4 project, I noticed a lot of state data stored in private members of that particular dialog instance instead of storing it within it's own StateProperty. For instance the developer tried to store data between WaterfallSteps in private members and wanted to consume it in a subsequent step within a new turn (instead of pushing the result with stepContext.Next(result)).

Different to v3 (as soon as I remember), in v4 the dialog itself is not serialized and therefore those private members are "reset" in a new turn.

I saw this "try" with many of my co-workers when they started with bot framework v4 as it feels natural to them.

Thus my question is more out of curiosity and as follows:

As documented here, the bot initializes the dialog subsystem by calling create context on the dialog set, which returns a dialog context. That dialog context contains the necessary information needed by the dialog.

As the DialogSet is initialized with ConversationState, I asked my self what exactly is meant by "the necessary informations". Which informations of the particular dialog instance are actually restored?

Are there any or is it really just the context around a dialog (like waterfall step index) that is restored?

Depending on the response to this question, one could ask why design was chosen to store it with dedicated state properties instead of serializing the dialog instance with its members set, which seems a more natural way for most people I looked over their shoulders.

Why was the behaviour changed between v3 and v4 and what are the top reasons for this?

1

1 Answers

0
votes

In both Bot Builder V4 and V3, the DialogStack is stored in state. You are correct that V3 serialized and deserialized dialog fields. However, this 'magic' was often times problematic. The V3 binary serialization method would only allow the sdk to target netframework, and the entire dialog stack was more fragile. The V4 dialog stack was re-architected, and feedback from V3 was incorporated. State is now less automatic, and more 'in the hands of the developer'.

Here is an example of ConversationState containing a DialogStack:

"document": {
        "$type": "System.Collections.Concurrent.ConcurrentDictionary`2[[System.String, System.Private.CoreLib],[System.Object, System.Private.CoreLib]], System.Collections.Concurrent",
        "DialogState": {
            "$type": "Microsoft.Bot.Builder.Dialogs.DialogState, Microsoft.Bot.Builder.Dialogs",
            "DialogStack": {
                "$type": "System.Collections.Generic.List`1[[Microsoft.Bot.Builder.Dialogs.DialogInstance, Microsoft.Bot.Builder.Dialogs]], System.Private.CoreLib",
                "$values": [
                    {
                        "$type": "Microsoft.Bot.Builder.Dialogs.DialogInstance, Microsoft.Bot.Builder.Dialogs",
                        "Id": "GreetingDialog",
                        "State": {
                            "$type": "System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.Object, System.Private.CoreLib]], System.Private.CoreLib",
                            "dialogs": {
                                "$type": "Microsoft.Bot.Builder.Dialogs.DialogState, Microsoft.Bot.Builder.Dialogs",
                                "DialogStack": {
                                    "$type": "System.Collections.Generic.List`1[[Microsoft.Bot.Builder.Dialogs.DialogInstance, Microsoft.Bot.Builder.Dialogs]], System.Private.CoreLib",
                                    "$values": [
                                        {
                                            "$type": "Microsoft.Bot.Builder.Dialogs.DialogInstance, Microsoft.Bot.Builder.Dialogs",
                                            "Id": "namePrompt",
                                            "State": {
                                                "$type": "System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.Object, System.Private.CoreLib]], System.Private.CoreLib",
                                                "options": {
                                                    "$type": "Microsoft.Bot.Builder.Dialogs.PromptOptions, Microsoft.Bot.Builder.Dialogs",
                                                    "Prompt": {
                                                        "$type": "Microsoft.Bot.Schema.Activity, Microsoft.Bot.Schema",
                                                        "type": "message",
                                                        "id": "3Md4r2ECwdEJnnPshesDe1-g|0000009",
                                                        "timestamp": null,
                                                        "localTimestamp": null,
                                                        "localTimezone": null,
                                                        "serviceUrl": "https://webchat.botframework.com/",
                                                        "channelId": "webchat",
                                                        "from": {
                                                            "$type": "Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema",
                                                            "id": "BotHealthTest@6hiZPWXn5jc",
                                                            "name": "BotHealthTest",
                                                            "aadObjectId": null,
                                                            "role": null
                                                        },
                                                        "conversation": {
                                                            "$type": "Microsoft.Bot.Schema.ConversationAccount, Microsoft.Bot.Schema",
                                                            "isGroup": null,
                                                            "conversationType": null,
                                                            "id": "3Md4r2ECwdEJnnPshesDe1-g",
                                                            "name": null,
                                                            "aadObjectId": null,
                                                            "role": null,
                                                            "tenantId": null
                                                        },
                                                        "recipient": {
                                                            "$type": "Microsoft.Bot.Schema.ChannelAccount, Microsoft.Bot.Schema",
                                                            "id": "EGnHowki8Se",
                                                            "name": "You",
                                                            "aadObjectId": null,
                                                            "role": null
                                                        },
                                                        "textFormat": null,
                                                        "attachmentLayout": null,
                                                        "membersAdded": null,
                                                        "membersRemoved": null,
                                                        "reactionsAdded": null,
                                                        "reactionsRemoved": null,
                                                        "topicName": null,
                                                        "historyDisclosed": null,
                                                        "locale": null,
                                                        "text": "What is your name?",
                                                        "speak": null,
                                                        "inputHint": "expectingInput",
                                                        "summary": null,
                                                        "suggestedActions": null,
                                                        "attachments": null,
                                                        "entities": null,
                                                        "channelData": null,
                                                        "action": null,
                                                        "replyToId": "3Md4r2ECwdEJnnPshesDe1-g|0000007",
                                                        "label": null,
                                                        "valueType": null,
                                                        "value": null,
                                                        "name": null,
                                                        "relatesTo": null,
                                                        "code": null,
                                                        "expiration": null,
                                                        "importance": null,
                                                        "deliveryMode": null,
                                                        "listenFor": null,
                                                        "textHighlights": null,
                                                        "semanticAction": null
                                                    },
                                                    "RetryPrompt": null,
                                                    "Choices": null,
                                                    "Validations": null
                                                },
                                                "state": {
                                                    "$type": "System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.Object, System.Private.CoreLib]], System.Private.CoreLib"
                                                }
                                            }
                                        },
                                        {
                                            "$type": "Microsoft.Bot.Builder.Dialogs.DialogInstance, Microsoft.Bot.Builder.Dialogs",
                                            "Id": "profileDialog",
                                            "State": {
                                                "$type": "System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.Object, System.Private.CoreLib]], System.Private.CoreLib",
                                                "options": null,
                                                "values": {
                                                    "$type": "System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.Object, System.Private.CoreLib]], System.Private.CoreLib"
                                                },
                                                "instanceId": "9b48b35f-3fa5-431d-bb4d-9a512491aca4",
                                                "stepIndex": 1
                                            }
                                        }
                                    ]
                                }
                            }
                        }
                    }
                ]
            }
        }
    }

That said, Bot Builder Adaptive Dialog follows a model more closely resembling the V3 implementation. Preview bits can be found in this branch: 4.Future Please check it out, and provide feedback on the Github repository.