Kernel handling in mulit chat/service solution #8104
-
I am currently working on a multi chat/service solution with the Semantic Kernel and I wonder what is the best practice to handle the Kernel in such a scenario. As each chat could have its own unique configuation should the Kernel be used as singleton or a new instance for each chat? Here an (very simplified) example: var kernel = new KernelBuilder().Build();
var chat1 = kernel.GetRequiredService<IChatCompletionService>();
kernel.ImportPluginFromObject("abc");
var chat1Response = chat1.GetChatMessageContentsAsync(..., kernel);
var chat2 = kernel.GetRequiredService<IChatCompletionService>();
kernel.ImportPluginFromObject("def");
var chat2Response = chat2.GetChatMessageContentsAsync(..., kernel); In this example I would guess that in a mutli chat scenario I should create a new |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@akordowski I think you can create a new |
Beta Was this translation helpful? Give feedback.
@akordowski I think you can create a new
Kernel
instance for each chat and configure it respectively. We haveAddKernel
extension method forIServiceCollection
, where we register it as Transient for exactly the same purpose, so in different places in your application you can configure your Kernel in unique way by adding different set of plugins, filters, data etc:semantic-kernel/dotnet/src/SemanticKernel.Abstractions/Services/KernelServiceCollectionExtensions.cs
Lines 22 to 29 in f9247da