Skip to content

Commit

Permalink
Merge pull request #2 from llm-agents-php/feature/links-interfaces
Browse files Browse the repository at this point in the history
Use HasLinkedAgentsInterface interface for linked agents handling
  • Loading branch information
butschster authored Sep 7, 2024
2 parents 371ba1c + 3bfae04 commit e58dfb3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"require": {
"php": "^8.3",
"llm-agents/agents": "^1.2",
"llm-agents/agents": "^1.5",
"llm-agents/json-schema-mapper": "^1.0"
},
"require-dev": {
Expand Down
5 changes: 5 additions & 0 deletions src/Interceptors/LinkedAgentsInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
11 changes: 5 additions & 6 deletions src/Interceptors/UserPromptInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
]),
),
),
);
Expand Down

0 comments on commit e58dfb3

Please sign in to comment.