adachsoft / ai-integration-middleware
Middleware decorators for adachsoft/ai-integration tool-calling chat facade.
Package info
gitlab.com/a.adach/ai-integration-middleware
pkg:composer/adachsoft/ai-integration-middleware
Requires
- php: ^8.3
- adachsoft/ai-integration: ^0.8
- adachsoft/collection: ^3.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 not auto-updated.
Last update: 2026-09-04 19:28:21 UTC
README
Middleware decorators for adachsoft/ai-integration tool-calling chat facades.
Problem
AI providers reject a request when the conversation contains an assistant message with a tool call but no matching tool result. A typical provider error is:
No tool output found for function call <id>
This package repairs that history immediately before the decorated facade sends it to a provider. Each missing result is represented by a deterministic synthetic tool message.
Installation
composer require adachsoft/ai-integration-middleware
Usage
The middleware is opt-in. Wrap the facade at the composition root and pass the returned facade wherever a ToolCallingChatFacadeInterface is required:
use AdachSoft\AiIntegrationMiddleware\OrphanedToolCall\OrphanedToolCallRepairingFacadeFactory;
$toolCallingChatFacade = (new OrphanedToolCallRepairingFacadeFactory())
->wrap($toolCallingChatFacade);
// Pass $toolCallingChatFacade to the consumer as ToolCallingChatFacadeInterface.
A custom message can be configured through the factory constructor:
$toolCallingChatFacade = (new OrphanedToolCallRepairingFacadeFactory(
'The previous tool execution was interrupted. Run the tool again if needed.',
))->wrap($toolCallingChatFacade);
Scope and limitations
- The middleware does not persist or modify conversation history.
- Existing messages and their order are preserved.
- Existing tool results are never replaced.
- Tool messages without a corresponding assistant tool call are outside the repair scope and are passed through unchanged.
- The middleware is disabled unless the facade is explicitly wrapped.
- The package does not depend on
adachsoft/ai-agent.
The public composition API is OrphanedToolCallRepairingFacadeFactory::wrap(). The decorator and repair service are internal implementation details.
See the middleware design rules for the package conventions used by future decorators.
License
MIT