elliottlawson/converse

A Laravel package for storing and managing AI conversation history in your applications


README

Converse Logo


Tests Latest Stable Version Total Downloads License


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.