May 21st, 2025
1 reaction

Semantic Kernel and Microsoft.Extensions.AI: Better Together, Part 1

Roger Barreto
Senior Software Engineer

This is the start of a series highlighting the integration between Microsoft Semantic Kernel and Microsoft.Extensions.AI. Future parts will provide detailed examples of using Semantic Kernel with Microsoft.Extensions.AI abstractions. 

The most common questions are: 

  • “Do Microsoft’s AI extensions replace Semantic Kernel?” 
  • “When should I use Microsoft’s AI extensions instead of Semantic Kernel?” 

This blog post will address these questions and offer guidance on when and how to use them. First, we will explore what Microsoft Extensions AI is and its relationship with Semantic Kernel. 

The Evolution of AI Integration in .NET with Microsoft Extensions AI

Artificial Intelligence, or AI, is evolving at a rapid pace that many developers struggle to keep up with. The Semantic Kernel team responded to this shift in how apps are written with a suite of solutions that run on multiple platforms and support most popular languages, leading with C#.  

The .NET team recognized the importance and impact of AI and built a set of foundational building blocks to support a thriving ecosystem and ease the burden of learning and integrating AI into applications for .NET developers.  This foundation is based on established patterns, and in many cases Semantic Kernel used as the prototype. This foundation exists in the Microsoft.Extensions.AI namespace and provides AI extensions for .NET. 

The AI extensions not only catalyzed a thriving and rapidly growing ecosystem but also simplified many common interactions developers have with LLMs such as bidirectional chat and image analysis. The team worked closely with Semantic Kernel to ensure that once the building blocks were released, Semantic Kernel could easily migrate from their built-in primitives to use AI extensions. Due to the timing needed to make this possible, the interim state led to some confusion amongst developers wondering whether the AI extensions would replace the corresponding concepts in Semantic Kernel. 

The release of the AI extensions for .NET (the types and interfaces provided by the Microsoft.Extensions.AI.* set of packages) set an important catalyst for the evolution of Intelligent Apps in .NET. The AI extensions are intended to provide the grounds of common primitives and building blocks that the .NET ecosystem can use to build higher level AI applications and solutions including orchestrators and agentic frameworks. They serve as “exchange types”, types .NET libraries can and should expose and consume so that many such libraries can be composed and easily interoperate. Semantic Kernels is such a set of libraries. 

The concept of the .NET AI extensions is based on successful patterns from other popular .NET frameworks including ASP.NET. If you are a web developer, you may be familiar with some of the concepts that ASP.NET supports, including dependency injection, middleware, and support for multiple providers. The extensions for AI in .NET are based on these proven patterns.  

How Microsoft Extensions AI relates to Semantic Kernel

To better understand the relationship between Microsoft Extensions AI and Semantic Kernel, consider the analogy of a foundational SDK and a specialized SDK built on top of it.

Microsoft Extensions AI serves as a foundational SDK, providing low-level abstractions and APIs for integrating AI capabilities into your applications. It offers flexible tools that enable you to build custom AI workflows tailored to your specific needs.

Semantic Kernel, on the other hand, is a specialized SDK built on top of Microsoft Extensions AI. It extends the foundational capabilities by introducing higher-level features designed for more advanced AI scenarios, such as agents, plugins, prompt templates, and workflow automation. Semantic Kernel simplifies tasks that would otherwise require significant effort if built purely with the foundational SDK.

A useful analogy within the C# ecosystem is the relationship between System.Net.Http and ASP.NET Core MVC:

  • System.Net.Http is a foundational SDK that provides the tools for sending and receiving HTTP requests. It allows developers to work directly with the HTTP protocol, enabling full control over how data is sent and received.
  • ASP.NET Core, while not a framework in this analogy, can be thought of as a specialized SDK that builds upon foundational tools like System.Net.Http. It abstracts away many of the lower-level details of making HTTP requests and provides additional features such as routing, model binding, and view rendering, tailored specifically for building web applications.Similarly:
  • Microsoft Extensions AI is the foundational SDK, offering the core abstractions for building AI-enabled applications.
  • Semantic Kernel is the specialized SDK that builds on Microsoft Extensions AI, simplifying advanced AI workflows and enabling features like agents, plugins, and automation. By leveraging both, developers can choose the right level of abstraction for their application, whether they need the flexibility of Microsoft Extensions AI or the higher-level capabilities of Semantic Kernel for complex AI scenarios.Because many of the current Microsoft Extensions AI abstractions were inspired by the initial abstractions in Semantic Kernel, some overlap exists in terms of functionality. To address this, Semantic Kernel has recently been updated to natively support Microsoft Extensions AI abstractions in its APIs, such as IChatClient and others. This alignment ensures a smoother integration experience and allows developers to leverage the strengths of both SDKs seamlessly.

When to use Microsoft Extensions AI and Semantic Kernel?

Microsoft Extensions AI provides a lower-level abstraction layer. By creating your code on top of Microsoft Extensions AI, you automatically can use those implementations with Semantic Kernel. 

