-
-
Notifications
You must be signed in to change notification settings - Fork 173
[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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <fabien@symfony.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\AI\Agent\Compression; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we move it to |
||
|
|
||
| use Symfony\AI\Platform\Message\MessageBag; | ||
|
|
||
| /** | ||
| * Event dispatched after history compression is applied. | ||
| * Listeners can inspect or modify the compressed messages before they are used. | ||
| * | ||
| * @author Christopher Hertel <mail@christopher-hertel.de> | ||
| */ | ||
| final class AfterHistoryCompression | ||
| { | ||
| public function __construct( | ||
| private readonly MessageBag $originalMessages, | ||
| private MessageBag $compressedMessages, | ||
| ) { | ||
| } | ||
|
|
||
| public function getOriginalMessages(): MessageBag | ||
| { | ||
| return $this->originalMessages; | ||
| } | ||
|
|
||
| public function getCompressedMessages(): MessageBag | ||
| { | ||
| return $this->compressedMessages; | ||
| } | ||
|
|
||
| /** | ||
| * Replace the compressed messages (e.g., for further modification). | ||
| */ | ||
| public function setCompressedMessages(MessageBag $messages): void | ||
| { | ||
| $this->compressedMessages = $messages; | ||
| } | ||
|
|
||
| /** | ||
| * Returns the number of messages removed by compression. | ||
| */ | ||
| public function getCompressionDelta(): int | ||
| { | ||
| return \count($this->originalMessages) - \count($this->compressedMessages); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <fabien@symfony.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\AI\Agent\Compression; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same |
||
|
|
||
| use Symfony\AI\Platform\Message\MessageBag; | ||
|
|
||
| /** | ||
| * Event dispatched before history compression is applied. | ||
| * Listeners can inspect the original messages and optionally skip compression. | ||
| * | ||
| * @author Christopher Hertel <mail@christopher-hertel.de> | ||
| */ | ||
| final class BeforeHistoryCompression | ||
| { | ||
| private bool $skip = false; | ||
|
|
||
| public function __construct( | ||
| private readonly MessageBag $originalMessages, | ||
| ) { | ||
| } | ||
|
|
||
| public function getOriginalMessages(): MessageBag | ||
| { | ||
| return $this->originalMessages; | ||
| } | ||
|
|
||
| /** | ||
| * Call this to prevent compression from being applied. | ||
| */ | ||
| public function skip(): void | ||
| { | ||
| $this->skip = true; | ||
| } | ||
|
|
||
| public function isSkipped(): bool | ||
| { | ||
| return $this->skip; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the Symfony package. | ||
| * | ||
| * (c) Fabien Potencier <fabien@symfony.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| namespace Symfony\AI\Agent\Compression; | ||
|
|
||
| use Symfony\AI\Platform\Message\MessageBag; | ||
|
|
||
| /** | ||
| * Strategy for compressing conversation history. | ||
| * | ||
| * @author Christopher Hertel <mail@christopher-hertel.de> | ||
| */ | ||
| interface CompressionStrategyInterface | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Reason I'm saying this is that there could be use cases other than compression for using this, especially around filtering/adding more messages.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| { | ||
| /** | ||
| * Determines whether the message bag should be compressed. | ||
| */ | ||
| public function shouldCompress(MessageBag $messages): bool; | ||
|
|
||
| /** | ||
| * Compresses the message bag and returns a new, smaller message bag. | ||
| */ | ||
| public function compress(MessageBag $messages): MessageBag; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.