microsoft / microsoft/semantic-kernel

.Net: Feature: ChatHistoryCompactionReducer — an alternative IChatHistoryReducer that preserves structured history

Open
#13,918 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

.NET triage
Dominant language
C#
Stars
28.6k
Forks
4.8k
Avg merge
14h 13m
Merged PRs (30d)
18

Description


name: ChatHistoryCompactionReducer
about: An alternative IChatHistoryReducer that compacts history into a structured
message list rather than a single free-text summary.


Summary

This is a proposal to add ChatHistoryCompactionReducer, an experimental alternative
implementation of IChatHistoryReducer.

Unlike summarization-based reducers that replace older messages with a single free-text
summary, this reducer asks an LLM to compact the history via a required tool call
(submit_history) and returns a structured list of ChatMessageContent objects.
The LLM decides what to keep, shorten, or remove — but the result remains a typed
message list rather than a plain-text summary. This means function call / result pairs
can be retained in the compacted history when the LLM considers them relevant, avoiding
redundant agent invocations to recover information lost after context reduction.

The reducer is fail-fast: when the model returns structurally invalid output, it throws
rather than attempting silent correction. Known edge cases and their potential fixup
strategies are documented in the README.

The implementation is experimental and not extensively tested. I am sharing it with
the community to get feedback on whether this approach is worth pursuing further.

Implementation (part of a working project):
https://github.com/00wz/DesktopAssistant/tree/main/src/DesktopAssistant.Infrastructure/AI/Summarization

Intent

I am willing to submit a PR with unit tests following SK contribution guidelines.
Happy to discuss the design before proceeding.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed implementation in the linked DesktopAssistant.Infrastructure/AI/Summarization path and the existing IChatHistoryReducer contract in Semantic Kernel. Read the README for documented edge cases, then clarify the design before adding the reducer and unit tests; done means an agreed approach with repository changes and test coverage for structured compaction and fail-fast invalid output.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
ai
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.