SIGN IN SIGN UP

Integrate cutting-edge LLM technology quickly and easily into your apps

0 0 24 C#
Python: Introduce the non-chat, non-streaming OpenAIAssistantAgent, samples, and tests (#7477) ### Motivation and Context To align with SK dotnet and to allow SK Python devs to leverage the OpenAI/Azure OpenAI assistants, this code is a required component for SK Python. <!-- 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 We're introducing the code to build non-chat, non-streaming OpenAIAssistantAgents for both the OpenAI and Azure OpenAI styles. This PR introduces: - The required code to create OpenAI/AzureOpenAI assistants using the v2 library. - Samples showing how to create the agent, and how to use the tool resources like the code interpreter and file search. - Unit test coverage at 100% - Full mypy coverage - Closes #7080 ![image](https://github.com/user-attachments/assets/1c874710-067d-435e-9382-975d3697a16a) One to-do item: - introduce Agent integration tests Note: streaming assistant agent support will come in the next PR. <!-- 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 - [X] I didn't break anyone :smile:
2024-08-01 09:45:06 -04:00
# Copyright (c) Microsoft. All rights reserved.
from semantic_kernel.exceptions.kernel_exceptions import KernelException
class AgentException(KernelException):
"""Base class for all agent exceptions."""
Python: Introduce the non-chat, non-streaming OpenAIAssistantAgent, samples, and tests (#7477) ### Motivation and Context To align with SK dotnet and to allow SK Python devs to leverage the OpenAI/Azure OpenAI assistants, this code is a required component for SK Python. <!-- 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 We're introducing the code to build non-chat, non-streaming OpenAIAssistantAgents for both the OpenAI and Azure OpenAI styles. This PR introduces: - The required code to create OpenAI/AzureOpenAI assistants using the v2 library. - Samples showing how to create the agent, and how to use the tool resources like the code interpreter and file search. - Unit test coverage at 100% - Full mypy coverage - Closes #7080 ![image](https://github.com/user-attachments/assets/1c874710-067d-435e-9382-975d3697a16a) One to-do item: - introduce Agent integration tests Note: streaming assistant agent support will come in the next PR. <!-- 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 - [X] I didn't break anyone :smile:
2024-08-01 09:45:06 -04:00
pass
class AgentFileNotFoundException(AgentException):
"""The requested file was not found."""
Python: Introduce the non-chat, non-streaming OpenAIAssistantAgent, samples, and tests (#7477) ### Motivation and Context To align with SK dotnet and to allow SK Python devs to leverage the OpenAI/Azure OpenAI assistants, this code is a required component for SK Python. <!-- 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 We're introducing the code to build non-chat, non-streaming OpenAIAssistantAgents for both the OpenAI and Azure OpenAI styles. This PR introduces: - The required code to create OpenAI/AzureOpenAI assistants using the v2 library. - Samples showing how to create the agent, and how to use the tool resources like the code interpreter and file search. - Unit test coverage at 100% - Full mypy coverage - Closes #7080 ![image](https://github.com/user-attachments/assets/1c874710-067d-435e-9382-975d3697a16a) One to-do item: - introduce Agent integration tests Note: streaming assistant agent support will come in the next PR. <!-- 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 - [X] I didn't break anyone :smile:
2024-08-01 09:45:06 -04:00
pass
Python: Introduce Agent group chat functionality (#8184) ### Motivation and Context In the next phase of the agent work in Python, we are to introduce the ability to have agents interact with each other. Agent group chat allows developers to create richer and more dynamic agent interactions. <!-- 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 introduces the following: - Agent group chat functionality via an `agent_chat` base class that forms the foundation for group chats. An `agent_group_chat` class extends that underlying functionality and provides an entry point to kick off the group chat either via invoking the chat for the defined agents, or specifying if a provided agent is to join the existing chat. - The required channels for the chat completion agent and assistant agent to properly chat together - Adds more concept samples and getting started with agent samples to enrich the onboarding experiencing for those wanting to see the capability of agents and agent group chat. - Adds unit test for near 100% coverage - Updates some existing imports for agents, which try and make the required import experience more intuitive. - Introduces assistant agent abstractions for working with files and vector stores so we don't directly expose the underlying client types. - Closes #7966 - Closes #7577 <!-- 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 :smile:
2024-08-19 14:04:44 -04:00
class AgentInitializationException(AgentException):
"""An error occurred while initializing the agent."""
Python: Introduce the non-chat, non-streaming OpenAIAssistantAgent, samples, and tests (#7477) ### Motivation and Context To align with SK dotnet and to allow SK Python devs to leverage the OpenAI/Azure OpenAI assistants, this code is a required component for SK Python. <!-- 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 We're introducing the code to build non-chat, non-streaming OpenAIAssistantAgents for both the OpenAI and Azure OpenAI styles. This PR introduces: - The required code to create OpenAI/AzureOpenAI assistants using the v2 library. - Samples showing how to create the agent, and how to use the tool resources like the code interpreter and file search. - Unit test coverage at 100% - Full mypy coverage - Closes #7080 ![image](https://github.com/user-attachments/assets/1c874710-067d-435e-9382-975d3697a16a) One to-do item: - introduce Agent integration tests Note: streaming assistant agent support will come in the next PR. <!-- 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 - [X] I didn't break anyone :smile:
2024-08-01 09:45:06 -04:00
pass
Python: Introduce Agent group chat functionality (#8184) ### Motivation and Context In the next phase of the agent work in Python, we are to introduce the ability to have agents interact with each other. Agent group chat allows developers to create richer and more dynamic agent interactions. <!-- 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 introduces the following: - Agent group chat functionality via an `agent_chat` base class that forms the foundation for group chats. An `agent_group_chat` class extends that underlying functionality and provides an entry point to kick off the group chat either via invoking the chat for the defined agents, or specifying if a provided agent is to join the existing chat. - The required channels for the chat completion agent and assistant agent to properly chat together - Adds more concept samples and getting started with agent samples to enrich the onboarding experiencing for those wanting to see the capability of agents and agent group chat. - Adds unit test for near 100% coverage - Updates some existing imports for agents, which try and make the required import experience more intuitive. - Introduces assistant agent abstractions for working with files and vector stores so we don't directly expose the underlying client types. - Closes #7966 - Closes #7577 <!-- 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 :smile:
2024-08-19 14:04:44 -04:00
class AgentExecutionException(AgentException):
"""An error occurred while executing the agent."""
Python: Introduce the non-chat, non-streaming OpenAIAssistantAgent, samples, and tests (#7477) ### Motivation and Context To align with SK dotnet and to allow SK Python devs to leverage the OpenAI/Azure OpenAI assistants, this code is a required component for SK Python. <!-- 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 We're introducing the code to build non-chat, non-streaming OpenAIAssistantAgents for both the OpenAI and Azure OpenAI styles. This PR introduces: - The required code to create OpenAI/AzureOpenAI assistants using the v2 library. - Samples showing how to create the agent, and how to use the tool resources like the code interpreter and file search. - Unit test coverage at 100% - Full mypy coverage - Closes #7080 ![image](https://github.com/user-attachments/assets/1c874710-067d-435e-9382-975d3697a16a) One to-do item: - introduce Agent integration tests Note: streaming assistant agent support will come in the next PR. <!-- 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 - [X] I didn't break anyone :smile:
2024-08-01 09:45:06 -04:00
pass
Python: Introduce Agent group chat functionality (#8184) ### Motivation and Context In the next phase of the agent work in Python, we are to introduce the ability to have agents interact with each other. Agent group chat allows developers to create richer and more dynamic agent interactions. <!-- 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 introduces the following: - Agent group chat functionality via an `agent_chat` base class that forms the foundation for group chats. An `agent_group_chat` class extends that underlying functionality and provides an entry point to kick off the group chat either via invoking the chat for the defined agents, or specifying if a provided agent is to join the existing chat. - The required channels for the chat completion agent and assistant agent to properly chat together - Adds more concept samples and getting started with agent samples to enrich the onboarding experiencing for those wanting to see the capability of agents and agent group chat. - Adds unit test for near 100% coverage - Updates some existing imports for agents, which try and make the required import experience more intuitive. - Introduces assistant agent abstractions for working with files and vector stores so we don't directly expose the underlying client types. - Closes #7966 - Closes #7577 <!-- 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 :smile:
2024-08-19 14:04:44 -04:00
class AgentInvokeException(AgentException):
"""An error occurred while invoking the agent."""
Python: Introduce the non-chat, non-streaming OpenAIAssistantAgent, samples, and tests (#7477) ### Motivation and Context To align with SK dotnet and to allow SK Python devs to leverage the OpenAI/Azure OpenAI assistants, this code is a required component for SK Python. <!-- 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 We're introducing the code to build non-chat, non-streaming OpenAIAssistantAgents for both the OpenAI and Azure OpenAI styles. This PR introduces: - The required code to create OpenAI/AzureOpenAI assistants using the v2 library. - Samples showing how to create the agent, and how to use the tool resources like the code interpreter and file search. - Unit test coverage at 100% - Full mypy coverage - Closes #7080 ![image](https://github.com/user-attachments/assets/1c874710-067d-435e-9382-975d3697a16a) One to-do item: - introduce Agent integration tests Note: streaming assistant agent support will come in the next PR. <!-- 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 - [X] I didn't break anyone :smile:
2024-08-01 09:45:06 -04:00
pass
Python: Introduce Agent group chat functionality (#8184) ### Motivation and Context In the next phase of the agent work in Python, we are to introduce the ability to have agents interact with each other. Agent group chat allows developers to create richer and more dynamic agent interactions. <!-- 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 introduces the following: - Agent group chat functionality via an `agent_chat` base class that forms the foundation for group chats. An `agent_group_chat` class extends that underlying functionality and provides an entry point to kick off the group chat either via invoking the chat for the defined agents, or specifying if a provided agent is to join the existing chat. - The required channels for the chat completion agent and assistant agent to properly chat together - Adds more concept samples and getting started with agent samples to enrich the onboarding experiencing for those wanting to see the capability of agents and agent group chat. - Adds unit test for near 100% coverage - Updates some existing imports for agents, which try and make the required import experience more intuitive. - Introduces assistant agent abstractions for working with files and vector stores so we don't directly expose the underlying client types. - Closes #7966 - Closes #7577 <!-- 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 :smile:
2024-08-19 14:04:44 -04:00
class AgentChatException(AgentException):
"""An error occurred while invoking the agent chat."""
pass
Python: Introduce the chat history reducer (#10190) ### Motivation and Context The SK Python framework has been missing the ability to configure a chat history reducer of type `ChatHistoryTruncationReducer` and `ChatHistorySummarizationReducer` which have existed in the .Net SK Agent framework for some time. The goal of this PR is to introduce the chat history reducers and allow them for use for not only the agent framework, but also anything else that uses a chat history (chat completion, for example). The ChatHistoryReducer extends the ChatHistory class, and so it's simple to include a reducer and logic to reduce messages as one manages the chat history either in an agent framework setting or in a chat completion setting. <!-- 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: - Introduces the chat history reducer functionality in Python -- both the `ChatHistoryTruncationReducer` and `ChatHistorySummarizationReducer`. - Add unit tests for code coverage. - Adds a sample `Chat Completion History Reducer` to show how to configure both reducers and what each parameter does. - Add chat completion samples showing how to manage a chat history reducer, including how to specify that function call content and function result content should be part of the summarization payload. - Updates the Agent SelectionStrategy, KernelFunctionSelectionStrategy and KernelFunctionTermination strategy to use the reducer. - Additionally updates the classes above to use a new `select_agent` abstract method so that one can define an initial agent to run in a particular scenario. - Removes the deprecated `FunctionCallBehavior` class, and removes some nasty circular dependencies that we had lurking in the code base for some time. This `FunctionCallBehavior` has been marked with a deprecation warning for 6+ months now. All samples and docs have moved over to use `FunctionChoiceBehavior` - developers using `FunctionCallBehavior` should have had enough time to switch. - Closes #7969 - Closes #10102 <!-- 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 - [X] I didn't break anyone :smile:
2025-01-24 07:30:54 +09:00
class AgentChatHistoryReducerException(AgentException):
"""An error occurred while reducing the chat history."""
pass
Python: Introduce the Copilot Studio Agent (#11851) ### Motivation and Context Semantic Kernel Python currently has a demo showing how to interact with a Copilot Studio Agent; however, that uses the `DirectLine API`. This PR introduces a Semantic Kernel `CoilotStudioAgent` that leverages the team's new `microsoft.agents.copilotstudio.client`. One must first have a Copilot Studio Agent created via the portal; and once ready, they can reference it with the proper App Registration and Agent metadata. Interacting with the Agent can leverage Microsoft Copilot Studio's knowledge sources and internal tools. <!-- 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 Add support for the `CopilotStudioAgent`. - Provide getting started samples - Introduces a detailed README on what is required for setup and interacting with the agent. - The current version of the `CopilotStudioAgent` does not support calling another Copilot Studio Agent via a skill. - Authentication for the agent is limited to interactive right now. Once service-to-service auth is support via the client, we will add this into SK. - Closes #11607 <!-- 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 - [X] I didn't break anyone :smile:
2025-05-06 19:29:29 +09:00
class AgentThreadInitializationException(AgentException):
"""An error occurred while initializing the agent thread."""
pass
class AgentThreadOperationException(AgentException):
"""An error occurred while performing an operation on the agent thread."""
pass