Introduction
The integration of AI into enterprise software has moved beyond chatbots and recommendation systems — it’s now about embedding reasoning, automation, and contextual intelligence directly into your application workflows.
Two powerful frameworks — LangChain and Semantic Kernel (SK) — make this possible. Both empower .NET developers to connect LLMs (Large Language Models) like GPT with custom business data, workflows, and APIs.
In this article, we’ll explore how to integrate LangChain and Semantic Kernel with ASP.NET Core, explaining their architecture, use cases, and implementation — all in a simple, educational, step-by-step way.
1. Why Integrate AI with ASP.NET Core
Modern enterprise APIs built with ASP.NET Core are excellent for performance, scalability, and modular design. But they lack one thing: contextual intelligence.
By integrating LLM frameworks such as LangChain or Semantic Kernel, you can enhance APIs to:
Generate smart summaries or insights from data
Automate decision-making based on rules and AI reasoning
Understand and process natural language queries
Build conversational interfaces backed by your business data
2. What Are LangChain and Semantic Kernel?
LangChain (for Python/JS/.NET)
LangChain is a framework designed to connect LLMs with external data sources and tools.
It provides modules for:
Prompt engineering
Memory (context retention)
Tool use (API calling, data retrieval)
Chaining — connecting model outputs into a reasoning pipeline
Semantic Kernel (for .NET, Python, Java)
Semantic Kernel is Microsoft’s open-source orchestration framework for integrating AI into applications.
It supports:
Semantic Functions (prompts + LLMs)
Native Functions (C# logic)
Memory storage (Redis, Cosmos DB, etc.)
Planner — automatically decides which function to execute next
3. Technical Workflow (Flowchart)
Below is a simple technical workflow showing how AI is integrated into an ASP.NET Core API:
+-------------------------+
| Client (Angular App) |
+-----------+-------------+
|
| HTTP Request (user query)
v
+-----------+-------------+
| ASP.NET Core API |
|-------------------------|
| Controller / Endpoint |
| Semantic Kernel Setup |
| LangChain Agent Logic |
+-----------+-------------+
|
| LLM Request (via OpenAI / Azure OpenAI)
v
+-----------+-------------+
| LLM Model (GPT, etc.) |
+-----------+-------------+
|
| Response (reasoned output)
v
+-----------+-------------+
| ASP.NET Core Response |
+-----------+-------------+
|
v
+-----------+-------------+
| Angular / UI Component |
+-------------------------+4. Setting Up Semantic Kernel in ASP.NET Core
Step 1: Install Required Packages
dotnet add package Microsoft.SemanticKernel
dotnet add package Microsoft.SemanticKernel.Connectors.AI.OpenAI
Step 2: Configure Semantic Kernel
Program.cs
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Connectors.AI.OpenAI;
var builder = WebApplication.CreateBuilder(args);
// Register Semantic Kernel
builder.Services.AddSingleton<IKernel>(sp =>
{
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion(
modelId: "gpt-4o-mini",
apiKey: builder.Configuration["OpenAI:ApiKey"]
)
.Build();
return kernel;
});
var app = builder.Build();
app.MapControllers();
app.Run();
5. Creating a Semantic Function
Semantic functions are AI-powered skills defined in .skprompt.txt files or inline.
Example: Summarize Customer Feedback
using Microsoft.SemanticKernel;
[ApiController]
[Route("api/[controller]")]
public class FeedbackController : ControllerBase
{
private readonly IKernel _kernel;
public FeedbackController(IKernel kernel)
{
_kernel = kernel;
}
[HttpPost("summarize")]
public async Task<IActionResult> SummarizeFeedback([FromBody] string feedback)
{
var prompt = @"Summarize this customer feedback in 3 key points:
{{$input}}";
var summarize = _kernel.CreateSemanticFunction(prompt);
var result = await summarize.InvokeAsync(feedback);
return Ok(result.GetValue<string>());
}
}
Request Example
POST /api/feedback/summarize
Body: "The product works fine but delivery was late. Support was slow but helpful."Response

Join the conversation! Your thoughts help the community grow.