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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.SemanticKernel.Extensions.ChatHistories" Version="3.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.SemanticKernel.Extensions.ChatHistories" Version="3.0.7" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.SemanticKernel.Extensions.ChatHistories" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.SemanticKernel.Extensions.ChatHistories --version 3.0.7
                    
#r "nuget: Soenneker.SemanticKernel.Extensions.ChatHistories, 3.0.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.SemanticKernel.Extensions.ChatHistories@3.0.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.SemanticKernel.Extensions.ChatHistories&version=3.0.7
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.SemanticKernel.Extensions.ChatHistories&version=3.0.7
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image 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 structured ILogger 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 a ChatHistory
  • CopyTo(target): Copy messages to another history
  • WithPrependedSystemMessage(string): Insert a system prompt at the beginning
  • InsertSystemMessageAfterExistingSystemMessages(string): Add prompt after all existing system messages
  • RemoveSystemMessages(): Filter out system-only messages

🔐 Logging Helpers

  • AddSystemMessageLogged(...)
  • AddUserMessageLogged(...)
  • AddAssistantMessageLogged(...)
  • AddDeveloperMessageLogged(...)

All logging helpers support ILogger and LogLevel.

... and more

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.7 167 7/8/2025
3.0.6 280 7/2/2025
3.0.5 239 6/26/2025
3.0.4 221 6/20/2025
3.0.3 132 6/20/2025
3.0.2 177 6/17/2025
3.0.1 307 6/12/2025