microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
22.12k stars 3.3k forks source link

Python Agents: ChatHistoryReducer #7969

Open crickman opened 3 months ago

crickman commented 3 months ago

Replicate reducer feature implemented for .NET here: https://github.com/microsoft/semantic-kernel/pull/7570

public interface IChatHistoryReducer
{
    /// <summary>
    /// Each reducer shall override equality evaluation so that different reducers
    /// of the same configuration can be evaluated for equivalency.
    /// </summary>
    bool Equals(object? obj);

    /// <summary>
    /// Each reducer shall implement custom hash-code generation so that different reducers
    /// of the same configuration can be evaluated for equivalency.
    /// </summary>
    int GetHashCode();

    /// <summary>
    /// Optionally reduces the chat history.
    /// </summary>
    /// <param name="history">The source history (which may have been previously reduced)</param>
    /// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
    /// <returns>The reduced history, or 'null' if no reduction has occurred</returns>
    Task<IEnumerable<ChatMessageContent>?> ReduceAsync(IReadOnlyList<ChatMessageContent> history, CancellationToken cancellationToken = default);
}

With implementations:

  1. ChatHistoryTruncationReducer
  2. ChatHistorySummarizationReducer

Utilize within ChatHistoryChannel with utility extension for "no-chat" case

Note: May want to give the .NET feature a couple weeks bake time (for customer feedback)

github-actions[bot] commented 1 week ago

This issue is stale because it has been open for 90 days with no activity.