Database-Backed Persistence
Conversations and messages are stored in your database, surviving page reloads and server restarts. Query your AI history with Eloquent.
AI SDKs are great at sending messages, but terrible at having conversations. Converse makes AI conversations flow as naturally as Eloquent makes database queries.
Install the package via Composer:
composer require elliottlawson/converse
Add the trait to your User model:
use ElliottLawson\Converse\Traits\HasAIConversations;
class User extends Model
{
use HasAIConversations;
}
Start a conversation:
// 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);
Learn more in the documentation →
Using Prism for your AI integrations? Check out Converse-Prism for a seamless integration between both packages.
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. The entire conversation history, context management, and message formatting is handled automatically. It's the difference between sending messages and actually having a conversation.