Available Drivers
| Driver | Use Case | Persistence | Performance |
|---|---|---|---|
InMemoryStorage | Testing, single-request processing | None | Fastest |
SessionStorage | Web requests, user sessions | Session lifetime | Fast |
CacheStorage | Temporary storage with TTL | Configurable | Fast |
FileStorage | Simple file-based persistence | Permanent | Moderate |
SimpleEloquentStorage | Database (JSON blob) | Permanent | Moderate |
EloquentStorage | Database (normalized rows) | Permanent | Best for querying |
Driver Chain (Fallback Pattern)
LarAgentStorage classes support configuring multiple drivers in a chain. The first driver is the primary, and subsequent drivers serve as fallbacks:
- Reading: Tries the primary driver first. If it returns no data, falls back to the next driver.
- Writing: Writes to all drivers in the chain to keep them synchronized.
- Removing: Removes from all drivers.
InMemoryStorage
Stores data in PHP memory. Data is lost after the request ends. Ideal for testing or single-request agents.There is no point in using InMemoryStorage with other storage drivers in a fallback chain.
SessionStorage
Uses Laravel’s session to store data. Perfect for web applications where context should persist across user requests.CacheStorage
Uses Laravel’s cache system. Supports different cache stores like Redis, Memcached, or file.Custom configuration
Custom configuration
MyAgent
| Parameter | Type | Default | Description |
|---|---|---|---|
$store | ?string | null | Cache store name (e.g., 'redis', 'memcached'). Uses default cache store if null. |
FileStorage
Stores data as JSON files on disk using Laravel’s filesystem.Custom configuration
Custom configuration
MyAgent
| Parameter | Type | Default | Description |
|---|---|---|---|
$disk | ?string | null | Storage disk name. Uses config('filesystems.default') if null. |
$folder | string | 'laragent_storage' | Folder path within the disk where files are stored. |
EloquentStorage
Stores each item as a separate database row. Best for applications that need to query individual messages or require advanced database features.Example here uses
historyStorageDrivers instead of defaultStorageDrivers to show chat history specific laravel model override.Custom configuration
Custom configuration
MyAgent
| Parameter | Type | Default | Description |
|---|---|---|---|
$model | ?string | null | Eloquent model class name. Defaults to LaragentMessage::class. |
| Method | Description |
|---|---|
setKeyColumn(string $column) | Column for session identifier |
setPositionColumn(string $column) | Column for item ordering |
Custom model example
Custom model example
SimpleEloquentStorage
Stores all data as a JSON blob in a single database row. Simple setup, good for basic use cases.Custom configuration
Custom configuration
MyAgent
| Parameter | Type | Default | Description |
|---|---|---|---|
$model | ?string | null | Eloquent model class name. Defaults to LaragentStorage::class. |
Custom model example
Custom model example
Selection Guide
| Use Case | Recommended Driver(s) |
|---|---|
| Development/Testing | in_memory |
| Simple web app | session or cache |
| Production with Redis | cache (redis) |
| Need to query data | database (EloquentStorage) |
| Simple DB persistence | database-simple |
| High availability | cache + file (fallback chain) |
| Serverless/Lambda | database or database-simple |
| Long-running processes | cache + database |

