Search by

adachsoft / ai-tool-runtime

Arkadiusz Adach

Runtime layer for adachsoft/ai-tool-call: tool configuration loading, result normalization and exception flattening.

Package info

gitlab.com/a.adach/ai-tool-runtime

Issues

pkg:composer/adachsoft/ai-tool-runtime

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-09-09 07:59 UTC

This package is not auto-updated.

Last update: 2026-09-10 04:43:15 UTC


README

adachsoft/ai-tool-runtime is a runtime layer for adachsoft/ai-tool-call. It loads tool configuration, resolves placeholders, normalizes tool results for JSON serialization, extracts tool names from SPI factories, and flattens exception chains.

Usage

Use JsonFileToolConfigResolverFactory as the recommended entry point:

use AdachSoft\AiToolRuntime\Config\Dto\ToolConfigContextDto;
use AdachSoft\AiToolRuntime\Config\Dto\ToolConfigLayerContextDto;
use AdachSoft\AiToolRuntime\Factory\JsonFileToolConfigResolverFactory;

$factory = new JsonFileToolConfigResolverFactory();
$resolver = $factory->create(['/etc/my-tools']);

$configs = $resolver->buildToolConfigs(
    registeredToolNames: ['example_tool'],
    toolConfigContextDto: new ToolConfigContextDto(['api_key' => $apiKey]),
    toolConfigLayerContextDto: new ToolConfigLayerContextDto(),
);

$facadeBuilder->withToolConfigs($configs);

JSON configuration

Each tool configuration is stored in <tool_name>.json. The filename must exactly match the name returned by the tool's getDefinition() method. The JSON root must be an object. Configuration keys must satisfy the ConfigMap rules: a non-empty string of at most 32 characters containing lowercase letters, digits, underscores, and optional dot-separated segments.

Placeholders use the {{name}} syntax. Whitespace inside the braces is accepted, and dotted names are supported. Values are taken exclusively from the ToolConfigContextDto supplied by the caller.

This package never reads environment variables, .env files, $_ENV, $_SERVER, or getenv(). The host application decides where context values come from. Exception messages do not contain environment variable names.

Public API and internal implementation

Public APIPurpose
ToolConfigResolverInterfaceBuilds final tool configurations.
ToolConfigPlaceholderResolverInterfaceResolves configuration placeholders.
ToolConfigRepositoryInterfaceExtension point for configuration sources.
ToolConfigLayerInterfaceExtension point for configuration layers.
SpiToolNameExtractorInterfaceExtracts registered tool names from SPI factories.
ToolCallResultNormalizerInterfaceConverts tool results into JSON-safe values.
ToolConfigContextDto, ToolConfigLayerContextDtoInput context DTOs.
Classes in Exception/Exceptions exposed to consumers.
ExceptionChainFlattenerPublic exception-chain formatting helper.
JsonFileToolConfigResolverFactoryRecommended resolver factory.
RepositoryToolConfigLayerReusable repository-backed layer.
InMemoryToolConfigRepositoryIn-memory repository for tests and custom integrations.

ToolConfigResolver, ToolConfigPlaceholderResolver, JsonFileToolConfigRepository, SpiToolNameExtractor, and ToolCallResultNormalizer are internal implementations created or used by the factory.

Configuration for a tool that is not registered causes the build to fail fast with ToolConfigUnknownToolException.

Testing

vendor/bin/phpunit -c packages/ai-tool-runtime/phpunit.xml.dist
vendor/bin/phpstan analyse packages/ai-tool-runtime/src packages/ai-tool-runtime/tests
vendor/bin/rector process packages/ai-tool-runtime/src packages/ai-tool-runtime/tests
vendor/bin/php-cs-fixer fix packages/ai-tool-runtime/src packages/ai-tool-runtime/tests

First release

Version 0.1.0 is the first release of adachsoft/ai-tool-runtime. It provides the runtime services required to load tool configuration, resolve caller-provided placeholders, normalize tool results for JSON serialization, extract registered SPI tool names, and flatten exception chains.

Install the package with Composer:

composer require adachsoft/ai-tool-runtime:^0.1

See CHANGELOG.md for the complete release history.