microsoft / botbuilder-js

Welcome to the Bot Framework SDK for JavaScript repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using JavaScript.
https://github.com/Microsoft/botframework
MIT License
679 stars 276 forks source link

Can you elaborate the statement - "Adaptive dialog is not intended to be used directly in an SDK-first bot" #3718

Closed bhushanvadgave closed 3 years ago

bhushanvadgave commented 3 years ago

Context

We have been using Component Dialog + Waterfall dialogs to build the bots with NodeJS SDK for the last 4 years. We have built complex bots with a lot of flows.

We are working on the changing the process of building bot flows by moving from Waterfall Dialogs to Adaptive Dialogs with NodeJS SDK. We started exploring Adaptive Dialogs and other modules like botbuilder-dialogs-declarative , adaptive expressions, etc. to use them in development of bots. Since adaptive dialogs in NodeJS SDK is in preview phase we are exploring the sample from https://github.com/microsoft/BotBuilder-Samples/tree/main/experimental/adaptive-dialog

However, in documentation pages we found this statement Adaptive dialog is not intended to be used directly in an SDK-first bot mentioned. On the same we found that SDK-first bot refers to bots created without Composer.

Question

Could any one please elaborate this statement? Does it mean bot developers should not use adaptive dialogs to develop bots if they are not in favour of using Composer? And if yes, please justify.

johnataylor commented 3 years ago

Adaptive Dialogs are derived from Dialogs and they interoperate. Adaptive Dialogs can invoke any Dialog including one that was written in code, for example, written using the Waterfall and Prompt classes. Technically there is also nothing stopping a Dialog written in code from calling an Adaptive Dialog class either, it is just that sometimes the Adaptive Dialog class will have other dependencies (accessed through the TurnContext.TurnState) and so that involves more runtime initialization that has to have been gotten right which makes the exercise somewhat less appealing.

We say Adaptive Dialogs are intended for use with Composer because the execution is flow designed such that it can be specified with data, specifically JSON. The JSON and the class structure are isomorphic. De-serializing this JSON into the class structure is the first step of the execution. And, as you might have discovered, the classes themselves are public and you can therefore, technically, construct this de-serialized structure in raw code. However, there is, no advantage in doing that over writing the JSON because it is exactly the same data structure and at this stage it is just a data structure. Further to this, expressions buried in this data structure are not native language expressions they are Adaptive Expressions. To your native language, and therefore your native language tooling, the expressions appear as strings. Composer is a tool for constructing this JSON and the embedded expressions correctly.

There is little or nothing to be gained from constructing this data structure and its embedded expressions in native code. The experience has been that it is significantly more challenging to debug. You cannot, for example, put meaningful breakpoints. Because your code executes it would be building the data structure that is later used in the runtime execution, you are not putting a breakpoint on the runtime execution itself. At least when debugging Waterfall logic you can hit a breakpoint in your step function.

You can technically invoke Adaptive Expressions from your native code. Though it is hard to see the point in choosing to do that over simply using native expressions. The other component of the Adaptive stack is the Language Generation, there is probably a stronger argument for using this from native code, however, if you were to look into that you'd see that that relies on Adaptive Expressions. At this point we are not promoting this approach. These technologies are best leveraged through Composer.

If you are interested in Adaptive Dialogs then we would strongly encourage you to take a look at Composer. Executing any coded Waterfall style Dialogs you have from Adaptive Dialogs is easily done with BeginDialog. Existing investments in reusable Dialogs can absolutely be used from new Composer developments. Another alternative, if you are interested in hybrid approaches is to invoke Skills. This latter approach having the advantage that the Skill and the main bot can even be written in different languages.

I hope that makes sense, and I'm sorry the documentation was not clearer.

bhushanvadgave commented 3 years ago

@johnataylor Thank you for the detailed information. It clarified my doubts.

We are working on building a Flow(Bot) Builder app (similar to Composer but with more abstracted functionalities) which will help us build bots through the user interface. Hence we are considering using the adaptive dialog stack. The only challenge we are facing is adaptive dialog in NodeJS is not released for public use. Also, there are limited documentation/samples available for adaptive dialogs with NodeJS SDK. Can you help us know by when this will be stable and released for use?

johnataylor commented 3 years ago

@bhushanvadgave We are currently targeting the Fall of this year for the stable release in JavaScript. The exact release date is not set.

There are a couple of things you might be interested in. If you are writing tooling that generates the JSON, the intention is that the JSON for every implementation platform is the same. i.e. the JSON you see today for the C# implementation should create the equivalent in JavaScript, Python and Java when those implementations are available.

Also Composer is designed to be styled and customized so that might be a path for you to explorer.

bhushanvadgave commented 3 years ago

Yes, we are checking JSONs generated from different bots to understand more about adaptive dialogs. We'll explore Composer customizations as well. Thanks for the update and information. @johnataylor