Soenneker.SemanticKernel.Extensions.ChatHistories
3.0.7
Prefix Reserved
dotnet add package Soenneker.SemanticKernel.Extensions.ChatHistories --version 3.0.7
NuGet\Install-Package Soenneker.SemanticKernel.Extensions.ChatHistories -Version 3.0.7
<PackageReference Include="Soenneker.SemanticKernel.Extensions.ChatHistories" Version="3.0.7" />
<PackageVersion Include="Soenneker.SemanticKernel.Extensions.ChatHistories" Version="3.0.7" />
<PackageReference Include="Soenneker.SemanticKernel.Extensions.ChatHistories" />
paket add Soenneker.SemanticKernel.Extensions.ChatHistories --version 3.0.7
#r "nuget: Soenneker.SemanticKernel.Extensions.ChatHistories, 3.0.7"
#:package Soenneker.SemanticKernel.Extensions.ChatHistories@3.0.7
#addin nuget:?package=Soenneker.SemanticKernel.Extensions.ChatHistories&version=3.0.7
#tool nuget:?package=Soenneker.SemanticKernel.Extensions.ChatHistories&version=3.0.7
Soenneker.SemanticKernel.Extensions.ChatHistories
A collection of helpful Semantic Kernel ChatHistory
extension methods
This library provides composable and production-grade extension methods for working with Microsoft.SemanticKernel.ChatCompletion.ChatHistory
. It includes utilities for transformation, logging, filtering, restructuring, and role-aware operations—ideal for agent frameworks, prompt engineering, and chat memory management.
🛠️ Installation
dotnet add package Soenneker.SemanticKernel.Extensions.ChatHistories
✨ Features
🧩 Modular utilities to copy, clone, transform, and manipulate chat history
🔍 Logging-aware
Add*MessageLogged(...)
methods with structuredILogger
output🧠 Intelligent system prompt injection:
- At the beginning
- After existing system messages
🧼 Role-based filtering (e.g., remove all system messages)
🧾 Clean composition for creating structured, valid chat histories
📦 Example Usage
var history = new ChatHistory();
history.AddUserMessage("What is the capital of France?");
history.AddAssistantMessage("Paris is the capital of France.");
// Clone the chat history
var clone = history.Clone();
// Prepend a new system message
var withSystem = history.WithPrependedSystemMessage("You are a helpful assistant.");
// Insert system message after existing system messages
var withInsertedSystem = history.InsertSystemMessageAfterExistingSystemMessages("Follow strict format rules only.");
Add messages with logging:
var logger = loggerFactory.CreateLogger("Chat");
history.AddUserMessageLogged("Hello!", logger);
history.AddAssistantMessageLogged("Hi there!", logger);
🧩 API Highlights
💬 Chat History Transformations
Clone()
: Deep copy of aChatHistory
CopyTo(target)
: Copy messages to another historyWithPrependedSystemMessage(string)
: Insert a system prompt at the beginningInsertSystemMessageAfterExistingSystemMessages(string)
: Add prompt after all existing system messagesRemoveSystemMessages()
: Filter out system-only messages
🔐 Logging Helpers
AddSystemMessageLogged(...)
AddUserMessageLogged(...)
AddAssistantMessageLogged(...)
AddDeveloperMessageLogged(...)
All logging helpers support ILogger
and LogLevel
.
... and more
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Microsoft.SemanticKernel.Abstractions (>= 1.60.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.