Skip to main content
LarAgent provides several storage drivers for persisting data. Each driver can be used with any storage type — chat history, usage tracking, identity storage, or custom storages.

Available Drivers

Driver Chain (Fallback Pattern)

LarAgent Storage classes support configuring multiple drivers in a chain. The first driver is the primary, and subsequent drivers serve as fallbacks:
How it works:
  • 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.
Use the fallback pattern for high availability. For example, cache for speed with file storage as a durable backup.

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.
Requires an active Laravel session. Not suitable for CLI or queue workers.

CacheStorage

Uses Laravel’s cache system. Supports different cache stores like Redis, Memcached, or file.
MyAgent
Constructor arguments:

FileStorage

Stores data as JSON files on disk using Laravel’s filesystem.
MyAgent
Constructor arguments:

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.
MyAgent
Constructor arguments:Additional methods:

SimpleEloquentStorage

Stores all data as a JSON blob in a single database row. Simple setup, good for basic use cases.
MyAgent
Constructor arguments:

Selection Guide

Next Steps

Chat History

Configure chat history storage and truncation strategies.

Usage Tracking

Track token usage and costs with storage drivers.