Introducing Bot Framework Component Model for better sharing and extensibility
Tags: azure, botframework, chatbots, opensource
Published: 2021-06-08 07:53:48

Hey there! 👋 I am back with the bot post again.

The Conversational AI has witnessed a tremendous growth just in past 2-3 years. According to latest research, Gartner <a href="https://www.gartner.com/smarterwithgartner/top-cx-trends-for-cios-to-watch/#:~:text=Chatbots%2C%20virtual%20assistants%20and%20robots,up%20from%2015%25%20in%202018" data-saferedirecturl="https://www.google.com/url?q=https://www.gartner.com/smarterwithgartner/top-cx-trends-for-cios-to-watch/%23:~:text%3DChatbots%252C%2520virtual%2520assistants%2520and%2520robots,up%2520from%252015%2525%2520in%25202018&amp;source=gmail&amp;ust=1620929202150000&amp;usg=AFQjCNHqLEXDwGf2hoInoVK1R5bimGANSw">predicts</a> that by 2022, 70% of customer interactions will involve bots — an increase of 15% from 2018. This does not come as a surprise, considering a <a href="https://www.businessinsider.com/chatbot-market-stats-trends">good amount</a> of consumers say they prefer chatbots to other virtual agents.

Last couple of months must have been super overwhelming for the overall Conversational AI team at Microsoft. Whether it's the <a href="https://docs.microsoft.com/en-us/azure/bot-service/what-is-new?view=azure-bot-service-4.0&amp;WT.mc_id=AI-MVP-5003464">Bot Framework SDK</a> or <a href="https://docs.microsoft.com/en-us/composer/what-is-new">Composer</a> with tons of new features, Power Virtual Agents <a href="https://docs.microsoft.com/en-us/power-virtual-agents/advanced-bot-framework-composer?WT.mc_id=AI-MVP-5003464">seamless integration</a> with Composer or the <a href="https://docs.microsoft.com/en-us/azure/bot-service/bot-service-manage-channels?view=azure-bot-service-4.0&amp;WT.mc_id=AI-MVP-5003464">new channels</a> and improvements at the Azure Bot Service; there have been significant updates for businesses. Cherry on the top is <a href="https://techcommunity.microsoft.com/t5/azure-ai/build-2021-conversational-ai-update/ba-p/2375203">Build 2021 goodness</a>!

As I said in my previous <a href="https://www.arafattehsin.com/generate-dialogs-automatically-using-form-dialogs-for-bot-framework-composer/">blog post</a> where I discussed the automatic generation of the Form Dialogs that every new feature deserves the whole blog post because of their explorative nature and productive use-case.

Therefore, today I am going to write about something which is freshly baked, super hot from the oven and that is the way of creating packages for your bots for better sharing, re-usability and cost-effective solutions. Before we get into the details of packages and their implementation, let us first understand why is it so important that a dedicated team worked on this new model for months to bring this goodness to you.
<blockquote>
<div>If you're relatively new to the Bot Framework (or Composer) then I'd suggest you to have a look <a href="https://docs.microsoft.com/en-us/composer/tutorial/tutorial-introduction">here</a> as in this post, it is assumed that you're familiar with the concepts and implementation of Bot Framework.</div></blockquote>
<h3>Challenges with the Current State</h3>
If you've built a sophisticated bot using Bot Framework Composer (&lt; v2.0.0) which is responsible for booking and tracking the food orders from your customers and you want to extend your bot to incorporate some middleware, custom adapters and other actions; you may have to face a lot hurdles to sort that out and that won't be straight forward at all.

Even if you get successful by addressing all of these challenges, you may have to go through the same issues again for another bot. <strong>Lacks re-usability. </strong>

Furthermore, if you create your bot using (Enterprise) Virtual Assistant Template, QnA Maker or just simple Echo bot using Visual Studio, you may end up having different experiences with each of them and building a common functionality around them may lead to a dead end.

Therefore, the Bot Framework team realized and this became the reason of the evolution of Bot Framework Component Model.
<h3>Meet Bot Framework Component Model</h3>
The <a href="https://github.com/BotBuilderCommunity/botbuilder-community-dotnet/releases/tag/v4.13.0">Bot Framework Component</a> Model is the new framework to share and re-use bot's functionality in the form of bot templates (<em>Empty bot, Core bot with Language</em>), packages (<em>Custom Adapters, Middleware</em>) or complete bots as skills. You can now create the bots with confidence as you won't find yourself in a situation where you can't customize or find it difficult to share the portions of your bot with others (<em>unless it's poorly designed </em>🤐)

<img class="aligncenter size-full wp-image-31156" src="https://www.arafattehsin.com/wp-content/uploads/2021/05/component-model.png" alt="Bot Framework Component Model" width="819" height="749" />

&nbsp;
<blockquote>Bot Framework Composer is now considered as the standard go-to approach for all sort of bots.</blockquote>
&nbsp;

This model is comprised of a few essential pieces;
<h3>Adaptive Runtime</h3>
Adaptive Runtime is the core of this model which wraps up the Bot Framework SDK and provides the extensibility points to add any functionality by importing packages, adding your custom coded extensions or even connecting to skills. This means that you just have to take care of your business logic rather than worrying about the runtime code.
<h3>Templates</h3>
Templates such as Empty Bot, Core Bot with QnA Maker etc. are created on top of Component Model. Since they're built by composing the packages (<em>discussed below</em>) therefore you can always edit / extend them according to your needs. For example, if you create a bot using Core Bot with QnA Maker, you can then add other packages such as Custom Adapters (Google, Zoom etc.) or Declarative Assets (LG) such as Welcome, Help &amp; Cancel. <strong>Flexibility is the key. </strong>

<img class="aligncenter size-full wp-image-31157" src="https://www.arafattehsin.com/wp-content/uploads/2021/05/templates.png" alt="Bot Framework Composer Templates" width="975" height="628" />
<h3>Skills</h3>
<a href="https://www.arafattehsin.com/add-skills-to-your-bot/">Skills</a> are just regular bots with the plug and play functionality. These bots can be connected to your existing bots to process the messages for you. This is done through the Skill manifest which establishes the contract that bots can follow and communicate with each other.
<h3>Packages</h3>
Packages are the components (or <em>bits</em> as per the product team) of a bot you want to re-use and share. Packages can be in the form of Declarative Dialogs (LG templates such as Welcome, Help etc.), Custom Adapters (Google, RingCentral, WhatsApp or Zoom etc.), Custom Actions (Adaptive Cards, Microsoft Teams etc.), Middleware and more. They can also be built in the combination of one another such as Custom Actions with Declarative Assets and so on.
<blockquote>Packages are just regular NuGet / npm packages depending upon the code language of your bot. On NuGet / npm, these packages are tagged with <em>msbot-component</em> to be displayed in Bot Framework Composer.</blockquote>
&nbsp;

With Bot Framework Composer v2.0.0 release, the creation experience is now based upon Adaptive Runtime and that's why you can see a new little icon on your left hand side of the Composer which indicates a whole section of Packages.

<img class="aligncenter size-full wp-image-31162" src="https://www.arafattehsin.com/wp-content/uploads/2021/05/package-manager.png" alt="Package Manager for Bot Framework Composer" width="746" height="588" />

&nbsp;

These packages can easily be added to your bot by just clicking on the Install button. If they're custom actions, you'll be able to see them right away in the Menu. For other types of packages such as Middleware, Custom Adapters, Skills etc. they can be used as described by their creators.

[Check out the video on this link to see how you can add the packages](https://www.arafattehsin.com/wp-content/uploads/2021/05/BotFramework-Packages.gif.mp4)

Did you notice that the team at Microsoft has done a great job in bringing up all of those packages upfront which were essential for bot development. For example, Adaptive Cards, Teams, Telephony and so much more.

But is it just Microsoft who is doing it? What if I want to connect it to some external middleware (as we discussed in start) or surface our bot to Google Assistant? Do we have something for that? Short answer is <strong>yes</strong>.
<h4>Community Packages</h4>
<a href="https://www.arafattehsin.com/bot-builder-community-project/">Bot Builder Community</a>, with the awesome collaboration and contributions from Microsoft, has done a great job in developing all of these fantastic packages which includes several Custom Adapters, Recognizers and Hand-off packages. You can easily have a look at the community packages by selecting the <strong>community </strong>options from the list. <em>Right now, they are not filtered properly but you can always identify the Community packages with <strong>BotBuilder.Community.Components.&lt;type&gt;.&lt;name&gt; </strong>pattern. </em>
<blockquote>Community Packages are 100% opensource and you're most welcome to get some inspiration from the existing implementation or provide your feedback by opening an issue</blockquote>
&nbsp;

<img class="aligncenter size-full wp-image-31165" src="https://www.arafattehsin.com/wp-content/uploads/2021/05/community-packages.gif" alt="Community Packages for Bot Framework Component Model" width="1908" height="992" />
<h4>Local Packages</h4>
Now if you are like me and you'd like to create your own or use packages developed by your team internally, then you'd want to test them before you actually publish them to either npm or NuGet. So, to address this issue, we've got to set-up the local feed (<em>same as we do for other .NET / js packages) </em>and we just have to add a new feed by clicking on the <strong>Edit feeds</strong> button inside Package manager. Once you've setup the local feed, your packages will start showing up and you can easily install / use them in a similar way as shown above.

[Check out the video on how you can add the locally developed packages to your bots](https://www.arafattehsin.com/wp-content/uploads/2021/05/2021-05-25_19-55-12.mp4)

Packages are the game changer esp. for Composer first bots. They definitely eliminate the need of re-writing code and increase the extensibility with better sharing capabilities. Not only this, it also allows you to connect with Skills seamlessly. In my upcoming post, I'll walk you through how you can create different types of Packages using Bot Framework Component Model.

Until next time.