Skip to content

Commit e58dfb3

Browse files
authored
Merge pull request #2 from llm-agents-php/feature/links-interfaces
Use HasLinkedAgentsInterface interface for linked agents handling
2 parents 371ba1c + 3bfae04 commit e58dfb3

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"require": {
66
"php": "^8.3",
7-
"llm-agents/agents": "^1.2",
7+
"llm-agents/agents": "^1.5",
88
"llm-agents/json-schema-mapper": "^1.0"
99
},
1010
"require-dev": {

src/Interceptors/LinkedAgentsInjector.php

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace LLM\Agents\PromptGenerator\Interceptors;
66

77
use LLM\Agents\Agent\AgentRepositoryInterface;
8+
use LLM\Agents\Agent\HasLinkedAgentsInterface;
89
use LLM\Agents\LLM\Prompt\Chat\MessagePrompt;
910
use LLM\Agents\LLM\Prompt\Chat\Prompt;
1011
use LLM\Agents\LLM\Prompt\Chat\PromptInterface;
@@ -27,6 +28,10 @@ public function generate(
2728
): PromptInterface {
2829
\assert($input->prompt instanceof Prompt);
2930

31+
if (!$input->agent instanceof HasLinkedAgentsInterface) {
32+
return $next($input);
33+
}
34+
3035
if (\count($input->agent->getAgents()) === 0) {
3136
return $next($input);
3237
}

src/Interceptors/UserPromptInjector.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44

55
namespace LLM\Agents\PromptGenerator\Interceptors;
66

7-
use LLM\Agents\LLM\Prompt\Chat\ChatMessage;
7+
use LLM\Agents\LLM\Prompt\Chat\MessagePrompt;
88
use LLM\Agents\LLM\Prompt\Chat\Prompt;
99
use LLM\Agents\LLM\Prompt\Chat\PromptInterface;
10-
use LLM\Agents\LLM\Prompt\Chat\Role;
1110
use LLM\Agents\PromptGenerator\InterceptorHandler;
1211
use LLM\Agents\PromptGenerator\PromptGeneratorInput;
1312
use LLM\Agents\PromptGenerator\PromptInterceptorInterface;
@@ -23,10 +22,10 @@ public function generate(
2322
return $next(
2423
input: $input->withPrompt(
2524
$input->prompt->withAddedMessage(
26-
new ChatMessage(
27-
content: (string) $input->userPrompt,
28-
role: Role::User,
29-
),
25+
MessagePrompt::user('{user_prompt}')
26+
->withValues([
27+
'user_prompt' => (string) $input->userPrompt,
28+
]),
3029
),
3130
),
3231
);

0 commit comments

Comments
 (0)