Soenneker.SemanticKernel.Pool 4.0.124

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.SemanticKernel.Pool --version 4.0.124
                    
NuGet\Install-Package Soenneker.SemanticKernel.Pool -Version 4.0.124
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.SemanticKernel.Pool" Version="4.0.124" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.SemanticKernel.Pool" Version="4.0.124" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.SemanticKernel.Pool" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.SemanticKernel.Pool --version 4.0.124
                    
#r "nuget: Soenneker.SemanticKernel.Pool, 4.0.124"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.SemanticKernel.Pool@4.0.124
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.SemanticKernel.Pool&version=4.0.124
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.SemanticKernel.Pool&version=4.0.124
                    
Install as a Cake Tool

alternate text is missing from this package README image
alternate text is missing from this package README image
alternate text is missing from this package README image

alternate text is missing from this package README image Soenneker.SemanticKernel.Pool

A high-performance, thread-safe pool implementation for Microsoft Semantic Kernel instances with built-in rate limiting capabilities.

Features

  • Kernel Pooling: Efficiently manages and reuses Semantic Kernel instances
  • Rate Limiting: Built-in support for request rate limiting at multiple time windows:
    • Per-second rate limiting
    • Per-minute rate limiting
    • Per-day rate limiting
    • Token-based rate limiting
  • Thread Safety: Fully thread-safe implementation using concurrent collections and async locking
  • Flexible Configuration: Configurable rate limits and pool settings
  • Resource Management: Automatic cleanup of expired rate limit windows

Installation

dotnet add package Soenneker.SemanticKernel.Pool
services.AddSemanticKernelPoolAsSingleton();

Extension Packages

This library has several extension packages for different AI providers:

Usage

Startup Configuration

// Program.cs or Startup.cs
public class Program
{
    public static async Task Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        // Add the kernel pool as a singleton
        builder.Services.AddSemanticKernelPoolAsSingleton();

        var app = builder.Build();

        // Get the pool service
        var kernelPool = app.Services.GetRequiredService<ISemanticKernelPool>();

        // Create SemanticKernelOptions (example uses OpenAI)
        var options = new SemanticKernelOptions
        {
            ApiKey = "your-api-key",
            Endpoint = "https://api.openai.com/v1",
            Model = "gpt-4",
            KernelFactory = async (opts, _) =>
            {
                return Kernel.CreateBuilder()
                             .AddOpenAIChatCompletion(
                                 modelId: opts.ModelId!,
                                 new OpenAIClient(
                                     new ApiKeyCredential(opts.ApiKey),
                                     new OpenAIClientOptions { Endpoint = new Uri(opts.Endpoint) }));
            },

            // Rate Limiting
            RequestsPerSecond = 10,
            RequestsPerMinute = 100,
            RequestsPerDay = 1000,
            TokensPerDay = 10000
        };

        // Register one or more entries under a "sub-pool-1" sub-pool
        // poolId: "sub-pool-1", entryKey: "entry1"
        await kernelPool.Register("sub-pool-1", "entry1", options);

        // You can register additional entries (with different entryKey or options)
        // await kernelPool.Register("sub-pool-1", "entry2", otherOptions);

        await app.RunAsync();
    }
}

Working with Sub-Pools

Each call to Register(...) creates a new “entry” under the specified poolId. Entries are checked out in the order they were added (round-robin), subject to rate limits. You can have multiple sub-pools by choosing different poolId strings:

// Register two separate sub-pools
await kernelPool.Register("reasoning", "o4-mini-high", reasoningOptions);
await kernelPool.Register("high-performance", "4o", highPerformanceOptions);

Retrieving an Available Kernel

public class MyService
{
    private readonly ISemanticKernelPool _kernelPool;

    public MyService(ISemanticKernelPool kernelPool)
    {
        _kernelPool = kernelPool;
    }

    public async Task ProcessAsync()
    {
        // Attempt to get an available kernel from the "my-kernel" sub-pool
        // If no type is provided, defaults to KernelType.Chat
        var (kernel, entry) = await _kernelPool.GetAvailableKernel("my-kernel");

        if (kernel is null || entry is null)
        {
            Console.WriteLine("No available kernel or operation was cancelled.");
            return;
        }

        // Use the kernel as usual
        var chatCompletion = kernel.GetService<IChatCompletionService>();

        var chatHistory = new ChatHistory();
        chatHistory.AddMessage(AuthorRole.User, "What's the capital of France?");

        var response = await chatCompletion.GetChatMessageContentAsync(chatHistory);
        Console.WriteLine($"Response: {response.Content}");

        // Check rate limit usage
        var remaining = await entry.RemainingQuota();
        Console.WriteLine($"Remaining quotas — Second: {remaining.Second}, Minute: {remaining.Minute}, Day: {remaining.Day}");
    }
}

Unregistering and Clearing

  • Remove a single entry from a sub-pool

    bool removed = await kernelPool.Remove("sub-pool-1", "entry1");
    
  • Clear a single sub-pool (removes all entries under that poolId and clears cache for those entries)

    await kernelPool.Clear("sub-pool-1");
    
  • Clear all sub-pools (removes every poolId, all entries, and clears the entire cache)

    await kernelPool.ClearAll();
    
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Soenneker.SemanticKernel.Pool:

Package Downloads
Soenneker.SemanticKernel.Pool.OpenAi

Provides OpenAI-specific registration extensions for KernelPoolManager, enabling integration with local LLMs via Semantic Kernel.

Soenneker.SemanticKernel.Pool.Ollama

Provides Ollama-specific registration extensions for KernelPoolManager, enabling integration with local LLMs via Semantic Kernel.

Soenneker.SemanticKernel.Pool.OpenAi.Azure

Provides Azure OpenAI-specific registration extensions for KernelPoolManager, enabling integration with local LLMs via Semantic Kernel.

Soenneker.SemanticKernel.Pool.Gemini

Provides Gemini-specific registration extensions for KernelPoolManager, enabling integration with local LLMs via Semantic Kernel.

Soenneker.SemanticKernel.Pool.Mistral

