3 state problem, and simple examples aren't helping so much.
The problem of simple bot examples. My problem is I have been tasked with creating a bot which can switch between tasks at any point in a conversation.
For example. If John asks the bot, "I would like to submit my timesheet".
Bot: "Sure, would you like to submit last week or this week". John: "Last week, please" Bob: "You worked 40 hrs last week, is this correct".
Now John remembers that he needs to order some new supplies, and now decides to say.
John: "I need to order some new pens".
The Bot is expecting a boolean(ish) reply but receives something not even close. So the expected behaviour is that the bot will be able to switch to a new task without missing a beat.
I refer to this problem as a 3-state problem. States 1) The reply is an expected value. 2) The reply is an unexpected value, but it is understood as a new/different task. 3) The reply is unexpected, and is not understood and is assumed to be an error. The bot framework doesn't seem to handle anything like this, which is fine because I have built simple pattern which does. The V1 of the bot framework worked well with the pattern, but the v3 seems to have hidden a lot of this away which makes it difficult/impossible. Which leads to my questions, where does the dialogstack get stored, and how do replies get the correct callback method to execute.
@mephisto83 are you using C# sdk or node? C# sdk has a concept called [Scorable](https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Dialogs/Scorable.cs#L48) that if your dialogs implement the IScorable interface they will be ranked based on the score they assign to the incoming message and the dialog with the highest score will get the incoming request. I believe you can achieve your goal using this paradigm.
We have an example of simple scorable here: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Tests/Microsoft.Bot.Builder.Tests/ScorablesTests.cs#L279
We don't have a lot of samples because it's sufficiently advanced and there hasn't been enough demand yet for it.
A general overview:
We are building a distributed system of bots which will only be accessible by the user through a single “parent bot”. The plan is that there will be hundreds of “child bots” which will be developed independently by different functional teams in our company. At the same time, these bots will be independently pluggable and upgradeable. Each bot in the system will not have access to the “parent bot” credentials, so direct communication with an end-user is a non-starter, and is not desired.
When we receive a message through the bot connector, the “parent bot” will determine if the message is part of an ongoing conversation. If it is, the message is routed directly to the correct “child bot” through a web api or some other transport. If it is not, the “parent bot” uses LUIS to determine the general intent of the message and which “child bot” can handle it. Once a bot is identified the message is passed. When the message arrives at the “child bot” capable of handling the message, another LUIS endpoint is contacted to get a more exact representation of the intent and as many details of the intent as possible.
For the “parent bot” to be able to keep track of ongoing conversations, every message from the user and response from the “child bots” has to go through the “parent bot”. With hundreds of “child bots” with different LUIS endpoints, the amount of expected traffic is large enough that scaling the number of instances of bots of any type will require Service Fabric or similar for managing each bot node.
Specifically the to the 3-state problem:
We have to be able to break out of an ongoing conversation with one dialog (Timesheet “child bot” in the original post) and switch seamlessly to a different dialog and potentially different “child bot“ (Purchase order “child bot” in the original example) running on a different node etc. When a “child bot”/dialog encounters an unexpected value/message from the user (In the example the Timesheet bot is waiting for a Yes/No response from the user, but receives “I need to order…”) the “parent bot” gets notified and checks if any of the other “child bots” can handle the intent of this message. In the example the Purchase order bot will handle this type of message (State 2 in the original post). If there is no “child bot” that can handle the message, it is assumed to be a typographical error and the Timesheet bot will respond with something like “I didn’t get that. Please try again” (State 3)
The Scorable functionality doesn’t appear to fit this scenario.
The company will want to make as much of our functionality available as possible, which means over the longer term potentially 1000 child bots. Each bot may contain at least 10 dialogs. I have big hopes for the bot framework and great confidence that this will all work for our use case, but I also have reservations that more complex use cases like ours will be forgotten as they are not mainstream.
@mephisto83 can you be explicit about the difference between the V1 and V3 versions of the framework that make this harder for you? I was re-reading your original post and did not understand. Was there something in particular that was hidden away?
The most salient difference is that V1 of the framework allowed a reply message to the user to be sent inline with the http response corresponding to the incoming message to the bot. All additional messages were sent directly with a separate http request from the bot to the connector. In V3, all messages are sent directly with a separate http request from the bot to the connector.
Regarding your scenario, you should be able to define a protocol between your parent and child bots to delegate messages to them. This protocol should have some facility for communicating whether the understood the user's message and wants to continue, understood the user's message and does not want to continue receiving message, or did not understand the user's message and wants to see if the parent can handle the message instead.
I'm going to close this issue, but feel free to open a new issue for further discussions.