// Copyright (c) Microsoft. All rights reserved. using System; using System.Collections.Generic; using System.Text.Json; using Microsoft.Agents.AI.Compaction; using Microsoft.Extensions.AI; namespace Microsoft.Agents.AI; /// /// Represents configuration options for . /// public sealed class InMemoryChatHistoryProviderOptions { /// /// Gets or sets an optional delegate that initializes the provider state on the first invocation. /// If , a default initializer that creates an empty state will be used. /// public Func? StateInitializer { get; set; } /// /// Gets or sets an optional instance used to process, reduce, or optimize chat messages. /// This can be used to implement strategies like message summarization, truncation, or cleanup. /// public IChatReducer? ChatReducer { get; set; } /// /// Gets or sets when the message reducer should be invoked. /// The default is , /// which applies reduction logic when messages are retrieved for agent consumption. /// /// /// Message reducers enable automatic management of message storage by implementing strategies to /// keep memory usage under control while preserving important conversation context. /// public ChatReducerTriggerEvent ReducerTriggerEvent { get; set; } = ChatReducerTriggerEvent.BeforeMessagesRetrieval; /// /// Gets or sets an optional key to use for storing the state in the . /// If , a default key will be used. /// public string? StateKey { get; set; } /// /// Gets or sets optional JSON serializer options for serializing the state of this provider. /// This is valuable for cases like when the chat history contains custom types /// and source generated serializers are required, or Native AOT / Trimming is required. /// public JsonSerializerOptions? JsonSerializerOptions { get; set; } /// /// Gets or sets an optional filter function applied to request messages before they are added to storage /// during . /// /// /// When , the provider defaults to excluding messages with /// source type to avoid /// storing messages that came from chat history in the first place. /// Depending on your requirements, you could provide a different filter, that also excludes /// messages from e.g. AI context providers. /// public Func, IEnumerable>? StorageInputMessageFilter { get; set; } /// /// Gets or sets an optional filter function applied to messages produced by this provider /// during . /// /// /// This filter is only applied to the messages that the provider itself produces (from its internal storage). /// /// /// When , no filtering is applied to the output messages. /// public Func, IEnumerable>? ProvideOutputMessageFilter { get; set; } /// /// Defines the events that can trigger a reducer in the . /// public enum ChatReducerTriggerEvent { /// /// Trigger the reducer when a new message is added. /// will only complete when reducer processing is done. /// AfterMessageAdded, /// /// Trigger the reducer before messages are retrieved from the provider. /// The reducer will process the messages before they are returned to the caller. /// BeforeMessagesRetrieval } }