Semantic Kernel: AI Orchestration for .NET Developers
Back to Tutorials
Azure AIIntermediate6 Steps

Semantic Kernel: AI Orchestration for .NET Developers

Microsoft LearnNovember 10, 202520 min watch19:07 min video

Learn Microsoft Semantic Kernel, the open-source SDK for building AI agents and integrating LLMs into .NET applications. Covers plugins, planners, memory, and multi-agent patterns.

Semantic Kernel: AI Orchestration for .NET

Semantic Kernel is Microsoft's open-source SDK for integrating Large Language Models (LLMs) into your applications. Think of it as the "middleware" between your app and AI models — handling plugins, memory, planning, and function calling.

Why Semantic Kernel?

  • Official Microsoft SDK for building AI agents in .NET (also Python & Java)
  • Model agnostic — Works with Azure OpenAI, OpenAI, Hugging Face, local models
  • Enterprise ready — Telemetry, dependency injection, async-first
  • Used by Microsoft — Powers Copilot features internally

Getting Started

Install the NuGet Package

dotnet add package Microsoft.SemanticKernel

Create the Kernel

using Microsoft.SemanticKernel;

var builder = Kernel.CreateBuilder();

builder.AddAzureOpenAIChatCompletion(
    deploymentName: "gpt-4o",
    endpoint: "https://my-openai.openai.azure.com/",
    apiKey: "your-key"
);

var kernel = builder.Build();

Simple Chat

var response = await kernel.InvokePromptAsync(
    "What are the benefits of microservices architecture?"
);
Console.WriteLine(response);

Plugins: Extending the AI

Plugins give the AI access to your application's capabilities.

Native Functions (C# methods)

public class WeatherPlugin
{
    [KernelFunction("get_weather")]
    [Description("Get the current weather for a city")]
    public async Task<string> GetWeatherAsync(
        [Description("The city name")] string city)
    {
        // Call your weather API
        var weather = await _weatherService.GetCurrentAsync(city);
        return $"{city}: {weather.Temp}°C, {weather.Condition}";
    }
}

// Register the plugin
kernel.Plugins.AddFromType<WeatherPlugin>();

Prompt Functions (AI-powered)

var summarize = kernel.CreateFunctionFromPrompt(
    "Summarize the following text in {{$maxSentences}} sentences: {{$input}}",
    new OpenAIPromptExecutionSettings { MaxTokens = 500 }
);

var result = await kernel.InvokeAsync(summarize, new()
{
    ["input"] = longDocument,
    ["maxSentences"] = "3"
});

Auto Function Calling

The most powerful feature — let the AI decide which plugins to use:

using Microsoft.SemanticKernel.Connectors.OpenAI;

// Register plugins
kernel.Plugins.AddFromType<WeatherPlugin>();
kernel.Plugins.AddFromType<CalendarPlugin>();
kernel.Plugins.AddFromType<EmailPlugin>();

// Enable automatic function calling
var settings = new OpenAIPromptExecutionSettings
{
    FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
};

var chatService = kernel.GetRequiredService<IChatCompletionService>();
var history = new ChatHistory();

history.AddUserMessage(
    "Check tomorrow's weather in Seattle and if it's rainy, " +
    "email the team to reschedule the outdoor event."
);

// The AI will automatically:
// 1. Call GetWeather("Seattle")
// 2. Check if it's rainy
// 3. Call SendEmail() to the team if needed
var response = await chatService.GetChatMessageContentAsync(
    history, settings, kernel
);

Memory & Embeddings

Add long-term memory to your AI using vector stores:

using Microsoft.SemanticKernel.Memory;

// Configure memory with Azure AI Search
var memoryBuilder = new MemoryBuilder();
memoryBuilder.WithAzureOpenAITextEmbeddingGeneration(
    "text-embedding-ada-002", endpoint, apiKey
);
memoryBuilder.WithAzureAISearchMemoryStore(searchEndpoint, searchApiKey);

var memory = memoryBuilder.Build();

// Save information
await memory.SaveInformationAsync("company-policies",
    id: "refund-policy",
    text: "Customers can request a full refund within 30 days of purchase..."
);

// Recall relevant information
var results = memory.SearchAsync("company-policies",
    "What is the refund policy?", limit: 3
);

Multi-Agent Patterns

Orchestrate multiple specialized agents:

using Microsoft.SemanticKernel.Agents;

// Define agents
var researcher = new ChatCompletionAgent
{
    Name = "Researcher",
    Instructions = "You research topics and provide detailed findings.",
    Kernel = kernel
};

var writer = new ChatCompletionAgent
{
    Name = "Writer",
    Instructions = "You write polished articles based on research findings.",
    Kernel = kernel
};

// Create a group chat
var chat = new AgentGroupChat(researcher, writer)
{
    ExecutionSettings = new()
    {
        TerminationStrategy = new MaxTurnsTerminationStrategy(6)
    }
};

chat.AddChatMessage(new ChatMessageContent(AuthorRole.User,
    "Write a blog post about the future of AI in healthcare"));

await foreach (var message in chat.InvokeAsync())
{
    Console.WriteLine($"{message.AuthorName}: {message.Content}");
}

Resources

Video: Watch the Semantic Kernel getting started series on Microsoft Developer YouTube.

Semantic Kernel.NETAI AgentsAzure OpenAIOrchestration

Share this tutorial

Chapters (6)

  1. 1

    What is Semantic Kernel?

    Overview of the SDK and its role in AI development

    00:00
  2. 2

    Setting Up in .NET

    Install and configure Semantic Kernel with Azure OpenAI

    04:00
  3. 3

    Plugins & Functions

    Create native and prompt-based plugins

    6:00
  4. 4

    Auto Function Calling

    Let the AI choose and invoke plugins autonomously

    8:00
  5. 5

    Memory & Embeddings

    Add long-term memory with vector stores

    12:00
  6. 6

    Multi-Agent Patterns

    Orchestrate multiple agents for complex tasks

    15:00

About the Author

KH

Microsoft Learn

Microsoft MVP | AI Engineer

Software & AI Engineer specializing in Microsoft Azure, .NET, and cutting-edge AI technologies.

Need help with your project?

Let's discuss how I can help bring your ideas to life.

Get In Touch