Skip to content

Python : Sample for Swarm Agent Approach #10723

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

Closed

Conversation

nmoeller
Copy link
Contributor

@nmoeller nmoeller commented Feb 28, 2025

Motivation and Context

In OpenAI Swarm & Autogen Swarm Agents are able to handoff via Function Calling, rather than using a Prompt in the Selection Strategy. This PR should provide a sample how you can build a Swarm Agent System in Semantic Kernel.

The example implents the sample of Autogen Swarm.

Contribution Checklist

@markwallace-microsoft markwallace-microsoft added the python Pull requests for the Python Semantic Kernel label Feb 28, 2025
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 28, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
semantic_kernel/agents/strategies/selection
   swarm_selection_strategy.py29290%3–71
TOTAL19047240987% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3199 5 💤 0 ❌ 0 🔥 1m 41s ⏱️

@nmoeller
Copy link
Contributor Author

nmoeller commented Feb 28, 2025

Hey,

so this is just a sample how an Agent handoff could be done with Function Calling.
Would you be interested in this integrated in Semantic Kernel Agents ?

I think i could also make a class SwarmAgentChat,SwarmSelectionStrategy in SK.

Just let me know if you would be interested in a more sophisticated implementation or the Sample is enough.

@nmoeller nmoeller marked this pull request as ready for review March 1, 2025 10:00
@nmoeller nmoeller requested a review from a team as a code owner March 1, 2025 10:00
@moonbox3
Copy link
Contributor

Thanks for working on this @nmoeller. It looks like with OpenAI's release today of their Agent SDK, Swarm is no longer going to be maintained. With that said, they introduced the "handoff" feature in the new SDK. We can have some equivalent behavior in SK with something like this. What are your thoughts?

@nmoeller
Copy link
Contributor Author

nmoeller commented Mar 12, 2025

@moonbox3 Thanks for looking into this. Let's probably first discuss if my sample still makes sense compared to the one @sphenry provided. What i wanted to show in my sample is how to handover with KernelFunction / function_calling , I think this is definitely included in the sample aswell.

I have two thoughts on this :

  1. If providing the history as parameter for the function does the LLM determines the history or is the History injected via the KernelArguments ? I think from a performance perspective maybe it's not good to have this parameter determined by the language model.

  2. The sample doesn't do multiple handoffs in a single Iteration, this can also be implemented with the strategy he's chosen but i think this would be easier with using a AgentGroupChat. But the advantage here is definitely it is more readable than mine and does not need so much pre-knowledge of SK.

Conclusion :
From my perspective i think both samples make sense in the repo, One with more autonomy the other one with less autonomy. But we should align the samples.

I would adjust my Sample to be closer to his sample proposing the following changes:

  1. Removing the Swarm naming and just calling it a "handoff pattern via KernelFunctions with Agents"
  2. I would refactor my code to be closer to his Handoff Plugin

What do you think ?

If you think it does not make sense we can also close this PR.

@nmoeller nmoeller closed this Mar 25, 2025
@nmoeller nmoeller reopened this Mar 25, 2025
@nmoeller
Copy link
Contributor Author

I will close this due to #11184 , which brings a similar approach, if this is still needed feel free to ping me, then i will reopen.

@nmoeller nmoeller closed this Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python Pull requests for the Python Semantic Kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants