adachsoft / ai-agent-conversation-repository-json
JSON filesystem implementation of the AdachSoft AI Agent conversation repository interface
Package info
gitlab.com/a.adach/ai-agent-conversation-repository-json
pkg:composer/adachsoft/ai-agent-conversation-repository-json
Requires
- php: >=8.3
- adachsoft/ai-agent: ^0.13 || ^0.14
- adachsoft/ai-conversation-model: ^0.2
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^12.4
- rector/rector: ^2.9
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This package stores AI agent conversation histories as JSON files. Each conversation is stored in a separate <conversation-id>.json file. It provides a filesystem-backed implementation of the AdachSoft AI Agent conversation repository interface.
Requirements
- PHP 8.3 or later.
- Composer.
Capabilities
- Create, load, append to, list, and delete conversations.
- Store each conversation independently as a JSON file.
- Serialize current histories using the shared conversation model's versioned JSON format.
- Read supported legacy message lists and normalize them when a non-empty append is persisted.
Installation
Install the package with Composer:
composer require adachsoft/ai-agent-conversation-repository-json
Usage
Install the dependency, create the repository with a persistent writable storage path, and call it through the repository interface. See the JSON file repository example for a complete workflow.
Integration
Create the repository through its factory and provide the resulting implementation wherever the AI Agent conversation repository interface is required:
use AdachSoft\AiAgentConversationRepositoryJson\JsonFileConversationRepositoryFactory;
$factory = new JsonFileConversationRepositoryFactory(__DIR__ . '/var/conversations');
$conversationRepository = $factory->create();
$conversationRepository->create('conversation-123');
$history = $conversationRepository->load('conversation-123');
The factory creates the storage directory if it does not exist. Keep the directory writable by the application process and choose a location appropriate for persistent application data.
File format
New and updated files use a versioned envelope with messages in the canonical adachsoft/ai-conversation-model array format:
{
"format": "ai-conversation-model",
"version": 1,
"messages": []
}
The shared model preserves typed text and media content, tool calls, tool results, timestamps, roles, and metadata.
Legacy format
Existing files containing a top-level list of legacy messages remain readable. Legacy camelCase fields are converted to the shared conversation model, tool-result arrays are encoded as JSON text, and inconsistent histories are repaired when loaded. The next non-empty append writes the complete history in the versioned format.