|
19 | 19 | use Symfony\AI\Agent\Agent; |
20 | 20 | use Symfony\AI\Agent\AgentAwareInterface; |
21 | 21 | use Symfony\AI\Agent\AgentInterface; |
| 22 | +use Symfony\AI\Agent\Chat; |
| 23 | +use Symfony\AI\Agent\Chat\MessageStore\InMemoryStore; |
22 | 24 | use Symfony\AI\Agent\Exception\InvalidArgumentException; |
23 | 25 | use Symfony\AI\Agent\Exception\MissingModelSupportException; |
24 | 26 | use Symfony\AI\Agent\Exception\RuntimeException; |
|
30 | 32 | use Symfony\AI\Platform\Message\Content\Audio; |
31 | 33 | use Symfony\AI\Platform\Message\Content\Image; |
32 | 34 | use Symfony\AI\Platform\Message\Content\Text; |
| 35 | +use Symfony\AI\Platform\Message\Message; |
33 | 36 | use Symfony\AI\Platform\Message\MessageBag; |
34 | 37 | use Symfony\AI\Platform\Message\UserMessage; |
35 | 38 | use Symfony\AI\Platform\Model; |
|
49 | 52 | #[UsesClass(Text::class)] |
50 | 53 | #[UsesClass(Audio::class)] |
51 | 54 | #[UsesClass(Image::class)] |
| 55 | +#[UsesClass(InMemoryStore::class)] |
| 56 | +#[UsesClass(Chat::class)] |
52 | 57 | #[Small] |
53 | 58 | final class AgentTest extends TestCase |
54 | 59 | { |
@@ -395,4 +400,32 @@ public function testConstructorAcceptsTraversableProcessors() |
395 | 400 |
|
396 | 401 | $this->assertInstanceOf(AgentInterface::class, $agent); |
397 | 402 | } |
| 403 | + |
| 404 | + public function testDoubleAgentCanUseSameMessageStore() |
| 405 | + { |
| 406 | + $platform = $this->createMock(PlatformInterface::class); |
| 407 | + $model = $this->createMock(Model::class); |
| 408 | + |
| 409 | + $firstAgent = new Agent($platform, $model); |
| 410 | + $secondAgent = new Agent($platform, $model); |
| 411 | + |
| 412 | + $store = new InMemoryStore(); |
| 413 | + $firstStore = $store->withSession($firstAgent->getId()); |
| 414 | + $secondStore = $store->withSession($secondAgent->getId()); |
| 415 | + |
| 416 | + $firstChat = new Chat($firstAgent, $firstStore); |
| 417 | + $secondChat = new Chat($secondAgent, $secondStore); |
| 418 | + |
| 419 | + $messages = new MessageBag( |
| 420 | + Message::forSystem('You are a helpful assistant. You only answer with short sentences.'), |
| 421 | + ); |
| 422 | + |
| 423 | + $firstChat->initiate($messages); |
| 424 | + $firstChat->submit(new UserMessage(new Text('Hello'))); |
| 425 | + $secondChat->submit(new UserMessage(new Text('Hello'))); |
| 426 | + $secondChat->submit(new UserMessage(new Text('Hello there'))); |
| 427 | + |
| 428 | + $this->assertCount(1, $firstStore->load()); |
| 429 | + $this->assertCount(2, $secondStore->load()); |
| 430 | + } |
398 | 431 | } |
0 commit comments