Method SummarizeConversationAsync
SummarizeConversationAsync(ChatHistory, LM, string, CancellationToken)
Summarizes a conversation into episodic memory entries that capture the key topics, decisions, and outcomes discussed.
public Task<ConversationSummaryResult> SummarizeConversationAsync(ChatHistory chatHistory, LM summarizationModel, string dataSourceIdentifier = "conversation_episodes", CancellationToken cancellationToken = default)
Parameters
chatHistoryChatHistoryThe chat history to summarize. Only User and Assistant messages are included.
summarizationModelLMThe language model used to generate the summary.
dataSourceIdentifierstringThe data source where episodic entries are stored. Default is
"conversation_episodes".cancellationTokenCancellationTokenA token to monitor for cancellation requests.
Returns
- Task<ConversationSummaryResult>
A ConversationSummaryResult describing what was stored.
Examples
Example: Summarizing a session before exit
// At the end of a session
var result = await memory.SummarizeConversationAsync(
executor.ChatHistory, chatModel);
Console.WriteLine($"Stored {result.EntriesCreated} episodic memories.");
foreach (var summary in result.Summaries)
Console.WriteLine($" - {summary}");
memory.Serialize("agent_memory.bin");
Remarks
Call this method at the end of a session (before disposing the conversation or
agent) to preserve a compressed record of the interaction. The resulting entries
are stored as Episodic memory with metadata containing
the conversation_id and message_count.
The LLM is prompted to produce up to MaxConversationSummaries concise summaries, each capturing a distinct topic or outcome from the conversation. Short conversations (fewer than 2 user messages) are skipped.
Exceptions
- ArgumentNullException
Thrown when
chatHistoryorsummarizationModelisnull.