Implementation:Microsoft Semantic kernel Kernel CreateBuilder
| Knowledge Sources | |
|---|---|
| Domains | AI_Orchestration, Dependency_Injection |
| Last Updated | 2026-02-11 19:00 GMT |
Overview
Concrete tool for creating a new kernel builder instance provided by the Microsoft Semantic Kernel library.
Description
Kernel.CreateBuilder() is the static factory method that returns a new IKernelBuilder instance. This is the primary entry point for constructing a Semantic Kernel. The returned builder exposes a fluent API for registering AI services, plugins, and other dependencies before materializing the kernel via the Build() method.
Internally, the method creates a KernelBuilder that wraps an IServiceCollection. All subsequent configuration calls (such as adding AI connectors or plugins) register services into this collection. When Build() is finally called, the collection is compiled into an IServiceProvider which the kernel uses to resolve its dependencies at runtime.
Usage
Use Kernel.CreateBuilder() at the beginning of any Semantic Kernel application to start the kernel configuration pipeline. This is the first call in the standard setup sequence: create builder, register services, build kernel.
Code Reference
Source Location
- Repository: semantic-kernel
- File:
dotnet/src/SemanticKernel.Abstractions/Kernel.cs:L85
Signature
public static IKernelBuilder CreateBuilder()
Import
using Microsoft.SemanticKernel;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| (none) | N/A | N/A | This is a parameterless static factory method. |
Outputs
| Name | Type | Description |
|---|---|---|
| return | IKernelBuilder |
A new builder instance that can be configured with AI services, plugins, and other dependencies before calling Build(). |
Usage Examples
Minimal Kernel Creation
using Microsoft.SemanticKernel;
// Create a builder and immediately build a minimal kernel
Kernel kernel = Kernel.CreateBuilder().Build();
Kernel with OpenAI Chat Service
using Microsoft.SemanticKernel;
// Create kernel with OpenAI chat completion
Kernel kernel = Kernel.CreateBuilder()
.AddOpenAIChatClient(
modelId: "gpt-4o",
apiKey: "your-api-key")
.Build();
Builder with Multiple Services
using Microsoft.SemanticKernel;
// Create a builder, configure multiple services, then build
IKernelBuilder builder = Kernel.CreateBuilder();
builder.AddOpenAIChatClient(
modelId: "gpt-4o",
apiKey: "your-api-key");
// Register additional services into the builder's service collection
builder.Services.AddLogging(b => b.AddConsole());
Kernel kernel = builder.Build();