Skip to content

Commit 9e979f8

Browse files
authored
Python: Improve/Simplify the Assistant Agents (microsoft#10666)
### Motivation and Context The current abstractions we have around the Semantic Kernel Assistant Agents are considered to be "fully-wrapped." This is beneficial in that SK provides a tight/complete abstraction over the agent; however, it doesn't scale well when new features are added to the underlying APIs (OpenAI) - it requires updates from SK to make each and every update. It also adds a lot more complexity in terms of needing to handle everything in SK, requires more code coverage, and chances for bugs to surface due to these complexities. > **NOTE:** this update is _breaking_. We're moving to simplify the abstractions/APIs before we move Assistant Agents from **experimental** to GA. Similar to how the `AzureAIAgent` was created, we're moving to a "less-wrapped" abstraction around the OpenAI Assistant v2 APIs. We do have some "convenience methods" on the Agents, via class methods, to configure things like the code interpreter tool and resource, file search tool and resource, the clients required to interact with the Assistants, as well as being able to easily configure structured outputs, similar to how it is done with a ChatCompletion (either provide the Pydantic model or the Python class). To work with Assistant Agents now, it's as simple as: ```python from semantic_kernel.agents.open_ai import AzureAssistantAgent from semantic_kernel.functions import kernel_function class MenuPlugin: # Plugin code here using the @kernel_function decorator # Create the client using Azure OpenAI resources and configuration client, model = AzureAssistantAgent.setup_resources() # Create the assistant definition definition = await client.beta.assistants.create( model=model, instructions="Answer questions about the menu.", name="Host", ) agent = AzureAssistantAgent( client=client, definition=definition, plugins=[MenuPlugin()], # The plugins can be passed in as a list to the constructor ) # Note: plugins can also be configured on the Kernel and passed in as a parameter to the OpenAIAssistantAgent # Define a thread and invoke the agent with the user input thread = await agent.client.beta.threads.create() ``` **I will create a migration guide (issue) showing what needs to be updated from the previous usage to this new pattern.** <!-- 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 This PR provides the new abstractions for the `AzureAssistantAgent`/`OpenAIAssistantAgent` classes. - Updates underlying code - Updates samples showing new patterns - Updates unit tests - Updates READMEs. - Closes microsoft#10605 Samples will be updated accordingly to show new patterns. <!-- 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: --> - [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 - [ ] I didn't break anyone 😄
1 parent 583db49 commit 9e979f8

File tree

79 files changed

+4947
-6874
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+4947
-6874
lines changed

python/samples/concepts/README.md

+38-7
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,51 @@
44

55
### Agents - Creating and using [agents](../../semantic_kernel/agents/) in Semantic Kernel
66

7-
- [Assistant Agent Chart Maker](./agents/assistant_agent/assistant_agent_chart_maker.py)
8-
- [Assistant Agent File Manipulation](./agents/assistant_agent/assistant_agent_file_manipulation.py)
9-
- [Assistant Agent File Manipulation Streaming](./agents/assistant_agent/assistant_agent_file_manipulation_streaming.py)
10-
- [Assistant Agent Retrieval](./agents/assistant_agent/assistant_agent_retrieval.py)
11-
- [Assistant Agent Streaming](./agents/assistant_agent/assistant_agent_streaming.py)
7+
#### [OpenAI Assistant Agent](../../semantic_kernel/agents/open_ai/open_ai_assistant_agent.py)
8+
9+
- [OpenAI Assistant Chart Maker Streaming](./agents/openai_assistant/openai_assistant_chart_maker_streaming.py)
10+
- [OpenAI Assistant Chart Maker](./agents/openai_assistant/openai_assistant_chart_maker.py)
11+
- [OpenAI Assistant File Manipulation Streaming](./agents/openai_assistant/openai_assistant_file_manipulation_streaming.py)
12+
- [OpenAI Assistant File Manipulation](./agents/openai_assistant/openai_assistant_file_manipulation.py)
13+
- [OpenAI Assistant File Manipulation Streaming](./agents/openai_assistant/openai_assistant_file_manipulation_streaming.py)
14+
- [OpenAI Assistant Retrieval](./agents/openai_assistant/openai_assistant_retrieval.py)
15+
- [OpenAI Assistant Streaming](./agents/openai_assistant/openai_assistant_streaming.py)
16+
- [OpenAI Assistant Structured Outputs](./agents/openai_assistant/openai_assistant_structured_outputs.py)
17+
- [OpenAI Assistant Templating Streaming](./agents/openai_assistant/openai_assistant_templating_streaming.py)
18+
- [OpenAI Assistant Vision Streaming](./agents/openai_assistant/openai_assistant_vision_streaming.py)
19+
20+
#### [Azure AI Agent](../../semantic_kernel/agents/azure_ai/azure_ai_agent.py)
21+
22+
- [Azure AI Agent with Azure AI Search](./agents/azure_ai_agent/azure_ai_agent_azure_ai_search.py)
23+
- [Azure AI Agent File Manipulation](./agents/azure_ai_agent/azure_ai_agent_file_manipulation.py)
24+
- [Azure AI Agent Streaming](./agents/azure_ai_agent/azure_ai_agent_streaming.py)
25+
26+
#### [Bedrock Agent](../../semantic_kernel/agents/bedrock/bedrock_agent.py)
27+
- [Bedrock Agent Simple Chat Streaming](./agents/bedrock_agent/bedrock_agent_simple_chat_streaming.py)
28+
- [Bedrock Agent Simple Chat](./agents/bedrock_agent/bedrock_agent_simple_chat.py)
29+
- [Bedrock Agent Update Agent](./agents/bedrock_agent/bedrock_agent_update_agent.py)
30+
- [Bedrock Agent Use Existing](./agents/bedrock_agent/bedrock_agent_use_existing.py)
31+
- [Bedrock Agent With Code Interpreter Streaming](./agents/bedrock_agent/bedrock_agent_with_code_interpreter_streaming.py)
32+
- [Bedrock Agent With Code Interpreter](./agents/bedrock_agent/bedrock_agent_with_code_interpreter.py)
33+
- [Bedrock Agent With Kernel Function Streaming](./agents/bedrock_agent/bedrock_agent_with_kernel_function_streaming.py)
34+
- [Bedrock Agent With Kernel Function](./agents/bedrock_agent/bedrock_agent_with_kernel_function.py)
35+
- [Bedrock Agent Mixed Chat Agents Streaming](./agents/bedrock_agent/bedrock_mixed_chat_agents_streaming.py)
36+
- [Bedrock Agent Mixed Chat Agents](./agents/bedrock_agent/bedrock_mixed_chat_agents.py)
37+
38+
#### [Chat Completion Agent](../../semantic_kernel/agents/chat_completion/chat_completion_agent.py)
39+
1240
- [Chat Completion Function Termination](./agents/chat_completion_agent/chat_completion_function_termination.py)
1341
- [Chat Completion History Reducer](./agents/chat_completion_agent/chat_completion_history_reducer.py)
14-
- [Mixed Chat Agents](./agents/mixed_chat/mixed_chat_agents.py)
42+
- [Chat Completion Templating](./agents/chat_completion_agent/chat_completion_templating.py)
43+
44+
#### [Mixed Agent Group Chat](../../semantic_kernel/agents/group_chat/agent_group_chat.py)
45+
1546
- [Mixed Chat Agents Plugins](./agents/mixed_chat/mixed_chat_agents_plugins.py)
47+
- [Mixed Chat Agents](./agents/mixed_chat/mixed_chat_agents.py)
1648
- [Mixed Chat Files](./agents/mixed_chat/mixed_chat_files.py)
1749
- [Mixed Chat Images](./agents/mixed_chat/mixed_chat_images.py)
1850
- [Mixed Chat Reset](./agents/mixed_chat/mixed_chat_reset.py)
1951
- [Mixed Chat Streaming](./agents/mixed_chat/mixed_chat_streaming.py)
20-
- [Bedrock Agent](./agents/bedrock_agent/README.md)
2152

2253
### Audio - Using services that support audio-to-text and text-to-audio conversion
2354

python/samples/concepts/agents/README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ This project contains a step by step guide to get started with _Semantic Kernel
77
- For the use of Chat Completion agents, the minimum allowed Semantic Kernel pypi version is 1.3.0.
88
- For the use of OpenAI Assistant agents, the minimum allowed Semantic Kernel pypi version is 1.4.0.
99
- For the use of Agent Group Chat, the minimum allowed Semantic kernel pypi version is 1.6.0.
10-
- For the use of Streaming OpenAI Assistant agents, the minimum allowed Semantic Kernel pypi version is 1.11.0
10+
- For the use of Streaming OpenAI Assistant agents, the minimum allowed Semantic Kernel pypi version is 1.11.0.
11+
- For the use of AzureAI and Bedrock agents, the minimum allowed Semantic Kernel pypi version is 1.21.0.
12+
- For the use of Crew.AI as a plugin, the minimum allowed Semantic Kernel pypi version is 1.21.1.
13+
1114

1215
## Source
1316

@@ -20,12 +23,12 @@ The concept agents examples are grouped by prefix:
2023
Prefix|Description
2124
---|---
2225
assistant|How to use agents based on the [Open AI Assistant API](https://platform.openai.com/docs/assistants).
23-
chat_completion|How to use Semantic Kernel Chat Completion agents.
24-
bedrock|How to use AWS Bedrock agents in Semantic Kernel.
26+
autogen_conversable_agent| How to use [AutoGen 0.2 Conversable Agents](https://microsoft.github.io/autogen/0.2/docs/Getting-Started) within Semantic Kernel.
27+
azure_ai_agent|How to use an [Azure AI Agent](https://learn.microsoft.com/en-us/azure/ai-services/agents/quickstart?pivots=programming-language-python-azure) within Semantic Kernel.
28+
chat_completion_agent|How to use Semantic Kernel Chat Completion agents that leverage AI Connector Chat Completion APIs.
29+
bedrock|How to use [AWS Bedrock agents](https://aws.amazon.com/bedrock/agents/) in Semantic Kernel.
2530
mixed_chat|How to combine different agent types.
26-
complex_chat|**Coming Soon**
27-
28-
_Note: As we strive for parity with .NET, more getting_started_with_agent samples will be added. The current steps and names may be revised to further align with our .NET counterpart._
31+
openai_assistant|How to use [OpenAI Assistants](https://platform.openai.com/docs/assistants/overview) in Semantic Kernel.
2932

3033
## Configuring the Kernel
3134

python/samples/concepts/agents/assistant_agent/README.md

-19
This file was deleted.

python/samples/concepts/agents/assistant_agent/assistant_agent_chart_maker.py

-112
This file was deleted.

python/samples/concepts/agents/assistant_agent/assistant_agent_file_manipulation.py

-87
This file was deleted.

0 commit comments

Comments
 (0)