Provides Mistral-specific registration extensions for KernelPoolManager, enabling integration via Semantic Kernel.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.147 241 11/12/2025
4.0.146 220 11/11/2025
4.0.145 267 11/11/2025
4.0.144 224 11/11/2025
4.0.143 246 11/11/2025
4.0.142 290 11/10/2025
4.0.141 202 11/7/2025
4.0.140 185 11/7/2025
4.0.139 160 11/7/2025
4.0.138 207 11/7/2025
4.0.137 229 11/7/2025
4.0.136 212 11/6/2025
4.0.135 207 11/6/2025
4.0.134 334 11/4/2025
4.0.133 217 11/4/2025
4.0.132 212 11/4/2025
4.0.131 207 11/4/2025
4.0.130 190 11/4/2025
4.0.129 207 11/3/2025
4.0.128 283 10/30/2025
4.0.127 251 10/30/2025
4.0.126 214 10/30/2025
4.0.125 207 10/30/2025
4.0.124 235 10/30/2025
4.0.123 200 10/29/2025
3.0.122 254 10/29/2025
3.0.121 291 10/24/2025
3.0.120 308 10/16/2025
3.0.119 282 10/16/2025
3.0.118 245 10/15/2025
3.0.117 206 10/15/2025
3.0.116 327 10/9/2025
3.0.115 376 10/8/2025
3.0.114 242 10/8/2025
3.0.113 274 9/30/2025
3.0.112 475 9/16/2025
3.0.111 349 9/16/2025
3.0.110 308 9/11/2025
3.0.109 228 9/10/2025
3.0.108 293 9/9/2025
3.0.107 197 9/9/2025
3.0.106 209 9/9/2025
3.0.105 178 9/9/2025
3.0.104 211 9/9/2025
3.0.103 364 9/5/2025
3.0.102 259 9/4/2025
3.0.101 302 9/4/2025
3.0.100 210 9/3/2025
3.0.99 238 9/3/2025
3.0.98 248 9/3/2025
3.0.97 183 9/3/2025
3.0.96 249 9/3/2025
3.0.95 176 9/3/2025
3.0.94 359 8/28/2025
3.0.93 248 8/27/2025
3.0.92 271 8/20/2025
3.0.91 238 8/17/2025
3.0.90 322 8/15/2025
3.0.89 265 8/14/2025
3.0.88 243 8/13/2025
3.0.87 300 8/12/2025
3.0.86 248 8/12/2025
3.0.85 167 8/12/2025
3.0.84 257 8/11/2025
3.0.83 174 8/11/2025
3.0.82 279 8/11/2025
3.0.81 161 8/11/2025
3.0.80 406 8/11/2025
3.0.79 179 8/11/2025
3.0.78 423 8/6/2025
3.0.77 346 8/5/2025
3.0.76 252 8/5/2025
3.0.75 334 8/5/2025
3.0.74 394 8/5/2025
3.0.73 233 7/30/2025
3.0.72 150 7/30/2025
3.0.71 548 7/25/2025
3.0.70 527 7/24/2025
3.0.69 415 7/9/2025
3.0.68 234 7/9/2025
3.0.67 207 7/9/2025
3.0.66 165 7/9/2025
3.0.65 223 7/9/2025
3.0.64 228 7/8/2025
3.0.63 473 7/4/2025
3.0.62 356 7/2/2025
3.0.61 355 6/28/2025
3.0.60 136 6/28/2025
3.0.59 202 6/28/2025
3.0.58 220 6/28/2025
3.0.57 115 6/27/2025
3.0.56 161 6/27/2025
3.0.55 284 6/26/2025
3.0.54 244 6/25/2025
3.0.53 251 6/25/2025
3.0.52 229 6/25/2025
3.0.51 397 6/17/2025
3.0.50 424 6/11/2025
3.0.49 392 6/11/2025
3.0.48 399 6/11/2025
3.0.47 446 6/11/2025
3.0.46 382 6/11/2025
3.0.45 424 6/10/2025
3.0.44 411 6/3/2025
3.0.43 251 6/3/2025
3.0.42 247 6/3/2025
3.0.41 210 6/3/2025
3.0.40 218 6/3/2025
3.0.39 218 6/3/2025
3.0.38 251 6/3/2025
3.0.37 229 6/2/2025
3.0.36 327 5/28/2025
3.0.35 260 5/28/2025
3.0.34 266 5/28/2025
3.0.33 199 5/28/2025
3.0.32 269 5/27/2025
3.0.31 236 5/27/2025
3.0.30 185 5/27/2025
3.0.29 310 5/27/2025
3.0.28 288 5/26/2025
3.0.27 186 5/25/2025
3.0.26 175 5/25/2025
3.0.25 158 5/23/2025
3.0.24 187 5/23/2025
3.0.23 172 5/23/2025
3.0.22 164 5/23/2025
3.0.21 176 5/23/2025
3.0.20 203 5/23/2025
3.0.19 195 5/22/2025
3.0.18 181 5/22/2025
3.0.17 472 5/22/2025
3.0.16 206 5/21/2025
3.0.15 265 5/20/2025
3.0.14 242 5/19/2025
3.0.13 220 5/19/2025
3.0.12 176 5/19/2025
3.0.11 180 5/19/2025
3.0.10 215 5/19/2025
3.0.9 184 5/19/2025
3.0.8 281 5/19/2025
3.0.7 177 5/18/2025
3.0.6 192 5/18/2025
3.0.5 187 5/18/2025
3.0.4 176 5/18/2025
3.0.3 169 5/18/2025
3.0.2 169 5/18/2025
3.0.1 174 5/18/2025