adachsoft / ai-agent-kv-memory-tool
Key-value memory tool for AI agents built on adachsoft/ai-tool-call.
Package info
gitlab.com/a.adach/ai-agent-kv-memory-tool
pkg:composer/adachsoft/ai-agent-kv-memory-tool
Requires
- php: >=8.3
- adachsoft/ai-tool-call: ^2.0.0
- adachsoft/collection: ^3.0
- psr/clock: ^1.0
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
Key-value memory tool for AI agents built on adachsoft/ai-tool-call.
Requirements
- PHP 8.3 or later
- Composer
adachsoft/ai-tool-callfor tool integration
Installation
In a monorepo setup, register the package as a Composer path repository in the root composer.json:
{
"type": "path",
"url": "packages/ai-agent-kv-memory-tool",
"options": {
"symlink": false
}
}
Then require it:
composer require adachsoft/ai-agent-kv-memory-tool
Usage
This package provides a ToolInterface implementation that exposes key-value operations scoped per conversation.
Supported operations:
kv_set– Store or overwrite a value for a given key.kv_get– Retrieve the value for a given key.kv_delete– Remove a specific key.kv_append– Append content to an existing value (or create a new entry).kv_clear– Remove all keys for the current conversation.kv_capacity– Report current usage and optional capacity limit.
The tool is integrated via KvMemoryToolFactory, which builds KvMemoryTool together with a set of operation handlers. A ConversationIdProviderInterface implementation must be supplied to resolve the current conversation identifier at runtime.
Integration
Create a repository and a conversation ID provider, then pass them to the factory. The in-memory repository is useful for tests and short-lived processes; use a persistent KvRepositoryInterface implementation to retain memory between process restarts.
use AdachSoft\AiAgentKvMemoryTool\Spi\Conversation\ConversationIdProviderInterface;
use AdachSoft\AiAgentKvMemoryTool\Spi\Repository\InMemoryKvRepository;
use AdachSoft\AiAgentKvMemoryTool\Tool\KvMemoryToolFactory;
use AdachSoft\AiToolCall\SPI\Collection\ConfigMap;
$conversationIdProvider = new class implements ConversationIdProviderInterface {
public function getCurrentConversationId(): string
{
return 'conversation-123'; // Resolve this from your application context.
}
};
$factory = KvMemoryToolFactory::withDefaults(
new InMemoryKvRepository(),
$conversationIdProvider,
kvMaxCapacity: 100,
);
$tool = $factory->create(new ConfigMap([]));
Register the resulting tool with your adachsoft/ai-tool-call integration. The provider must return the active conversation identifier for each call so that memory remains isolated per conversation.
Testing
Run the package test suite with the dedicated PHPUnit configuration:
vendor/bin/phpunit -c packages/ai-agent-kv-memory-tool/phpunit.xml.dist
Static analysis and code style are expected to be run from the monorepo root, for example:
vendor/bin/phpstan analyse packages/ai-agent-kv-memory-tool
vendor/bin/rector process packages/ai-agent-kv-memory-tool/src packages/ai-agent-kv-memory-tool/tests
vendor/bin/php-cs-fixer fix packages/ai-agent-kv-memory-tool