Skip to content

Python: honor reducer auto-reduce in chat completion threads#14017

Open
pragnyanramtha wants to merge 1 commit into
microsoft:mainfrom
pragnyanramtha:pragnyan/python-agent-thread-auto-reduce-12303
Open

Python: honor reducer auto-reduce in chat completion threads#14017
pragnyanramtha wants to merge 1 commit into
microsoft:mainfrom
pragnyanramtha:pragnyan/python-agent-thread-auto-reduce-12303

Conversation

@pragnyanramtha
Copy link
Copy Markdown

Motivation and Context

Fixes #12303.

ChatHistoryAgentThread can be initialized with a ChatHistoryReducer, but new thread messages were appended with add_message(). That bypasses reducer add_message_async() behavior, so reducers configured with auto_reduce=True do not reduce history as messages are added through the agent thread.

Description

  • call add_message_async() when the thread history is a ChatHistoryReducer
  • keep the existing synchronous append path for plain ChatHistory
  • add a regression test proving a truncation reducer with auto_reduce=True reduces newly added thread messages

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the SK Contribution Guidelines
  • The code follows the .NET coding conventions and Python coding conventions
  • All unit tests pass, and I have added new tests where possible
  • I didn't break anyone 😄

Validation

From python/:

  • uv run --python 3.12 pytest tests/unit/agents/chat_completion/test_chat_completion_agent.py -q -> 24 passed
  • uv run --python 3.12 pytest tests/unit/contents/test_chat_history_truncation_reducer.py tests/unit/agents/chat_completion/test_chat_completion_agent.py -q -> 42 passed
  • uv run ruff check semantic_kernel/agents/chat_completion/chat_completion_agent.py tests/unit/agents/chat_completion/test_chat_completion_agent.py -> passed
  • git diff --check -> passed

Copilot AI review requested due to automatic review settings May 16, 2026 17:01
@pragnyanramtha pragnyanramtha requested a review from a team as a code owner May 16, 2026 17:01
@moonbox3 moonbox3 added the python Pull requests for the Python Semantic Kernel label May 16, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 94% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by pragnyanramtha's agents

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@pragnyanramtha
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: Complete chat history is getting passed to LLM - chat history summarizer is not working

3 participants