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

Python: Allow plugins via agent constructors. Update samples. #10707

Merged
merged 19 commits into from
Feb 28, 2025

Conversation

moonbox3
Copy link
Contributor

Motivation and Context

In Semantic Kernel, our goal is to simplify working with agents. When an agent is created without a specified kernel, one is automatically created on the user’s behalf. This enables developers to pass in a list of plugins that are then added to the underlying kernel. If both the agent constructor and the provided kernel include plugins, those specified via the agent constructor take precedence—since plugins are stored in a dictionary, any duplicate names result in the agent’s plugin overwriting the existing one.

For the ChatCompletionAgent, usage is further simplified by allowing a ChatCompletionClientBase service to be passed via the constructor. If a kernel is supplied and already contains a chat completion service, the new service is added to the kernel. Moreover, if no execution settings are provided via KernelArguments, the first service registered on the kernel is used.

New usage to create a ChatCompletionAgent

agent = ChatCompletionAgent(
    service=AzureChatCompletion(),
    name="<name>",
    instructions="<instructions>",
)

New usage to create a ChatCompletionAgent with plugins:

agent = ChatCompletionAgent(
    service=AzureChatCompletion(),
    name="<name>",
    instructions="<instructions>",
    plugins=[SamplePlugin()],
)

Previously, the service_id constructor argument was retained after introducing KernelArguments. However, with our transition to using the kernel’s AI service selector, the service_id parameter has become redundant. As we move from the experimental phase toward a release candidate, removing service_id is a necessary, albeit breaking, change.

The getting_started_with_agents/chat_completion samples now begin by demonstrating the simplest way to configure the agent. The subsequent step illustrates the original method for setting up the chat completion service on the kernel. Similarly, for plugins, the initial approach is the easiest to follow, while the following step shows the traditional method of managing the kernel.

Updated documentation will follow, once these changes are released in a new package.

!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following information:

  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
    -->

Description

Simplifying interactions with agents.

Contribution Checklist

@moonbox3 moonbox3 added python Pull requests for the Python Semantic Kernel PR: breaking change Pull requests that introduce breaking changes agents labels Feb 27, 2025
@moonbox3 moonbox3 requested a review from a team as a code owner February 27, 2025 13:14
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Feb 27, 2025

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
semantic_kernel/agents/autogen
   autogen_conversable_agent.py74791%88, 184–185, 194–197
semantic_kernel/agents/azure_ai
   azure_ai_agent.py1181587%109, 111, 117, 128–133, 135, 137, 158–161, 210, 275, 336
semantic_kernel/agents/bedrock
   bedrock_agent.py2194181%119, 133, 137, 139, 188–201, 267, 291, 308, 341, 360, 376–379, 385, 387, 390, 394, 426, 456–465, 476, 508, 525–526, 528–529, 571, 582–583, 595, 631–642, 653, 670–683
semantic_kernel/agents/channels
   chat_history_channel.py68297%139, 142
semantic_kernel/agents/chat_completion
   chat_completion_agent.py1481093%98, 101, 111, 119–124, 133, 215, 288, 357
semantic_kernel/agents/open_ai
   azure_assistant_agent.py35294%79, 83
   open_ai_assistant_agent.py185697%213, 226, 262, 432, 523, 611
TOTAL19018238087% 

Python Unit Test Overview

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

@moonbox3 moonbox3 added this pull request to the merge queue Feb 28, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 28, 2025
@moonbox3 moonbox3 enabled auto-merge February 28, 2025 01:38
@moonbox3 moonbox3 added this pull request to the merge queue Feb 28, 2025
Merged via the queue into microsoft:main with commit fd27470 Feb 28, 2025
28 checks passed
@moonbox3 moonbox3 deleted the py-dev-qol branch February 28, 2025 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agents documentation PR: breaking change Pull requests that introduce breaking changes python Pull requests for the Python Semantic Kernel
Projects
Status: Sprint: Done
Development

Successfully merging this pull request may close these issues.

Python: ChatCompletionAgent constructor and invocation improvements
5 participants