-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
.Net: Python: ChatHistory Reduction #10102
Comments
I've already got this underway for the agent framework based on #7969. Is this something separate? |
We currently have this Blog post https://devblogs.microsoft.com/semantic-kernel/managing-chat-history-for-large-language-models-llms/ which describes how to manage chat history and includes samples for .Net only. The purpose of this task is to extend this to Python also. |
Thank you. Very helpful. |
### 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 😄
@markwallace-microsoft why do we need to re-open? |
@moonbox3 Dmytro has to add learn site documentation and also fix system message handling. I can remove you from the issue as there is nothing for you to do. This is one of the issues with shared issues! |
### Motivation and Context <!-- 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. --> Related: #10102 This PR contains changes to the chat history reducer implementations to avoid redaction of system messages if they exist in chat history. It's important to keep system messages in the chat history so the model can follow initial instructions independently from history redaction. ### 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 😄
The text was updated successfully, but these errors were encountered: