From 6fc61d8806b7d058b86014dbe710cde0ebeba291 Mon Sep 17 00:00:00 2001 From: Pavel Buchnev Date: Fri, 6 Sep 2024 20:03:33 +0400 Subject: [PATCH 1/2] Use HasLinkedAgentsInterface interface for linked agents handling --- composer.json | 2 +- src/Interceptors/LinkedAgentsInjector.php | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9822aec..8ea0e3d 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "license": "MIT", "require": { "php": "^8.3", - "llm-agents/agents": "^1.2", + "llm-agents/agents": "dev-feature/embeddings as 1.0", "llm-agents/json-schema-mapper": "^1.0" }, "require-dev": { diff --git a/src/Interceptors/LinkedAgentsInjector.php b/src/Interceptors/LinkedAgentsInjector.php index 9769843..cb803f1 100644 --- a/src/Interceptors/LinkedAgentsInjector.php +++ b/src/Interceptors/LinkedAgentsInjector.php @@ -5,6 +5,7 @@ namespace LLM\Agents\PromptGenerator\Interceptors; use LLM\Agents\Agent\AgentRepositoryInterface; +use LLM\Agents\Agent\HasLinkedAgentsInterface; use LLM\Agents\LLM\Prompt\Chat\MessagePrompt; use LLM\Agents\LLM\Prompt\Chat\Prompt; use LLM\Agents\LLM\Prompt\Chat\PromptInterface; @@ -27,6 +28,10 @@ public function generate( ): PromptInterface { \assert($input->prompt instanceof Prompt); + if (!$input->agent instanceof HasLinkedAgentsInterface) { + return $next($input); + } + if (\count($input->agent->getAgents()) === 0) { return $next($input); } From 3bfae0452f1ded7a6603805252f893495c4a7eb1 Mon Sep 17 00:00:00 2001 From: Pavel Buchnev Date: Sat, 7 Sep 2024 12:34:00 +0400 Subject: [PATCH 2/2] Improves user prompt message. It provides an ability to replace prompt text --- composer.json | 2 +- src/Interceptors/UserPromptInjector.php | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 8ea0e3d..03fc500 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "license": "MIT", "require": { "php": "^8.3", - "llm-agents/agents": "dev-feature/embeddings as 1.0", + "llm-agents/agents": "^1.5", "llm-agents/json-schema-mapper": "^1.0" }, "require-dev": { diff --git a/src/Interceptors/UserPromptInjector.php b/src/Interceptors/UserPromptInjector.php index 6862a36..3568e15 100644 --- a/src/Interceptors/UserPromptInjector.php +++ b/src/Interceptors/UserPromptInjector.php @@ -4,10 +4,9 @@ namespace LLM\Agents\PromptGenerator\Interceptors; -use LLM\Agents\LLM\Prompt\Chat\ChatMessage; +use LLM\Agents\LLM\Prompt\Chat\MessagePrompt; use LLM\Agents\LLM\Prompt\Chat\Prompt; use LLM\Agents\LLM\Prompt\Chat\PromptInterface; -use LLM\Agents\LLM\Prompt\Chat\Role; use LLM\Agents\PromptGenerator\InterceptorHandler; use LLM\Agents\PromptGenerator\PromptGeneratorInput; use LLM\Agents\PromptGenerator\PromptInterceptorInterface; @@ -23,10 +22,10 @@ public function generate( return $next( input: $input->withPrompt( $input->prompt->withAddedMessage( - new ChatMessage( - content: (string) $input->userPrompt, - role: Role::User, - ), + MessagePrompt::user('{user_prompt}') + ->withValues([ + 'user_prompt' => (string) $input->userPrompt, + ]), ), ), );