In cases where overlapping abstractions exist between Semantic Kernel and Microsoft Extensions AI, we recommend transitioning your code to use Microsoft Extensions AI abstractions. Over time, the overlapping abstractions in Semantic Kernel will be phased out in favor of the newer, more standardized abstractions in Microsoft Extensions AI. Detailed migration guidance will be shared in upcoming blog posts to help you make this transition smoothly.

For most applications, you will begin development using libraries implemented on top of Microsoft.Extensions.AI, which provide foundational AI capabilities. Semantic Kernel should be used when your application requires higher-level features such as Agents, Plugins, Prompt Templates, or Workflow Automation. Semantic Kernel builds on the foundational abstractions of Microsoft Extensions AI to simplify advanced AI scenarios and streamline development for more complex use cases.

How Semantic Kernel Supports Microsoft.Extensions.AI Types

Chat Completion

Semantic Kernel’s chat completion functionality now natively supports Microsoft.Extensions.AI types:

  1. Kernel Builder Extensions
    • The AddOpenAIChatClient()AddAzureOpenAIChatClient(), and other connector extension methods were added and now register the new  Microsoft.Extensions.AI’s IChatClient implementations
    • This allows you easily migrate to the new API with the same configuration
  2. Service Collection Extensions
    • Similar to KernelBuilder, DI extensions like services.AddOpenAIChatClient() now register the new IChatClient
    • This enables seamless integration in dependency injection scenarios
  3. ChatCompletionAgent
    • Can now work with either IChatCompletionService or IChatClient

Embedding Generation

Semantic Kernel has moved from its own ITextEmbeddingGenerationService to Microsoft.Extensions.AI’s IEmbeddingGenerator<string, Embedding<float>>:

  1. Embedding Service Registration
    • Methods like AddOpenAIEmbeddingGenerator() and AddAzureOpenAIEmbeddingGenerator() now register Microsoft.Extensions.AI’s IEmbeddingGenerator<string, Embedding<float>>
    • The older interfaces are marked as obsolete
  2. Automatic Conversion
    • Semantic Kernel provides extension methods to convert between its older embedding interfaces and the new Microsoft.Extensions.AI interfaces
    • This ensures backward compatibility while encouraging migration to the new types
  3. Vector Operations
    • Vector operations in Semantic Kernel now work with Microsoft.Extensions.AI’s Embedding<float> type
    • This provides a standardized way to work with embeddings across different providers
    • For more information check our vector data extensions blog post.

Function Calling

Semantic Kernel’s function calling capabilities now integrate with Microsoft.Extensions.AI types:

  1. UseKernelFunctionInvocation
    • Allows any IChatClient to be configured to invoke Kernel functions
    • Automatically handles function calling protocol conversion
  2. AIFunction Integration
    • Semantic Kernel’s KernelFunction is now a AIFunction and can be used with Microsoft.Extensions.AI’s compatible environment.
    • Extension methods like AsKernelFunction() are also available to allow specializing your existing AIFunction for easy conversion
  3. Function Arguments
    • Semantic Kernel’s KernelArguments are now Microsoft.Extensions.AI’s AIFunctionArguments

Content Types

Semantic Kernel now supports retrieval of Microsoft.Extensions.AI content types:

  1. ChatMessageContent
    • Can be converted to/from Microsoft.Extensions.AI’s ChatMessage
    • Supports all the same content types (text, images, function calls, etc.)
  2. Streaming Support
    • Semantic Kernel’s streaming interfaces now work with Microsoft.Extensions.AI’s ChatResponseUpdate
    • This enables consistent streaming behavior across different providers
  3. Kernel InvokeAsync<T>
    • Providing a T of Microsoft.Extensions.AI type is now supported when retrieving kernel contents.

Service Selection

Semantic Kernel’s service selection mechanism now works with Microsoft.Extensions.AI services:

  1. Added a new IChatClientSelector abstraction
    • Specialized selector for chat clients
    • Kernel instances now also rely on this new interface for Microsoft.Extensions.AI’s IChatClient discovery and selection

Dependency Injection

Semantic Kernel’s DI support now includes Microsoft.Extensions.AI types:

  1. Service Registration
    • IChatClient added to your service collection will be automatically visible to the Kernel selector.
  2. Automatic Adaptation
    • When using DI, Semantic Kernel automatically adapts between its own types and Microsoft.Extensions.AI types
    • This ensures a consistent experience regardless of which API style you prefer

This native support for Microsoft.Extensions.AI types means you can now use Semantic Kernel with the broader Microsoft AI ecosystem more seamlessly, with consistent programming models and easy interoperability between different components.

Eager to explore the new Microsoft.Extensions.AI with Semantic Kernel? Please check out these packages and samples: 

Package: 

References: 

  • EShop Support with Microsoft.Extensions.AI –  eShop Support 

Author

Roger Barreto
Senior Software Engineer

0 comments