Python: Ignore excluded tool results during compaction - #7391
Open
dk3yyyy wants to merge 2 commits into
Open
Conversation
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a compaction bug in the Python core where ToolResultCompactionStrategy could re-materialize tool result payloads that were already marked excluded, causing context token usage to grow during compaction. The update ensures generated tool-result summaries are built only from still-included messages while preserving full-group provenance links for traceability.
Changes:
- Build tool-result summary text and call-id→name mappings from included messages only within a selected tool-call group.
- Preserve provenance/backlinks using the full group’s original message IDs (including excluded messages).
- Add a regression test covering excluded-payload restoration, token growth prevention, and bidirectional provenance.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
python/packages/core/agent_framework/_compaction.py |
Filters group messages used to build tool-result digests to avoid summarizing excluded tool results while keeping full-group provenance. |
python/packages/core/tests/core/test_compaction.py |
Adds a regression test ensuring excluded tool results are not restored into the inserted summary and provenance links remain correct. |
5 tasks
Contributor
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
ToolResultCompactionStrategycould summarize messages that had already been marked as excluded when only part of a tool group remained in context. This could restore a large excluded tool result inside the generated summary and increase context token usage instead of reducing it.This change keeps excluded content out of generated summaries while preserving the existing provenance links between each original message and its summary.
Description & Review Guide
Related Issue
Fixes #7387
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.