Leap Forward with Modern AI using Microsoft 365 Agents SDK and Semantic Kernel

splash-agents-sdk-sk

Happy new year. I know you’re excited to see this. It is real, it is happening, but you know what? It is still in preview and things will break. So, get ready for it. If you’re wondering what this SDK is all about then despite my little coverage about it in this post, you also may want to read the official documentation which Microsoft team has quickly put together for you. The objective of this post is to show you how to use Semantic Kernel’s Agent Framework with Microsoft 365 Agents SDK and why is it a big deal.

🤔 Evolution or a new skin?

Not sure how many times (probably 100-ish?) I have mentioned on multiple instances that Bot Framework has been one of the best frameworks produced for Conversational AI by any team. I still remember those days when it evolved into such a great offering for not just code-first developers but also those who could utilise Composer client to create exceptional conversational experiences. However, with time and strategy change, Copilot Studio took the charge and started to release those cool features which are essential for today’s conversational experiences.

In the parallel world, considering multiple focus areas of Microsoft AI, enterprises who were already using Bot Framework SDK are a bit worried of its future. Why? Because they don’t see any advancements with the similar speed as they witness in other products, for example .NET AI Extensions, Semantic Kernel, Microsoft Copilot Studio and so on. I think today they have an answer (well, to be fair, an early answer) in the form of Microsoft Agents 365 SDK.

Microsoft 365 Agents SDK (Preview) represents a significant evolution in building enterprise-grade, scalable, multi-channel agents. It enables developers to create agents that integrate AI services of their choice, such as Azure AI Foundry and connect with orchestration layers like Semantic Kernel. These agents can be deployed across various channels including web via Direct Line, Microsoft Teams, Microsoft 365 Copilot and more.

To put it differently, this SDK bridges the gap between the robust foundation laid by the Bot Framework and the cutting-edge capabilities demanded by modern AI-driven conversational experiences. Think of it as a natural evolution rather than a replacement of Bot Framework, because in reality, it isn’t the one.

🚀 10x Up with Semantic Kernel

Semantic Kernel is an enterprise grade framework to build your AI-first apps. Every time we see any advancement within the Generative AI space, be it Parallel Function Calling, Vector Stores, Small Language Models and so on, we see these features getting shipped with a speed. Similarly, they already had ChatCompletion capabilities from day 1 and now with the advancements of Agentic AI, we’ve have got an Agent Framework as well.

However, due to the light-weight nature of the framework, Semantic Kernel relies upon developers to build their own conversational experiences. Such as conversational event handling (i.e. when someone joins the chat), effective middleware routing and integration with the external channels such as Direct Line, Telephony, Microsoft Teams, Facebook, Slack and so on. This can now be unlocked by Microsoft 365 Agent SDK, Azure Bot and Semantic Kernel together.

Sequence Diagram of a Microsoft 365 Agent SDK Agent with Semantic Kernel

Currently, the functionality doesn’t have much except for a very basic use-case which talks about getting the flight status (mocked up) from Azure OpenAI Service with an Adaptive Card as a response back. I will improve the use-case as we move along in our upcoming posts.

BotFramework-Emulator-Agent

📦 Project and Packages

We will now explore as how you can integrate Semantic Kernel’s Agent Framework with Microsoft 365 Agent SDK agent and surface it to multiple channels via Azure Bot. Unlike Bot Framework SDK, you don’t have any Visual Studio starter templates therefore, you need an Empty ASP.NET Core project. Once you get that project, all you need is the set of nuget packages, just like below.

NuGet Packages for M365 Agent SDK and Semantic Kernel

After that, you may create a similar folder structure as mine which I will explain you one by one. That’s how it looks like.

Solution Structure for M365 Agent SDK and Semantic Kernel

The complete working example is now a part of my repo which you can access. If you like it, give it a star as it will help others too.

Disclaimer: Below code description is generated by o1-preview.

Program.cs

This is the entry point of the application. It sets up the web application, configures services, and starts the web server.

  • Configuration: Adds user secrets in development mode.
  • Services: Adds controllers, HTTP client, and registers the Semantic Kernel.
  • AI Service Registration: Configures Azure OpenAI or OpenAI based on the configuration.
  • Bot Registration: Registers the TravelAgent and the bot handler.
  • Application Build and Run: Builds the application and maps controllers

BotHandler.cs

This file contains the BotHandler class, which handles bot interactions.

  • OnMessageActivityAsync: Processes incoming messages, invokes the TravelAgent, and sends the response back to the user
  • OnMembersAddedAsync: Sends a welcome message when a new member is added to the conversation

ServiceCollectionExtensions.cs

This file contains extension methods for configuring services in the dependency injection container.

  • AddBot: Configures services for the bot, including authentication, connection clients, and the bot adapter

BotController.cs

This file contains the BotController class, which handles HTTP requests related to the bot.

  • PostAsync: Processes incoming HTTP POST requests and invokes the bot to handle the message

appsettings.json

This file contains configuration settings for the application.

  • TokenValidation: Contains audience settings for token validation.
  • Connections: Contains settings for the bot service connection, including client ID, client secret, and scopes.
  • ConnectionsMap: Maps service URLs to connections.
  • Logging: Configures logging levels for different components

TravelAgent.cs

This file defines the TravelAgent class, which acts as a virtual assistant for flight tracking.

  • Constructor: Initializes the Kernel, ChatHistory, and ChatCompletionAgent. Adds the TimePlugin to the agent’s kernel.
  • InvokeAgentAsync: Takes user input, adds it to the chat history, invokes the agent, and ensures the response is in the correct format.

FlightResponse.cs

This file defines the FlightResponse class, which represents the response format expected from the TravelAgent

  • Properties: ContentType and Content with appropriate JSON serialization attributes.

TimePlugin.cs

This file defines the TimePlugin class, which provides time-related functionalities to the TravelAgent

  • Methods: Various methods to get the current date, time, year, month, day, etc., formatted in different ways.

🌐 Surface it to your favourite channels

If you have previously worked with Bot Framework SDK and Azure Bot then it wouldn’t surprise you that the process is still the same. However, if you are new to this, then you may have to learn about it first. Below screenshot is what I have created for this demo and then I have configured the Azure Bot to use my Web App.

Azure Resource Management

Please note that I have got an Azure OpenAI Service subscription residing outside of this resource group so it’s up to you if you want to keep it inside or use whatever is available. You can also learn about configuring the Azure Bot from Microsoft Learn docs. My current setup is just surfacing it to Microsoft Teams rather than anything else. Embedded WebChat and DirectLine are on by default.

Agent-Channels

I’m a part of Microsoft’s tenant as a Guest therefore, I do not have the privilege to install an app in Teams. However, I could successfully test on the same.

Microsoft-Teams-Agent

Microsoft 365 Agents SDK and Semantic Kernel represent a significant leap forward in the realm of AI-driven solutions. By leveraging these powerful tools, developers can create more intelligent, context-aware applications that enhance user experiences and streamline workflows.

The integration of Semantic Kernel allows for a deeper understanding of user intent, enabling more accurate and relevant responses. As we continue to explore the potential of these technologies, the possibilities for innovation are boundless. I will try to uncover some of the advanced capabilities in upcoming posts.

Until next time.

Leave a Reply