Skip to content

Commit 314b183

Browse files
committed
feature #350 Remove MessageBagInterface (chr-hertel)
This PR was merged into the main branch. Discussion ---------- Remove MessageBagInterface | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | | License | MIT The MessageBag was final for some time and the interface was needed to bring in more capabilities that users want to have on their end. The interface was quite heavy tho and changes would also be quite impactful - not saying adding a method to a class that gets extended is fun, but still less annoying from maintenance point of view - i hope 😬 Commits ------- d181fbe Remove MessageBagInterface
2 parents b9bfe58 + d181fbe commit 314b183

File tree

25 files changed

+60
-111
lines changed

25 files changed

+60
-111
lines changed

src/agent/src/Agent.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\AI\Agent\Exception\MissingModelSupportException;
1818
use Symfony\AI\Agent\Exception\RuntimeException;
1919
use Symfony\AI\Platform\Capability;
20-
use Symfony\AI\Platform\Message\MessageBagInterface;
20+
use Symfony\AI\Platform\Message\MessageBag;
2121
use Symfony\AI\Platform\Model;
2222
use Symfony\AI\Platform\PlatformInterface;
2323
use Symfony\AI\Platform\Result\ResultInterface;
@@ -61,7 +61,7 @@ public function __construct(
6161
* @throws InvalidArgumentException When the platform returns a client error (4xx) indicating invalid request parameters
6262
* @throws RuntimeException When the platform returns a server error (5xx) or network failure occurs
6363
*/
64-
public function call(MessageBagInterface $messages, array $options = []): ResultInterface
64+
public function call(MessageBag $messages, array $options = []): ResultInterface
6565
{
6666
$input = new Input($this->model, $messages, $options);
6767
array_map(fn (InputProcessorInterface $processor) => $processor->processInput($input), $this->inputProcessors);

src/agent/src/AgentInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\AI\Agent;
1313

1414
use Symfony\AI\Agent\Exception\ExceptionInterface;
15-
use Symfony\AI\Platform\Message\MessageBagInterface;
15+
use Symfony\AI\Platform\Message\MessageBag;
1616
use Symfony\AI\Platform\Result\ResultInterface;
1717

1818
/**
@@ -25,5 +25,5 @@ interface AgentInterface
2525
*
2626
* @throws ExceptionInterface When the agent encounters an error (e.g., unsupported model capabilities, invalid arguments, network failures, or processor errors)
2727
*/
28-
public function call(MessageBagInterface $messages, array $options = []): ResultInterface;
28+
public function call(MessageBag $messages, array $options = []): ResultInterface;
2929
}

src/agent/src/Chat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use Symfony\AI\Agent\Chat\MessageStoreInterface;
1515
use Symfony\AI\Platform\Message\AssistantMessage;
1616
use Symfony\AI\Platform\Message\Message;
17-
use Symfony\AI\Platform\Message\MessageBagInterface;
17+
use Symfony\AI\Platform\Message\MessageBag;
1818
use Symfony\AI\Platform\Message\UserMessage;
1919
use Symfony\AI\Platform\Result\TextResult;
2020

@@ -26,7 +26,7 @@ public function __construct(
2626
) {
2727
}
2828

29-
public function initiate(MessageBagInterface $messages): void
29+
public function initiate(MessageBag $messages): void
3030
{
3131
$this->store->clear();
3232
$this->store->save($messages);

src/agent/src/Chat/MessageStore/CacheStore.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\AI\Agent\Chat\MessageStoreInterface;
1616
use Symfony\AI\Agent\Exception\RuntimeException;
1717
use Symfony\AI\Platform\Message\MessageBag;
18-
use Symfony\AI\Platform\Message\MessageBagInterface;
1918

2019
final readonly class CacheStore implements MessageStoreInterface
2120
{
@@ -29,7 +28,7 @@ public function __construct(
2928
}
3029
}
3130

32-
public function save(MessageBagInterface $messages): void
31+
public function save(MessageBag $messages): void
3332
{
3433
$item = $this->cache->getItem($this->cacheKey);
3534

src/agent/src/Chat/MessageStore/InMemoryStore.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,17 @@
1313

1414
use Symfony\AI\Agent\Chat\MessageStoreInterface;
1515
use Symfony\AI\Platform\Message\MessageBag;
16-
use Symfony\AI\Platform\Message\MessageBagInterface;
1716

1817
final class InMemoryStore implements MessageStoreInterface
1918
{
20-
private MessageBagInterface $messages;
19+
private MessageBag $messages;
2120

22-
public function save(MessageBagInterface $messages): void
21+
public function save(MessageBag $messages): void
2322
{
2423
$this->messages = $messages;
2524
}
2625

27-
public function load(): MessageBagInterface
26+
public function load(): MessageBag
2827
{
2928
return $this->messages ?? new MessageBag();
3029
}

src/agent/src/Chat/MessageStore/SessionStore.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\AI\Agent\Chat\MessageStoreInterface;
1515
use Symfony\AI\Agent\Exception\RuntimeException;
1616
use Symfony\AI\Platform\Message\MessageBag;
17-
use Symfony\AI\Platform\Message\MessageBagInterface;
1817
use Symfony\Component\HttpFoundation\RequestStack;
1918
use Symfony\Component\HttpFoundation\Session\SessionInterface;
2019

@@ -32,12 +31,12 @@ public function __construct(
3231
$this->session = $requestStack->getSession();
3332
}
3433

35-
public function save(MessageBagInterface $messages): void
34+
public function save(MessageBag $messages): void
3635
{
3736
$this->session->set($this->sessionKey, $messages);
3837
}
3938

40-
public function load(): MessageBagInterface
39+
public function load(): MessageBag
4140
{
4241
return $this->session->get($this->sessionKey, new MessageBag());
4342
}

src/agent/src/Chat/MessageStoreInterface.php

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

1212
namespace Symfony\AI\Agent\Chat;
1313

14-
use Symfony\AI\Platform\Message\MessageBagInterface;
14+
use Symfony\AI\Platform\Message\MessageBag;
1515

1616
interface MessageStoreInterface
1717
{
18-
public function save(MessageBagInterface $messages): void;
18+
public function save(MessageBag $messages): void;
1919

20-
public function load(): MessageBagInterface;
20+
public function load(): MessageBag;
2121

2222
public function clear(): void;
2323
}

src/agent/src/ChatInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
use Symfony\AI\Agent\Exception\ExceptionInterface;
1515
use Symfony\AI\Platform\Message\AssistantMessage;
16-
use Symfony\AI\Platform\Message\MessageBagInterface;
16+
use Symfony\AI\Platform\Message\MessageBag;
1717
use Symfony\AI\Platform\Message\UserMessage;
1818

1919
interface ChatInterface
2020
{
21-
public function initiate(MessageBagInterface $messages): void;
21+
public function initiate(MessageBag $messages): void;
2222

2323
/**
2424
* @throws ExceptionInterface When the chat submission fails due to agent errors

src/agent/src/Input.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\AI\Agent;
1313

14-
use Symfony\AI\Platform\Message\MessageBagInterface;
14+
use Symfony\AI\Platform\Message\MessageBag;
1515
use Symfony\AI\Platform\Model;
1616

1717
/**
@@ -24,7 +24,7 @@ final class Input
2424
*/
2525
public function __construct(
2626
public Model $model,
27-
public MessageBagInterface $messages,
27+
public MessageBag $messages,
2828
private array $options,
2929
) {
3030
}

src/agent/src/Output.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
namespace Symfony\AI\Agent;
1313

14-
use Symfony\AI\Platform\Message\MessageBagInterface;
14+
use Symfony\AI\Platform\Message\MessageBag;
1515
use Symfony\AI\Platform\Model;
1616
use Symfony\AI\Platform\Result\ResultInterface;
1717

@@ -26,7 +26,7 @@ final class Output
2626
public function __construct(
2727
public readonly Model $model,
2828
public ResultInterface $result,
29-
public readonly MessageBagInterface $messages,
29+
public readonly MessageBag $messages,
3030
public readonly array $options,
3131
) {
3232
}

0 commit comments

Comments
 (0)