You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Agents can recognize semantic context boundaries—such as finishing planning or completing work that required a loaded skill—but existing compaction strategies run only according to developer-configured conditions. This change lets an agent request in-run compaction while preserving the existing responsibility split: the agent chooses when to compact, and the configured strategy controls what is removed and how.
The implementation composes with the existing function-calling and compaction pipelines and does not introduce persisted-history mutation.
Description & Review Guide
What are the major changes?
Added AgentTriggeredCompactionStrategy, which wraps one existing strategy and exposes one explicitly registered trigger tool.
Added UnloadSkillsCompactionStrategy and its unload_skill trigger for one skill, multiple skills, or all loaded skills.
Temporarily excludes the trigger group while the inner strategy runs so workload retention counters do not include control-plane context, then restores it by default or excludes it when configured.
Preserves mixed parallel tool batches atomically regardless of trigger position.
Added public exports, focused streaming/non-streaming and strategy tests, and generic plus skill-unloading samples.
What is the impact of these changes?
Applications can expose developer-controlled compaction to an agent without changing the existing CompactionStrategy protocol, Agent tool discovery, sessions, or history providers.
Existing strategies remain unchanged and can be wrapped directly.
What do you want reviewers to focus on?
The trigger-group lifecycle and whether temporarily excluding it gives the expected semantics for existing retention strategies.
Atomic behavior when the trigger appears in a mixed parallel tool batch.
The specialized trigger-tool factory used by skill unloading while retaining a single exposed tool.
This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and the title prefix in sync automatically.
The reason will be displayed to describe this comment to others. Learn more.
MAF Automated Review — Iteration 1
Result: Findings reported Scope: full PR (1 commit(s)): 7004916523b4 Model:gpt-5.6-sol
Overview
The PR composes agent-triggered compaction with the existing grouping and projection pipeline, with strong guards for one-shot consumption, failure restoration, mixed trigger batches, and streaming parity. The skill-unloading strategy also preserves ordinary mixed function-call groups and normalizes selected skill names. Two lifecycle gaps remain: rejected approval results are accepted as successful triggers, and completed non-adjacent trigger groups can be skipped because recency is based on the declaration's first occurrence.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
2 verified findings remained after source verification (2 medium) across 1 file. Details are attached to the affected lines below.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Repeated triggers can displace retained workload context, hosted-search batches can lose unrelated context, and the integration test does not exercise actual compaction.
Two load_skill calls with the same call_id but distinct Content.id values both pass this check when only one has a result. A later unload request can therefore exclude the entire group, including the unresolved call. Correlate terminal results per occurrence, retain any group with unresolved calls, and add a partial-completion regression test.
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
documentationUsage: [Issues, PRs], Target: documentation in the code base and learn docspythonUsage: [Issues, PRs], Target: Python
3 participants
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
Agents can recognize semantic context boundaries—such as finishing planning or completing work that required a loaded skill—but existing compaction strategies run only according to developer-configured conditions. This change lets an agent request in-run compaction while preserving the existing responsibility split: the agent chooses when to compact, and the configured strategy controls what is removed and how.
The implementation composes with the existing function-calling and compaction pipelines and does not introduce persisted-history mutation.
Description & Review Guide
AgentTriggeredCompactionStrategy, which wraps one existing strategy and exposes one explicitly registered trigger tool.UnloadSkillsCompactionStrategyand itsunload_skilltrigger for one skill, multiple skills, or all loaded skills.CompactionStrategyprotocol, Agent tool discovery, sessions, or history providers.Related Issue
Fixes #9381
Part of #9379
AI Assistance
AI assistance details: GitHub Copilot assisted with the design, Python implementation, tests, samples, and this pull request description.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and the title prefix in sync automatically.