microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
21.8k stars 3.24k forks source link

.Net: Is IKernel meant to be mutable or immutable? #3187

Closed stephentoub closed 11 months ago

stephentoub commented 1 year ago

IKernel is mostly immutable, except for exposing RegisterCustomFunction (which ImportFunctions uses) and the FunctionInvoking/FunctionInvoked events.

Is the intent for IKernel to be mutable or immutable?

If the intent is for it to be immutable, then these members need to be removed. RegisterCustomFunction just delegates to FunctionCollection.AddFunction, so its functionality exists elsewhere already (though it appears some higher-level helpers expect to be able to be passed an IKernel and store into it... should they instead be extensions on KernelBuilder?) And the events could be changed to be delegates passed to RunAsync.

If the intent is indeed for it to be mutable, then I don't understand the combination of FunctionsCollection wrapping a ConcurrentDictionary<> (instead of a Dictionary<>) and the FunctionInvoking/FunctionInvoked events living on this type. The former suggests that it's intended for an IKernel to be used concurrently by many concurrent executions, but if that's the case, those uses may also be setting and removing handlers from the events, in which case the events are going to erroneously cross-polinate between concurrent uses.

So... what is the intent here?

matthewbolanos commented 1 year ago

I believe we want to make the kernel immutable. In the triage call, it appears there is a consensus on this approach. @markwallace-microsoft to add additional comments.

stephentoub commented 11 months ago

IKernel is going away.