Home

How to Build Your First AI Agent with Semantic Kernel in 18 Minutes

Me

Mei-Lin Zhang

May 23, 20268 min read

# How to Build Your First AI Agent with Semantic Kernel in 18 Minutes ## What Semantic Kernel Is and Who Should Use It Semantic Kernel (SK) is an open‑source SDK that lets developers orchestrate larg...

How to Build Your First AI Agent with Semantic Kernel in 18 Minutes

What Semantic Kernel Is and Who Should Use It

Semantic Kernel (SK) is an open‑source SDK that lets developers orchestrate large language models (LLMs) with traditional code, plugins, and memory. It is maintained by Microsoft and targets .NET developers who want to add LLM‑driven reasoning to existing applications without rewriting them in a new framework. If you already work with C#, ASP.NET Core, or Azure Functions and need an agent that can call APIs, access databases, or run custom logic, SK provides a lightweight bridge between deterministic code and generative AI.

Key Features and Capabilities

  • Planner‑based orchestration: SK includes a built‑in planner that can decompose a user goal into a sequence of steps, each mapped to a registered plugin or native function.
  • Plugin model: Any .NET method, class, or HTTP endpoint can be exposed as a plugin. SK automatically generates function descriptions for the LLM so it knows when and how to invoke each plugin.
  • Memory connectors: SK ships with volatile, semantic, and external memory stores (e.g., Azure Cognitive Search, Redis, Qdrant) enabling the agent to retain context across turns.
  • Prompt templating: Uses the Handlebars‑like syntax to inject variables, chat history, and function results into LLM prompts.
  • Streaming support: Works with streaming completions from Azure OpenAI, OpenAI, and local models via Hugging Face pipelines.
  • Observability: Integrates with OpenTelemetry for tracing LLM calls, plugin executions, and token usage.

These features make SK suitable for building agents that need to combine deterministic business logic with LLM reasoning, such as automated report generation, dynamic workflow orchestration, or conversational assistants that query internal data sources.

Architecture and How It Works

At runtime, a Semantic Kernel agent consists of three layers:

  1. Kernel – the core object that holds service registrations (LLM, plugins, memory).
  2. Plugins – collections of functions annotated with kernel attributes or registered via kernel.ImportPluginFromType<T>(). Each function receives a KernelArguments bag containing inputs from the LLM or previous steps.
  3. Planner – optionally invoked to turn a natural‑language goal into an execution plan. The default planner uses a ReAct‑style loop: think (LLM decides next action), act (invoke plugin), observe (feed result back to LLM).

When a user message arrives, the kernel builds a prompt that includes the system message, chat history, and descriptions of all available plugins. The LLM returns either a plain text response or a structured function call. If a function call is returned, the kernel executes the matching plugin, captures its output, appends it to the chat history, and repeats until the LLM decides to finish.

This loop is fully asynchronous and can be customized: you can replace the planner with a custom logic, inject your own telemetry, or swap the LLM service for a local model served through ONNX Runtime.

Real‑World Use Cases

  • Internal knowledge‑base assistant: A company deploys an SK agent that plugs into Azure Cognitive Search. Employees ask natural‑language questions; the planner decides to invoke the search plugin, retrieves relevant documents, and the LLM summarizes the answer.
  • Automated CI/CD triage: An agent monitors pull‑request comments. When a reviewer requests a change, the agent invokes a plugin that runs a static‑analysis tool, posts results back, and suggests fixes.
  • Dynamic report generator: A marketing team uses an SK agent that pulls latest campaign metrics from a Power BI plugin, formats them with a templating plugin, and emails the PDF via SendGrid.
  • Edge‑device anomaly detector: On an IoT gateway, a lightweight SK host runs a local LLM (e.g., Phi‑2) and uses a plugin to read sensor streams. When values deviate, the planner triggers an alert plugin that sends an MQTT message.

These examples show SK’s strength in scenarios where you already have .NET services and want to augment them with LLM‑driven decision making without moving to a Python‑centric stack.

Strengths and Limitations

Strengths

  • Native .NET integration: no context switching between languages; you can reuse existing NuGet packages, dependency injection, and ASP.NET middleware.
  • Low latency for internal calls: plugin execution is in‑process, avoiding the overhead of RPC or container hops.
  • Transparent prompt engineering: you can inspect the exact prompt sent to the LLM at any point, which aids debugging and compliance.
  • Extensible memory: plug in any vector store or custom cache without rewriting the agent loop.

Limitations

  • Smaller community compared to LangChain or AutoGen; fewer third‑party plugins and tutorials.
  • Planner capabilities are less expressive than LangGraph’s state‑graph or CrewAI’s role‑based hierarchy; complex conditional loops may require custom planner code.
  • Primarily focused on .NET; if your team prefers Python or JavaScript, you’ll face a steeper learning curve.
  • Streaming support depends on the underlying LLM provider; some local models may not expose token‑by‑token callbacks.

Overall, SK excels when you need tight coupling between LLM reasoning and existing .NET services, but you may need to invest more effort for advanced multi‑agent choreography.

Comparison with Alternatives

The table below contrasts Semantic Kernel with three popular agent frameworks as of late 2025.

Feature Semantic Kernel (v1.x) LangChain/LangGraph AutoGen CrewAI
Primary language .NET (C#) Python Python (with .NET bridge) Python
Built‑in planner Yes (ReAct‑style) LangGraph (state graph) Yes (conversational) Yes (role‑based)
Plugin model .NET methods, HTTP, Azure Functions Tools (Python functions) Tools (Python/ .NET) Tools (Python)
Memory connectors Volatile, semantic, Azure Cognitive Search, Redis, Qdrant In‑memory, FAISS, Chroma, Pinecone Similar to LangChain Similar to LangChain
Streaming LLM support Yes (Azure OpenAI, OpenAI, Hugging Face) Yes Yes Yes
Observability OpenTelemetry tracing LangSmith (paid) + OpenTelemetry Azure Monitor integration Custom logging
Enterprise support Microsoft (Azure) Community + LangChain Inc. Microsoft (GitHub) Community
Typical use case .NET enterprise apps, Azure‑centric workflows Rapid prototyping, research Multi‑agent chat, code‑gen Role‑play simulations, training

Semantic Kernel’s advantage is its first‑class .NET experience; if your stack is already on Azure or you need to call existing C# services, SK reduces integration friction. For pure‑Python prototyping or when you need advanced graph‑based control flows, LangChain/LangGraph may be preferable.

Getting Started Guide

Below is a step‑by‑step walkthrough to create a simple agent that answers questions about the current weather using a free public API. The entire process can be completed in under 18 minutes if you have .NET 8 SDK installed.

1. Create a new console project

dotnet new console -n WeatherAgent
cd WeatherAgent

2. Add the Semantic Kernel NuGet package

dotnet add package Microsoft.SemanticKernel --version 1.22.0

3. Add a helper package for HTTP calls

dotnet add package System.Net.Http.Json

4. Implement a weather plugin

Create a file WeatherPlugin.cs:

using System;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.SemanticKernel;

public class WeatherPlugin
{
    private static readonly HttpClient _http = new HttpClient();

    [KernelFunction, Description("Gets the current weather for a given city.")]
    public async Task<string> GetCurrentWeatherAsync(
        [KernelParameterDescription("City name, e.g. London")] string city)
    {
        // Using wttr.in – a free, no‑API‑key service
        var url = $"https://wttr.in/{city}?format=%C+%t";
        var response = await _http.GetStringAsync(url);
        return response.Trim();
    }
}

5. Wire up the kernel in Program.cs

Replace the contents of Program.cs with:

using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;

var builder = Kernel.CreateBuilder();

// Add Azure OpenAI service – replace with your own endpoint and key
builder.Services.AddAzureOpenAIChatCompletion(
    deploymentName: "gpt-4o-mini",
    endpoint: "https://YOUR_RESOURCE.openai.azure.com/",
    apiKey: "YOUR_API_KEY");

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

Kernel kernel = builder.Build();

var chat = kernel.GetRequiredService<IChatCompletionService>();

Console.WriteLine("Ask about the weather (type 'exit' to quit):");
while (true)
{
    Console.Write("> ");
    var input = Console.ReadLine();
    if (string.Equals(input, "exit", StringComparison.OrdinalIgnoreCase)) break;

    var chatHistory = new ChatHistory();
    chatHistory.AddSystemMessage("You are a helpful assistant that can check the weather.");
    chatHistory.AddUserMessage(input);

    var result = await chat.GetChatMessageContentAsync(chatHistory, kernel);
    Console.WriteLine($"Assistant: {result}");
}

6. Run the agent

dotnet run

You should see a prompt. Try asking:

What’s the weather in Tokyo? The agent will call the GetCurrentWeatherAsync plugin, retrieve a short description like "Clear +22°C", and return it in a friendly sentence.

7. Extending the agent

  • Add more plugins (e.g., a calendar plugin that reads Outlook via Microsoft Graph).
  • Swap the planner: replace the default loop with new FunctionCallingStepwisePlanner(kernel) for more control.
  • Hook up a semantic memory store: builder.Services.AddMemoryStorage(new VolatileMemoryStore()); and enable recall in the chat history.

This minimal example demonstrates the core loop: LLM decides to invoke a plugin, plugin runs deterministic code, result feeds back into the conversation. From here you can scale to multi‑step workflows, integrate with Azure Functions for serverless scaling, or add telemetry to monitor token usage and latency.

Final Thoughts

Semantic Kernel offers a pragmatic path for .NET developers who want to augment existing services with LLM‑driven reasoning without abandoning their current toolchain. Its tight integration with .NET dependency injection, straightforward plugin model, and optional planner give you just enough abstraction to stay productive while retaining full control over the agent’s behavior. If your team lives in the .NET ecosystem and needs an agent that can call internal APIs, query databases, or run custom logic, SK is worth a closer look. For pure‑Python research or when you need advanced graph‑based orchestration, consider LangChain/LangGraph or AutoGen instead.


References

Keywords

Semantic KernelAI agent.NETLLM plannerplugin architectureweather agent tutorialcomparison with LangChain AutoGen CrewAI

Keep reading

More related articles from DriftSeas.