Skip to content

Python: Bug: Python 1.34.0 ChatHistoryTruncationReducer deletes the System Prompt #12612

Closed

Description

@imperonas

Describe the bug
When using the ChatHistoryTruncationReducer the reducer reduces the system prompt (both if added to the constructor via system_message or when manually added as first message to the history )

To Reproduce
Steps to reproduce the behavior:

  1. Create a History using the ChatHistoryTruncationReducer, and add a target_count
  2. populate the ChatHistory with more elements than the target_count
  3. call the reduce function

Expected behavior
I expect the System Prompt to be kept, as it is an integral part of the conversation

Screenshots
see first comment.

Platform

  • Language: Python
  • Source: pip semantic-kernel 1.34.0
  • AI model: OpenAI:GPT-4o-mini(2024-12-01-preview)
  • IDE: VS Code
  • OS: Windows

Additional context
Nothing, but additional context can be provided if needed.

Activity

  1. added theissue type on Jun 27, 2025
  2. changed the title [-]Bug: Python 1.34.0 ChatHistoryTruncationReducer deletes the System Prompt[/-] [+]Python: Bug: Python 1.34.0 ChatHistoryTruncationReducer deletes the System Prompt[/+] on Jun 27, 2025
  3. imperonas commented on Jun 27, 2025

    @imperonas
    Author

    here is an example

    import asyncio
    
    from semantic_kernel.contents import AuthorRole, ChatMessageContent
    from semantic_kernel.contents.history_reducer.chat_history_truncation_reducer import (
        ChatHistoryTruncationReducer,
    )
    
    
    async def test():
    
        history = ChatHistoryTruncationReducer(
            target_count=2, system_message="a system message"
        )
    
        history.add_message(
            ChatMessageContent(role=AuthorRole.USER, content="user prompt 1")
        )
        history.add_message(
            ChatMessageContent(role=AuthorRole.ASSISTANT, content="response 1")
        )
        history.add_message(
            ChatMessageContent(role=AuthorRole.USER, content="user prompt 2")
        )
        history.add_message(
            ChatMessageContent(role=AuthorRole.ASSISTANT, content="response 2")
        )
        history.add_message(
            ChatMessageContent(role=AuthorRole.USER, content="user prompt 3")
        )
        history.add_message(
            ChatMessageContent(role=AuthorRole.ASSISTANT, content="response 3")
        )
        history.add_message(
            ChatMessageContent(role=AuthorRole.USER, content="user prompt 4")
        )
        history.add_message(
            ChatMessageContent(role=AuthorRole.ASSISTANT, content="response 4")
        )
    
        print(str(history))
    
        print("\n reduce hist \n")
        await history.reduce()
        print(str(history))
    
    
    asyncio.run(test())
    

    and the output:

    <chat_history><message role="system"><text>a system message</text></message><message role="user"><text>user prompt 1</text></message><message role="assistant"><text>response 1</text></message><message role="user"><text>user prompt 2</text></message><message role="assistant"><text>response 2</text></message><message role="user"><text>user prompt 3</text></message><message role="assistant"><text>response 3</text></message><message role="user"><text>user prompt 4</text></message><message role="assistant"><text>response 4</text></message></chat_history>
    
     reduce hist
    
    <chat_history><message role="user"><text>user prompt 4</text></message><message role="assistant"><text>response 4</text></message></chat_history>
    
  4. github-actions commented on Sep 29, 2025

    @github-actions
    Contributor

    This issue is stale because it has been open for 90 days with no activity.

  5. added
    staleIssue is stale because it has been open for a while and has no activity
    on Sep 29, 2025
  6. removed
    staleIssue is stale because it has been open for a while and has no activity
    on Oct 2, 2025
  7. added a commit that references this issue on Mar 19, 2026
    3c1b688
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingpythonPull requests for the Python Semantic Kernel

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions