Skip to content

Conversation

joslat
Copy link
Contributor

@joslat joslat commented Apr 8, 2025

Motivation and Context

  1. Why
  2. Need to write too much code to set an agent as a plugin:
var agentPlugin = KernelPluginFactory.CreateFromFunctions("AgentPlugin",
            [
                AgentKernelFunctionFactory.CreateFromAgent(this.CreateSalesAssistant()),
                AgentKernelFunctionFactory.CreateFromAgent(this.CreateRefundAgent())
            ]);

while in Python:
plugins=[billing_agent, refund_agent],

  1. Scenario
    Making easier and simpler to write agentic code :)

  2. Issue: .NET Agents New Feature: When Adding an agent as a plugin it is too verbose, I want to do it like in Python! #11439

Description

Added the change as an extension method as KernelPluginFactory is in SemanticKernel.Core without any reference to Agents.Core where the method is. Unsure you would like to add a reference to it in the SemanticKernel.Core, but it would be a lot more simpler to implement.

Now, the changes have been applied here:

var agentPlugin = KernelPluginFactory.CreateFromFunctions("AgentPlugin",

So it would look instead of the above code as:

        KernelPlugin agentPlugin = KernelPluginFactoryExtensions.CreateFromFunctions("AgentPlugin",
            [
                this.CreateSalesAssistant(),
                this.CreateRefundAgent()
            ]);

Which is a little less verbose, and more similar to the Python code.

Contribution Checklist

@joslat joslat requested a review from a team as a code owner April 8, 2025 14:05
@markwallace-microsoft markwallace-microsoft added the .NET Issue or Pull requests regarding .NET code label Apr 8, 2025
@github-actions github-actions bot changed the title initial implementation through an extension method .Net: initial implementation through an extension method Apr 8, 2025
@joslat joslat changed the title .Net: initial implementation through an extension method .Net: KernelPluginFactory.CreateFromFunctions - enable direct support for agents through an extension method Apr 8, 2025
@joslat joslat changed the title .Net: KernelPluginFactory.CreateFromFunctions - enable direct support for agents through an extension method .Net: KernelPluginFactory.CreateFromFunctions - enable direct support for agents implicitly Apr 10, 2025
@joslat
Copy link
Contributor Author

joslat commented Apr 16, 2025

@markwallace-microsoft all changes applied 👍

@markwallace-microsoft markwallace-microsoft changed the title .Net: KernelPluginFactory.CreateFromFunctions - enable direct support for agents implicitly .Net: AgentKernelPluginFactory.CreateFromAgents - enable direct support for agents implicitly Apr 17, 2025
@SergeyMenshykh
Copy link
Member

LGTM: having a unit test or a few would be helpful here.

@markwallace-microsoft markwallace-microsoft added this pull request to the merge queue Jul 24, 2025
Merged via the queue into microsoft:main with commit 44418d1 Jul 24, 2025
19 checks passed
jcruzmot-te pushed a commit to thousandeyes/aia-semantic-kernel that referenced this pull request Sep 15, 2025
…rt for agents implicitly (microsoft#11443)

### Motivation and Context
1. Why
- it helps reduce cognitive overload and reduces the code to write, like
in python
   - solves microsoft#11439
2. Need to write too much code to set an agent as a plugin:
```
var agentPlugin = KernelPluginFactory.CreateFromFunctions("AgentPlugin",
            [
                AgentKernelFunctionFactory.CreateFromAgent(this.CreateSalesAssistant()),
                AgentKernelFunctionFactory.CreateFromAgent(this.CreateRefundAgent())
            ]);
```
while in Python:
`plugins=[billing_agent, refund_agent],`

3. Scenario
Making easier and simpler to write agentic code :)

4. Issue: microsoft#11439

### Description
Added the change as an extension method as KernelPluginFactory is in
SemanticKernel.Core without any reference to Agents.Core where the
method is. Unsure you would like to add a reference to it in the
SemanticKernel.Core, but it would be a lot more simpler to implement.

Now, the changes have been applied here:
https://github.com/microsoft/semantic-kernel/blob/0ff97c7fe73c5175df61ae627271341a32983c07/dotnet/samples/GettingStartedWithAgents/Step08_AgentAsKernelFunction.cs#L71

So it would look instead of the above code as:
```
        KernelPlugin agentPlugin = KernelPluginFactoryExtensions.CreateFromFunctions("AgentPlugin",
            [
                this.CreateSalesAssistant(),
                this.CreateRefundAgent()
            ]);
```
Which is a little less verbose, and more similar to the Python code.

### Contribution Checklist

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

- [x ] The code builds clean without any errors or warnings
- [x ] 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
- [ x] All unit tests pass, and I have added new tests where possible
- [x ] I didn't break anyone 😄

---------

Co-authored-by: Chris <[email protected]>
Co-authored-by: Mark Wallace <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Issue or Pull requests regarding .NET code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.Net Agents New Feature: I want the "Agents as plugins" to be able to access the main agent thread - if I want
5 participants