AgentSessionExtensions.SetInMemoryChatHistory Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Sets the in-memory chat message history for the specified agent session, replacing any existing messages.
public static void SetInMemoryChatHistory(this Microsoft.Agents.AI.AgentSession session, System.Collections.Generic.List<Microsoft.Extensions.AI.ChatMessage> messages, string? stateKey = default, System.Text.Json.JsonSerializerOptions? jsonSerializerOptions = default);
static member SetInMemoryChatHistory : Microsoft.Agents.AI.AgentSession * System.Collections.Generic.List<Microsoft.Extensions.AI.ChatMessage> * string * System.Text.Json.JsonSerializerOptions -> unit
<Extension()>
Public Sub SetInMemoryChatHistory (session As AgentSession, messages As List(Of ChatMessage), Optional stateKey As String = Nothing, Optional jsonSerializerOptions As JsonSerializerOptions = Nothing)
Parameters
- session
- AgentSession
The agent session whose in-memory chat history will be updated.
- messages
- List<ChatMessage>
The list of chat messages to store in memory for the session. Replaces any existing messages for the specified state key.
- stateKey
- String
The key used to identify the in-memory chat history within the session's state bag. If null, a default key is used.
- jsonSerializerOptions
- JsonSerializerOptions
The serializer options used when accessing or storing the state. If null, default options are applied.
Remarks
This method is only applicable when using InMemoryChatHistoryProvider and if the service does not require in-service chat history storage. If messages are set, but a different ChatHistoryProvider is used, or if chat history is stored in the underlying AI service, the messages will be ignored.