Search code examples
c#botframeworkbot-framework-composer

What is the purpose of DialogStack in Microsoft Bot Composer and how to reset it?


I am having an issue with the dialog stack getting too big and I have found ways to clean/reset but using TypeScript and not C#, which is what I need. Reason why I would wish to clear the dialog stack is because I want to avoid having issues with newtonsoft json complaining that the depth is too big (by default it is set to 64 and would like it to stay that way). It requires a lot of dialog hopping, so it would be quite uncommon but common enough to be worth preventing it. I would also like to know if this would mess something up internally with the bot logic.


Solution

  • Every bot, whether a BotFramework bot or someone else's, has some sort of dialog stack. The purpose of it is to record where the bot has come from as it traverses the conversation flow. It allows the bot to back up to a previous conversation point, for interruptions to occur (and, subsequently, return to the conversation point where the interruption occurred), the tracking of state, variables, and much more.

    Your use of the word 'reset' is a bit ambiguous. You can 'reset' the dialog stack by use of the 'Cancel all active dialogs' action. This will remove all child dialogs from the stack and return the user back to the main dialog.

    If you mean to re-instantiate the dialog stack, no, this is not possible out-of-the-box. You may be able to achieve this thru use of a custom runtime or custom action. But, for the reasons stated above, this would not be a recommended best practice.

    If you implement the suggested change below, you can avoid your stated issue, altogether. I'm in close contact with the BotFramework developers and this was their suggested course of action:

    Newtonsoft, v13, introduced the 'max depth' default. The BotFramework dotnet SDK relies on v12 which does not have that property. However, if your solution or project uses v13 anywhere within then that version will override v12 used elsewhere.

    You have two options to get around this:

    1. Downgrade newtonsoft to v12 in your solution/project.
    2. Switch from newtonsoft to System.Text.Json, as described in this MS doc. System.Text.Json also has a default max depth, however it also allows you to pass in a new configuration in order to override the default max depth.