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

Author: 00wzCreated Apr 25, 2026Updated Sep 30, 2026
Labels.NETtriagestale

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.

Source: microsoft/semantic-kernel