Tutorials AI & LLM Engineering for .NET Architects
Introduction to Microsoft Semantic Kernel (SK)
On this page
Semantic Kernel for .NET Architects
Semantic Kernel (SK) is Microsoft's answer to LangChain. It is a lightweight SDK that allows you to mix AI models with your existing C# code. It is designed to be the "Operating System" for AI applications.
1. Why Semantic Kernel?
LangChain is primarily Python-first and can be messy in a professional .NET environment. SK is C#-first, follows standard Dependency Injection (DI) patterns, and integrates perfectly with ASP.NET Core. It provides a structured way to handle prompts, memory, and tool-calling.
2. The Kernel Object
The Kernel is the heart of the app. It manages the configuration of AI models (OpenAI, Azure, local) and the registry of available tools (Plugins). Think of it as the "Orchestrator" that knows how to talk to models and code simultaneously.
3. Prompt Templating
SK uses a powerful templating engine. You can embed variables and even C# function calls directly inside your prompt strings:
"Summarize this text: {{ $input }}. Use a tone that matches {{ MyPlugin.GetTone }}."
4. Interview Mastery
Q: "How does Semantic Kernel enable 'Model Agnostic' development?"
Architect Answer: "SK uses a **Connector Architecture**. You write your code once using the SK interfaces. You can then swap between `AzureOpenAIChatCompletion`, `OpenAIChatCompletion`, or a local `LlamaSharp` model by changing only a single line in your Startup/Program configuration. This prevents vendor lock-in and allows for easy local development without cloud costs."