adachsoft / ai-tool-call-middleware
Middleware decorators for adachsoft/ai-tool-call facade.
Package info
gitlab.com/a.adach/ai-tool-call-middleware
pkg:composer/adachsoft/ai-tool-call-middleware
Requires
- php: ^8.3
- adachsoft/ai-tool-call: ^1.0 || ^2.0
Requires (Dev)
- adachsoft/php-code-style: ^0.7
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^12.5
- rector/rector: ^2.6
- symplify/phpstan-rules: ^14.13
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-03 07:01:25 UTC
README
adachsoft/ai-tool-call-middleware provides decorators for the public adachsoft/ai-tool-call facade.
Output-size safeguard
Wrap a facade through OutputSizeLimitingFacadeFactory:
use AdachSoft\AiToolCallMiddleware\OutputSize\OutputSizeLimitingFacadeFactory;
/** @var OutputSizeLimitingFacadeFactory $factory */
$factory = $container->get(OutputSizeLimitingFacadeFactory::class);
$facade = $factory->wrap($baseFacade);
wrap() returns an AiToolCallFacadeInterface. The returned facade measures supported tool results in bytes and passes results within the configured limit through unchanged. Oversized results are returned as a structured truncation payload containing the original size, configured limit, returned size, preview, and guidance for requesting a narrower result.
The middleware does not throw an exception when an output exceeds the limit. Results that cannot be measured are passed through unchanged, using a fail-open policy so the safeguard does not break an otherwise valid tool call. Exceptions raised by the wrapped facade are propagated unchanged.
Tool discovery methods are delegated without modification. The safeguard therefore applies only to tool-call results.
Individual tools should still provide their own limits, pagination, filtering, and truncation metadata. See the repository documentation in docs/tool-output-size-rules.md for the output-size contract.