Skip to content

Conversation

@chr-hertel
Copy link
Member

Q A
Bug fix? no
New feature? yes
Docs? no
Issues
License MIT

@chr-hertel chr-hertel added the Agent Issues & PRs about the AI Agent component label Feb 4, 2026
@chr-hertel chr-hertel force-pushed the feat-compression branch 3 times, most recently from 2a0f916 to 4127d74 Compare February 4, 2026 21:52
Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

Hot 🔥

@OskarStark
Copy link
Contributor

OskarStark commented Feb 4, 2026

Lets see if Copilot is complaining about sth

Copy link

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.

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), and HybridStrategy (combines multiple strategies)
  • Adds bundle configuration support through a new compression option 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);
Copy link

Copilot AI Feb 4, 2026

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.

Suggested change
$conversationText = $this->formatConversation($toSummarize);
$conversationText = $this->formatConversation($toSummarize);
if ('' === \trim($conversationText)) {
return $messages;
}

Copilot uses AI. Check for mistakes.
@chr-hertel chr-hertel force-pushed the feat-compression branch 2 times, most recently from fcd6194 to 3e246cf Compare February 4, 2026 22:21
@OskarStark
Copy link
Contributor

rebase unlocked

*
* @author Christopher Hertel <mail@christopher-hertel.de>
*/
interface CompressionStrategyInterface
Copy link
Contributor

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.

Copy link
Contributor

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.

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

Labels

Agent Issues & PRs about the AI Agent component Feature New feature Status: Reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants