Search by

adachsoft / ai-agent-context-message-injector

Arkadiusz Adach

Generic conversation message injector decorator for adachsoft/ai-agent.

Package info

gitlab.com/a.adach/ai-agent-context-message-injector

Issues

pkg:composer/adachsoft/ai-agent-context-message-injector

Statistics

Installs: 4

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.0 2026-11-28 20:03 UTC

This package is auto-updated.

Last update: 2026-11-28 19:03:56 UTC


README

Generic conversation message injector decorator for adachsoft/ai-agent.

Purpose

This library provides a generic ConversationContextStrategyInterface decorator that injects an additional ChatMessageDto from the shared adachsoft/ai-conversation-model package into the context produced by any inner strategy. The content is provided by a pluggable SPI (MessageContentProviderInterface), while the role and injection position are fully configurable via strategy params.

Key ideas:

  • Decorator pattern
  • SPI content provider
  • No domain dependencies on specific tools or working memory
  • Simple model: one injected message per decorator; N decorators = N injected messages
  • Three injection positions: start, before_last, end

Requirements

  • PHP >=8.3
  • adachsoft/ai-agent (^0.14)
  • adachsoft/ai-conversation-model (^0.2.0)
  • psr/clock (^1.0)

Installation

Install via Composer in a project that already uses adachsoft/ai-agent:

composer require adachsoft/ai-agent-context-message-injector

Configuration

The main entry point is the MessageInjectorConversationContextStrategy. It wraps an existing ConversationContextStrategyInterface implementation and injects a single message into its result.

Configuration parameters are defined in MessageInjectorStrategyParams:

  • injection_role (one of system, developer, user, or assistant; default: "user")
  • injection_position ("start" | "before_last" | "end", default: "end")
  • content_prefix (string, default: empty)
  • content_suffix (string, default: empty)
  • inject_when_empty (bool, default: false)
  • empty_content_placeholder (string, default: empty)

Content for the injected message is provided by an implementation of MessageContentProviderInterface.

Example wiring (pseudo-code)

use AdachSoft\AiAgentContextMessageInjector\MessageInjectorConversationContextStrategy;
use AdachSoft\AiAgentContextMessageInjector\MessageInjectorStrategyParams;
use AdachSoft\AiAgentContextMessageInjector\Spi\MessageContentProviderInterface;
use AdachSoft\AiAgent\Spi\Conversation\ConversationContextStrategyInterface;

final class StaticSystemPromptProvider implements MessageContentProviderInterface
{
    public function provide(string $conversationId): ?string
    {
        return 'You are a helpful assistant.';
    }
}

$innerStrategy = /* some ConversationContextStrategyInterface implementation */;
$provider = new StaticSystemPromptProvider();

$strategy = new MessageInjectorConversationContextStrategy(
    conversationContextStrategy: $innerStrategy,
    messageContentProvider: $provider,
);

$params = [
    MessageInjectorStrategyParams::INJECTION_ROLE => 'system',
    MessageInjectorStrategyParams::INJECTION_POSITION => 'start',
];

$resultConversation = $strategy->transform(
    $conversationId,
    $fullConversation,
    $params,
);

Testing

This package ships with a dedicated PHPUnit test suite under tests/. In a monorepo setup, include this directory in your root phpunit.xml configuration.