symfony/ai-session-message-store
Symfony AI Session Message Store integrates Symfony Session as a message store for Symfony AI Chat, letting you persist and retrieve chat conversation messages across requests using standard Symfony session handling.
SessionInterface vs. Laravel’s session() helper) introduce architectural friction. The package excels for lightweight, session-scoped AI interactions but lacks native support for Laravel’s session drivers (e.g., Redis, database) without additional abstraction.FlashBag may not map cleanly to Laravel’s session()->flash(), risking message loss or corruption.MessageStoreInterface with Laravel’s session system. Key challenges include:
Session::getBag('ai_messages') vs. session()->get('ai_messages')).symfony/ai-chat and symfony/http-foundation as dependencies, which may conflict with existing Laravel packages (e.g., symfony/console).Session expects methods like getFlashBag() and saveFlash(), which Laravel’s session() helper does not natively support. Custom middleware or facades are required to handle these cases.symfony/ai-chat lacks a changelog, and its 0.9+ versions may introduce breaking changes. The package’s lack of dependents (0) suggests low adoption, increasing risk of abandonment.symfony/ai-chat behind an interface (e.g., AiChatInterface) to isolate changes.FlashBag for AI chat notifications?WATCH) required?Core Dependencies:
composer require symfony/ai-session-message-store symfony/ai-chat symfony/http-foundation
Recommended Stack:
| Component | Recommendation | Notes |
|---|---|---|
| Session Driver | Redis (production) | Scalable, low latency. |
| Database (development) | Simpler but risks bloat. | |
| AI Chat Abstraction | Custom AiChatInterface |
Decouples from symfony/ai-chat. |
| Adapter Layer | LaravelSessionMessageStore |
Bridges Symfony MessageStoreInterface to Laravel. |
| Flash Handling | Custom middleware | Maps Symfony FlashBag to Laravel. |
| Fallback Storage | Database/Redis (hybrid) | For long-term retention. |
Example Adapter Implementation:
namespace App\Adapters;
use Symfony\Component\Ai\Chat\MessageStoreInterface;
use Illuminate\Session\Store;
use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
class LaravelSessionMessageStore implements MessageStoreInterface
{
public function __construct(private Store $laravelSession) {}
public function load(string $sessionId): array
{
$this->laravelSession->setId($sessionId);
return $this->laravelSession->get('ai_messages', []);
}
public function save(string $sessionId, array $messages): void
{
$this->laravelSession->setId($sessionId);
$this->laravelSession->put('ai_messages', $messages);
}
// Handle Symfony flash messages via Laravel's flash system
public function addFlash(string $type, string $message): void
{
$this->laravelSession->flash($type, $message);
}
}
Phase 1: Adapter Development (1–2 days)
LaravelSessionMessageStore to bridge Symfony’s MessageStoreInterface with Laravel’s session.FlashBag → Laravel session()->flash()).Phase 2: Integration (2–3 days)
$this->app->singleton(MessageStoreInterface::class, function ($app) {
return new LaravelSessionMessageStore($app->make('session'));
});
symfony/ai-chat to use the adapter:
$aiChat = new AiChat(
app(MessageStoreInterface::class),
app(AiModelInterface::class)
);
Phase 3: Optimization (1–2 days)
session()->save() hooks).symfony/http-foundation. Ensure no conflicts with existing Symfony packages (e.g., symfony/console).How can I help you explore Laravel packages today?