Search by

adachsoft / ai-agent-kv-memory-tool

Arkadiusz Adach

Key-value memory tool for AI agents built on adachsoft/ai-tool-call.

Package info

gitlab.com/a.adach/ai-agent-kv-memory-tool

Issues

pkg:composer/adachsoft/ai-agent-kv-memory-tool

Statistics

Installs: 16

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-26 17:30 UTC

This package is auto-updated.

Last update: 2026-11-26 16:30:55 UTC


README

Key-value memory tool for AI agents built on adachsoft/ai-tool-call.

Requirements

  • PHP 8.3 or later
  • Composer
  • adachsoft/ai-tool-call for 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