Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Change IKernelPlugin to be abstract class KernelPlugin #4084

Conversation

markwallace-microsoft
Copy link
Member

@markwallace-microsoft markwallace-microsoft commented Dec 7, 2023

Motivation and Context

Changing IKernelPlugin to be abstract class KernelPluginBase so that we have the flexibility to extend that we get from abstract classes.

Description

Contribution Checklist

@markwallace-microsoft markwallace-microsoft requested a review from a team as a code owner December 7, 2023 15:45
@shawncal shawncal added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels Dec 7, 2023
@github-actions github-actions bot changed the title Change IKernelPlugin to be abstract class ReadOnlyKernelPlugin .Net: Change IKernelPlugin to be abstract class ReadOnlyKernelPlugin Dec 7, 2023
@stephentoub
Copy link
Member

What's the reason for this change?

If we want to convert IKernelPlugin to be a base class instead, I'd suggest a few changes:

  • Just have it be called KernelPlugin rather than ReadOnlyKernelPlugin.
  • Change the existing KernelPlugin to be named something more like ComposedKernelPlugin, DynamicKernelPlugin, ManualKernelPlugin, etc. The number of folks that will need to consume / work with the base class is much, much larger than the number of folks that need to manually build up a new KernelPlugin from individual functions, so we should use the "good" name for the base class.
  • Any extension method we currently have in Abstractions (and possibly in Core, depending on what it is) around an IKernelPlugin should move to being an instance member of the base KernelPlugin.

@stephentoub
Copy link
Member

stephentoub commented Dec 7, 2023

Change the existing KernelPlugin to be named something more like ComposedKernelPlugin, DynamicKernelPlugin, ManualKernelPlugin, etc. The number of folks that will need to consume / work with the base class is much, much larger than the number of folks that need to manually build up a new KernelPlugin from individual functions, so we should use the "good" name for the base class.

Actually, the current KernelPlugin (the mutable one) probably doesn't even need to be public. You just have a KernelPluginFactory method that takes a name and an IEnumerable<KernelFunction> and it returns an internal type we can name whatever we want. Then we just use KernelPlugin as the good name for the abstract base class.

@markwallace-microsoft
Copy link
Member Author

What's the reason for this change?
Changing IKernelPlugin to be abstract class ReadOnlyKernelPlugin so that we have the flexibility to extend that we get from abstract classes.

  • Just have it be called KernelPlugin rather than ReadOnlyKernelPlugin.
    OK I will make this change
  • Change the existing KernelPlugin to be named something more like ComposedKernelPlugin, DynamicKernelPlugin, ManualKernelPlugin, etc.
    Need to think about this name.
  • Any extension method we currently have in Abstractions (and possibly in Core, depending on what it is) around an IKernelPlugin should move to being an instance member of the base KernelPlugin.
    Will make this change

@stephentoub
Copy link
Member

Change the existing KernelPlugin to be named something more like ComposedKernelPlugin, DynamicKernelPlugin, ManualKernelPlugin, etc. The number of folks that will need to consume / work with the base class is much, much larger than the number of folks that need to manually build up a new KernelPlugin from individual functions, so we should use the "good" name for the base class.

Actually, the current KernelPlugin (the mutable one) probably doesn't even need to be public. You just have a KernelPluginFactory method that takes a name and an IEnumerable<KernelFunction> and it returns an internal type we can name whatever we want. Then we just use KernelPlugin as the good name for the abstract base class.

I like this for the additional reason that it means b someone can't downcast to the mutable type and start adding functions to some random plugin.

@markwallace-microsoft
Copy link
Member Author

Change the existing KernelPlugin to be named something more like ComposedKernelPlugin, DynamicKernelPlugin, ManualKernelPlugin, etc. The number of folks that will need to consume / work with the base class is much, much larger than the number of folks that need to manually build up a new KernelPlugin from individual functions, so we should use the "good" name for the base class.

Actually, the current KernelPlugin (the mutable one) probably doesn't even need to be public. You just have a KernelPluginFactory method that takes a name and an IEnumerable<KernelFunction> and it returns an internal type we can name whatever we want. Then we just use KernelPlugin as the good name for the abstract base class.

For tooling scenarios we want to allow a developer to add functions to the Plugin. This is what Diego does in his .Net Interactive tool. So if we don't make the implementation that allows this public, do we add extension methods for AddFunction and AddFunctions that only work when the implementation is ours?

@stephentoub
Copy link
Member

stephentoub commented Dec 7, 2023

For tooling scenarios we want to allow a developer to add functions to the Plugin. This is what Diego does in his .Net Interactive tool

I see. Add functions one by one? In that case, yes, someone would need a mutable implementation, though it doesn't necessarily need to be in the core. With most of the functionality in the base class, someone who needs that interactivity could write the class which would be pretty short, right?

@markwallace-microsoft markwallace-microsoft force-pushed the users/markwallace/refactor_ikernelplugin branch from fdfed63 to 43bfcaa Compare December 7, 2023 20:13
@markwallace-microsoft markwallace-microsoft changed the title .Net: Change IKernelPlugin to be abstract class ReadOnlyKernelPlugin .Net: Change IKernelPlugin to be abstract class KernelPluginBase Dec 7, 2023
@stephentoub stephentoub changed the title .Net: Change IKernelPlugin to be abstract class KernelPluginBase .Net: Change IKernelPlugin to be abstract class KernelPlugin Dec 7, 2023
@markwallace-microsoft markwallace-microsoft added this pull request to the merge queue Dec 8, 2023
Merged via the queue into microsoft:main with commit 174aa71 Dec 8, 2023
18 checks passed
@markwallace-microsoft markwallace-microsoft deleted the users/markwallace/refactor_ikernelplugin branch December 8, 2023 14:11
Bryan-Roe pushed a commit to Bryan-Roe/semantic-kernel that referenced this pull request Oct 6, 2024
…ft#4084)

### Motivation and Context

Changing `IKernelPlugin` to be abstract class `KernelPluginBase` so that
we have the flexibility to extend that we get from abstract classes.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [ ] The code builds clean without any errors or warnings
- [ ] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [ ] All unit tests pass, and I have added new tests where possible
- [ ] I didn't break anyone 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants