elliottlawson / converse
A Laravel package for storing and managing AI conversation history in your applications
Requires
- php: ^8.2
- illuminate/contracts: ^11.0|^12.0
- illuminate/database: ^11.0|^12.0
- illuminate/support: ^11.0|^12.0
Requires (Dev)
- laravel/pint: ^1.22
- orchestra/testbench: ^9.4
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- spatie/laravel-ray: ^1.40
- dev-master
- v0.2.0
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-fix/prism-link
- dev-docs/add-prism-callout
- dev-docs/showcase-prism-integration
- dev-refactor/specific-upgrade-commands
- dev-feature/add-uuid-to-messages
- dev-feature/view-support
- dev-feature/inline-conditional-helpers
- dev-feature/fluent-api
- dev-feature/github-actions-ci
- dev-chore/pint-formatting
- dev-feature/configurable-tables-v2
- dev-feature/configurable-table-names
- dev-feature/add-test-user-model
- dev-fix/composer-dependencies
This package is auto-updated.
Last update: 2025-06-15 06:23:40 UTC
README
Converse - AI Conversation Management for Laravel
AI SDKs are great at sending messages, but terrible at having conversations.
Converse makes AI conversations flow as naturally as Eloquent makes database queries. Instead of manually managing message arrays and context for every API call, you just write $conversation->addUserMessage('Hello')
. The entire conversation history, context management, and message formatting is handled automatically.
📚 Documentation
View the full documentation - Comprehensive guides, API reference, and examples.
The Difference
Without Converse, every API call means manually rebuilding context:
// Manually track every message 😫 $messages = [ ['role' => 'system', 'content' => $systemPrompt], ['role' => 'user', 'content' => $oldMessage1], ['role' => 'assistant', 'content' => $oldResponse1], ['role' => 'user', 'content' => $oldMessage2], ['role' => 'assistant', 'content' => $oldResponse2], ['role' => 'user', 'content' => $newMessage], ]; // Send to API $response = $client->chat()->create(['messages' => $messages]); // Now figure out how to save everything...
With Converse, conversations just flow:
// Context is automatic ✨ $conversation->addUserMessage($newMessage); // Your AI call gets the full context $response = $aiClient->chat([ 'messages' => $conversation->messages->toArray() ]); // Store the response $conversation->addAssistantMessage($response->content);
That's it. It's the difference between sending messages and actually having a conversation.
Features
- 💾 Database-Backed Persistence - Conversations survive page reloads and server restarts
- 🔌 Provider Agnostic - Works with OpenAI, Anthropic, Google, or any LLM
- 🌊 Streaming Made Simple - Automatic message chunking and progress tracking
- 🧠 Automatic Context Management - Stop rebuilding message arrays for every API call
- 📡 Built-in Events - Track usage, build analytics, react to AI interactions
- 🏗️ Laravel Native - Built with Eloquent, events, and broadcasting
Installation
composer require elliottlawson/converse
Run the migrations:
php artisan migrate
Quick Start
Add the trait to your User model:
use ElliottLawson\Converse\Traits\HasAIConversations; class User extends Model { use HasAIConversations; }
Start having conversations:
// Build the conversation context $conversation = $user->startConversation(['title' => 'My Chat']) ->addSystemMessage('You are a helpful assistant') ->addUserMessage('Hello! What is Laravel?'); // Make your API call to OpenAI, Anthropic, etc. $response = $yourAiClient->chat([ 'messages' => $conversation->messages->toArray(), // ... other AI configuration ]); // Store the AI's response $conversation->addAssistantMessage($response->content);
Looking for an AI Client?
Using Prism? Try out Converse-Prism - a seamless integration that combines Prism's elegant AI client with Converse's conversation management.
Requirements
- PHP 8.2+
- Laravel 11+
License
The MIT License (MIT). Please see License File for more information.