-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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: Added IChatHistoryReducer for ChatCompletion with AzureOpenAI and OpenAI #8894
.Net: Added IChatHistoryReducer for ChatCompletion with AzureOpenAI and OpenAI #8894
Conversation
dotnet/src/SemanticKernel.Abstractions/AI/ChatCompletion/ChatHistoryReducerExtensions.cs
Outdated
Show resolved
Hide resolved
Would it make sense to provide both implementations of the reducer in the core framework:
|
dotnet/src/SemanticKernel.Abstractions/AI/ChatCompletion/ChatHistoryReducerExtensions.cs
Show resolved
Hide resolved
Hi @sandrohanea thanks for creating this PR. The team met to discuss and a few things came up
The consensus was that developers have control over the |
Closing this PR as it's not currently aligning with SK plan for abstractions. |
@markwallace-microsoft Can the Reducer implementation in #7570 be moved to Core? I believe it is useful not just for the Agent. |
Motivation and Context
When using Auto-Invocation for Tools with OpenAI and AzureOpenAI, there is no way to intercept and reduce the chat history after tools are being invoked.
This is needed as some tools might return long responses and we might want to execute different prompt compression / optimization based on the tool result.
Note:
AutoFunctionInvocationFilters
cannot be used as they are invoked only before the result of the tools is added to the chat history.The alternative to this approach would be to intercept the http call to Open AI and alter the request directly but that will cause multiple allocation, serializations and deserializations and won't scale to other Connectors.
Description
This change is extracting
IChatHistoryReducer
fromAgents.Core
project and moving it to SK.Abstrations.AI.ChatCompletions.IChatHistoryReducer
was renamed toIAgentChatHistoryReducer
in order to avoid confusion as it requires 2 more methods:Equals
andGetHashCode
that are used to compute the agent channel key. It now inheritsIChatHistoryReducer
.Added tests to ensure that a DI registered reducer is used in the ChatCompletionService of both OpenAI and AzureOpenAI connectors.
Important notice: the reducer is not mutating the
ChatHistory
, as it might be that new tool invocation or chat turns will require different reducing logic. (e.g. context-aware summarization)Contribution Checklist