Commit 9e979f8
authored
Python: Improve/Simplify the Assistant Agents (#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 #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- python
- samples
- concepts
- agents
- assistant_agent
- mixed_chat
- openai_assistant
- auto_function_calling
- resources
- getting_started_with_agents
- openai_assistant
- learn_resources/agent_docs
- semantic_kernel/agents
- azure_ai
- bedrock
- channels
- chat_completion
- group_chat
- open_ai
- tests
- samples
- unit
- agents
- chat_completion
- openai_assistant
- test_group_chat_strategies
- test_group_chat
- utils/agent_diagnostics
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| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
12 | 40 | | |
13 | 41 | | |
14 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
15 | 46 | | |
| 47 | + | |
16 | 48 | | |
17 | 49 | | |
18 | 50 | | |
19 | 51 | | |
20 | | - | |
21 | 52 | | |
22 | 53 | | |
23 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| |||
20 | 23 | | |
21 | 24 | | |
22 | 25 | | |
23 | | - | |
24 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
25 | 30 | | |
26 | | - | |
27 | | - | |
28 | | - | |
| 31 | + | |
29 | 32 | | |
30 | 33 | | |
31 | 34 | | |
| |||
This file was deleted.
Lines changed: 0 additions & 112 deletions
This file was deleted.
Lines changed: 0 additions & 87 deletions
This file was deleted.
0 commit comments