Skip to content

ConverseAI 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.

Quick Setup

Install the package via Composer:

bash
composer require elliottlawson/converse

Add the trait to your User model:

php
use ElliottLawson\Converse\Traits\HasAIConversations;

class User extends Model
{
    use HasAIConversations;
}

Start a conversation:

php
// 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 →

Looking for an AI Client?

Using Prism for your AI integrations? Check out Converse-Prism for a seamless integration between both packages.

The Difference

Without Converse, every API call means manually rebuilding context:

php
// 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:

php
// 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.

Released under the MIT License.