-
-
Notifications
You must be signed in to change notification settings - Fork 172
[Agent] Add history compression strategies #1549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
chr-hertel
commented
Feb 4, 2026
| Q | A |
|---|---|
| Bug fix? | no |
| New feature? | yes |
| Docs? | no |
| Issues | |
| License | MIT |
2a0f916 to
4127d74
Compare
OskarStark
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hot 🔥
|
Lets see if Copilot is complaining about sth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds history compression strategies to the Agent component to manage conversation length automatically. The feature helps control token costs and prevents exceeding context limits in long-running conversational agents.
Changes:
- Introduces a compression infrastructure with
CompressionStrategyInterface,HistoryCompressionInputProcessor, and lifecycle events (BeforeHistoryCompression,AfterHistoryCompression) - Implements three compression strategies:
SlidingWindowStrategy(keeps recent messages),SummarizationStrategy(uses LLM to summarize), andHybridStrategy(combines multiple strategies) - Adds bundle configuration support through a new
compressionoption for agents - Includes comprehensive documentation for both component and bundle usage
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/agent/src/Compression/CompressionStrategyInterface.php | Core interface defining the compression contract |
| src/agent/src/Compression/HistoryCompressionInputProcessor.php | Input processor that applies compression strategies |
| src/agent/src/Compression/BeforeHistoryCompression.php | Event dispatched before compression with skip capability |
| src/agent/src/Compression/AfterHistoryCompression.php | Event dispatched after compression with modification capability |
| src/agent/src/Compression/SlidingWindowStrategy.php | Simple strategy keeping only recent messages |
| src/agent/src/Compression/SummarizationStrategy.php | LLM-based strategy that summarizes old messages |
| src/agent/src/Compression/HybridStrategy.php | Progressive strategy combining primary and secondary approaches |
| src/ai-bundle/src/AiBundle.php | Bundle integration creating compression processor from config |
| src/ai-bundle/config/options.php | Configuration schema for compression option |
| src/ai-bundle/tests/DependencyInjection/AiBundleTest.php | Tests for compression configuration in the bundle |
| src/agent/tests/Compression/* | Test coverage for input processor, events, and strategies |
| docs/components/agent.rst | Component documentation covering compression usage and strategies |
| docs/bundles/ai-bundle.rst | Bundle documentation for compression configuration |
| src/agent/CHANGELOG.md | Documents new compression feature in agent component |
| src/ai-bundle/CHANGELOG.md | Documents new compression configuration option |
| return $messages; | ||
| } | ||
|
|
||
| $conversationText = $this->formatConversation($toSummarize); |
Copilot
AI
Feb 4, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compress method does not handle the case where formatConversation returns an empty string. If all messages to be summarized have no extractable text (e.g., messages with only null or empty content), generateSummary will still be called with an empty or nearly empty conversation text, resulting in an unnecessary API call. Consider adding a check after line 93 to return the original messages if the conversationText is empty or only whitespace.
| $conversationText = $this->formatConversation($toSummarize); | |
| $conversationText = $this->formatConversation($toSummarize); | |
| if ('' === \trim($conversationText)) { | |
| return $messages; | |
| } |
fcd6194 to
3e246cf
Compare
|
rebase unlocked |
3e246cf to
39bf824
Compare
| * | ||
| * @author Christopher Hertel <mail@christopher-hertel.de> | ||
| */ | ||
| interface CompressionStrategyInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface seems more generic than it's name would suggest, it's more like MessageBagTransformer.
Reason I'm saying this is that there could be use cases other than compression for using this, especially around filtering/adding more messages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One use case might be to remove certain types of messages that are not supported by other models/agents during hand-off/fork.