Skip to content

Commit b9bfe58

Browse files
committed
feature #345 [Agent][Platform] Add Metadata to MessageBag (VincentLanglet)
This PR was squashed before being merged into the main branch. Discussion ---------- [Agent][Platform] Add `Metadata` to `MessageBag` | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | yes | Issues | Fix #344 | License | MIT Commits ------- 30cfcb8 [Agent][Platform] Add `Metadata` to `MessageBag`
2 parents c27dafa + 30cfcb8 commit b9bfe58

File tree

14 files changed

+36
-15
lines changed

14 files changed

+36
-15
lines changed

src/agent/tests/StructuredOutput/AgentProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
use Symfony\AI\Fixtures\StructuredOutput\Step;
2424
use Symfony\AI\Platform\Capability;
2525
use Symfony\AI\Platform\Message\MessageBag;
26+
use Symfony\AI\Platform\Metadata\Metadata;
2627
use Symfony\AI\Platform\Model;
27-
use Symfony\AI\Platform\Result\Metadata\Metadata;
2828
use Symfony\AI\Platform\Result\ObjectResult;
2929
use Symfony\AI\Platform\Result\TextResult;
3030
use Symfony\Component\Serializer\SerializerInterface;

src/platform/src/Message/MessageBag.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@
1111

1212
namespace Symfony\AI\Platform\Message;
1313

14+
use Symfony\AI\Platform\Metadata\MetadataAwareTrait;
15+
1416
/**
1517
* @final
1618
*
1719
* @author Christopher Hertel <mail@christopher-hertel.de>
1820
*/
1921
class MessageBag implements MessageBagInterface
2022
{
23+
use MetadataAwareTrait;
24+
2125
/**
2226
* @var list<MessageInterface>
2327
*/

src/platform/src/Message/MessageBagInterface.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\AI\Platform\Message;
1313

14+
use Symfony\AI\Platform\Metadata\Metadata;
15+
1416
/**
1517
* @author Oskar Stark <oskarstark@googlemail.com>
1618
*/
@@ -36,4 +38,6 @@ public function prepend(MessageInterface $message): self;
3638
public function containsAudio(): bool;
3739

3840
public function containsImage(): bool;
41+
42+
public function getMetadata(): Metadata;
3943
}

src/platform/src/Result/Metadata/Metadata.php renamed to src/platform/src/Metadata/Metadata.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\AI\Platform\Result\Metadata;
12+
namespace Symfony\AI\Platform\Metadata;
1313

1414
/**
1515
* @implements \IteratorAggregate<string, mixed>

src/platform/src/Result/Metadata/MetadataAwareTrait.php renamed to src/platform/src/Metadata/MetadataAwareTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\AI\Platform\Result\Metadata;
12+
namespace Symfony\AI\Platform\Metadata;
1313

1414
/**
1515
* @author Denis Zunke <denis.zunke@gmail.com>

src/platform/src/Result/BaseResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\AI\Platform\Result;
1313

14-
use Symfony\AI\Platform\Result\Metadata\MetadataAwareTrait;
14+
use Symfony\AI\Platform\Metadata\MetadataAwareTrait;
1515

1616
/**
1717
* Base result of converted result classes.

src/platform/src/Result/ResultInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace Symfony\AI\Platform\Result;
1313

14+
use Symfony\AI\Platform\Metadata\Metadata;
1415
use Symfony\AI\Platform\Result\Exception\RawResultAlreadySetException;
15-
use Symfony\AI\Platform\Result\Metadata\Metadata;
1616

1717
/**
1818
* @author Christopher Hertel <mail@christopher-hertel.de>

src/platform/tests/Bridge/Mistral/TokenOutputProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use Symfony\AI\Agent\Output;
1919
use Symfony\AI\Platform\Bridge\Mistral\TokenOutputProcessor;
2020
use Symfony\AI\Platform\Message\MessageBagInterface;
21+
use Symfony\AI\Platform\Metadata\Metadata;
2122
use Symfony\AI\Platform\Model;
22-
use Symfony\AI\Platform\Result\Metadata\Metadata;
2323
use Symfony\AI\Platform\Result\Metadata\TokenUsage;
2424
use Symfony\AI\Platform\Result\RawHttpResult;
2525
use Symfony\AI\Platform\Result\ResultInterface;

src/platform/tests/Bridge/OpenAi/TokenOutputProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
use Symfony\AI\Agent\Output;
1919
use Symfony\AI\Platform\Bridge\OpenAi\TokenOutputProcessor;
2020
use Symfony\AI\Platform\Message\MessageBagInterface;
21+
use Symfony\AI\Platform\Metadata\Metadata;
2122
use Symfony\AI\Platform\Model;
22-
use Symfony\AI\Platform\Result\Metadata\Metadata;
2323
use Symfony\AI\Platform\Result\Metadata\TokenUsage;
2424
use Symfony\AI\Platform\Result\RawHttpResult;
2525
use Symfony\AI\Platform\Result\ResultInterface;

src/platform/tests/Message/MessageBagTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,17 @@ public function testContainsImageReturnsTrueWithImage()
166166

167167
$this->assertTrue($messageBag->containsImage());
168168
}
169+
170+
public function testItCanHandleMetadata()
171+
{
172+
$messageBag = new MessageBag();
173+
$metadata = $messageBag->getMetadata();
174+
175+
$this->assertCount(0, $metadata);
176+
177+
$metadata->add('key', 'value');
178+
$metadata = $messageBag->getMetadata();
179+
180+
$this->assertCount(1, $metadata);
181+
}
169182
}

0 commit comments

Comments
 (0)