Now that we know what Semantic Kernel is all about, it’s time to explore its key components. The Semantic Kernel library is built around several building blocks that can be used independently or in combination, depending on your application’s needs.
At a high level, the components include:
- The Kernel
- Services
- Plugins
- Functions
- Prompts and prompt templates
- Memory
- Filters
Let’s go step by step.
1. The Kernel – The Orchestrator
As the name suggests, the kernel is the central component of Semantic Kernel. It acts as an orchestrator between your application and AI models.
Key responsibilities include:
- Managing services and plugins – AI models, logging mechanisms, and other integrations are registered here.
- Dependency injection container – The kernel holds everything your app needs (services, plugins, utilities) and makes them accessible at runtime.
- Orchestrating tasks – Whether it’s a prompt execution, API call, or workflow, the kernel ensures the right components are available and used efficiently.
Getting started with the kernel is straightforward:
- Install the NuGet package – Since Semantic Kernel is a .NET library, you can add it via NuGet.
- Choose an AI model – It supports OpenAI GPT, Azure OpenAI, and other providers. Depending on your use case, you might need text completion, chat models, or image generation.
- Configure API keys – Each provider requires authentication. Your API key ensures secure communication between your app and the AI service.
Once the kernel is set up, you’re ready to extend it with services and plugins.
2. Services – Beyond Just AI Models
Services represent the capabilities your kernel can use.
- AI models – Examples include chat completion, text generation, image creation, or speech-to-text.
- Utilities – Logging, HTTP clients, or custom application services.
This design follows the .NET service provider pattern, making Semantic Kernel feel natural for developers already familiar with dependency injection.
3. Plugins – Extending Functionality
While services bring in external capabilities, plugins allow you to extend Semantic Kernel’s functionality with custom logic.
Examples include:
- Fetching live data from an external API.
- Retrieving records from a database.
- Triggering workflows inside your application.
With plugins, Semantic Kernel becomes more than just a bridge to AI—it becomes a hub where AI and business logic meet.
4. Functions, Prompts, and Templates
A function in Semantic Kernel represents a single task—like asking an LLM to summarize text or translate a sentence. Functions can be packaged into plugins or used standalone.
To power these functions, we rely on prompts and prompt templates:
- Prompts: Natural language instructions given to the model.
- Prompt templates: Reusable structures where parameters can be dynamically inserted.
This modularity makes prompts flexible, reusable, and maintainable across your application.
5. Memory
Semantic Kernel includes memory components, allowing you to persist context between interactions. This enables experiences like:
- Personalized conversations.
- Context-aware responses.
- Long-term knowledge retention.
6. Filters
Filters act as middleware for AI operations. They allow you to inspect, validate, or transform requests and responses before they are executed or returned.
Putting It All Together – Example
Once you initialize the kernel, you can register services like this:
var kernel = Kernel.CreateBuilder()
.AddOpenAIChatCompletion("gpt-4", apiKey)
.Build();
Now, you can build a simple console chatbot:
while (true)
{
Console.Write("User: ");
var input = Console.ReadLine();
var response = await kernel.InvokePromptAsync(input);
Console.WriteLine("AI: " + response);
}
This tiny app shows the power of Semantic Kernel: a few lines of code, and you have a working AI-powered chatbot.
And remember—you’re not limited to text. Semantic Kernel can integrate:
- Text-to-image: Generate images from descriptions.
- Image-to-text: Describe images (e.g., anomaly detection).
- Text-to-audio: Turn text into speech.
- Audio-to-text: Transcribe speech into text.
Conclusion
The key components of Semantic Kernel—kernel, services, plugins, functions, prompts, memory, and filters—work together to make AI integration into .NET apps both powerful and flexible.
By combining these elements, you can build applications that not only interact with AI but also integrate seamlessly with your business logic, external systems, and real-world workflows.
This is only the beginning. As you continue exploring, you’ll see how these components unlock new possibilities in AI-powered application design.
Top comments (0)