-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from llm-agents-php/feature/agent-execution-in…
…terceptors Adds agent execution interceptors
- Loading branch information
Showing
6 changed files
with
100 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Domain\Chat\PromptGenerator; | ||
|
||
use LLM\Agents\LLM\Prompt\Chat\PromptInterface; | ||
use LLM\Agents\PromptGenerator\InterceptorHandler; | ||
use LLM\Agents\PromptGenerator\PromptGeneratorInput; | ||
use LLM\Agents\PromptGenerator\PromptInterceptorInterface; | ||
|
||
final class Dump implements PromptInterceptorInterface | ||
{ | ||
public function generate( | ||
PromptGeneratorInput $input, | ||
InterceptorHandler $next, | ||
): PromptInterface { | ||
dump($input->prompt->format()); | ||
|
||
return $next($input); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
app/src/Domain/Chat/PromptGenerator/SessionContextInjector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Domain\Chat\PromptGenerator; | ||
|
||
use LLM\Agents\LLM\Prompt\Chat\MessagePrompt; | ||
use LLM\Agents\LLM\Prompt\Chat\Prompt; | ||
use LLM\Agents\LLM\Prompt\Chat\PromptInterface; | ||
use LLM\Agents\PromptGenerator\Context; | ||
use LLM\Agents\PromptGenerator\InterceptorHandler; | ||
use LLM\Agents\PromptGenerator\PromptGeneratorInput; | ||
use LLM\Agents\PromptGenerator\PromptInterceptorInterface; | ||
|
||
final class SessionContextInjector implements PromptInterceptorInterface | ||
{ | ||
public function generate( | ||
PromptGeneratorInput $input, | ||
InterceptorHandler $next, | ||
): PromptInterface { | ||
\assert($input->prompt instanceof Prompt); | ||
|
||
if ( | ||
(!$input->context instanceof Context) | ||
|| $input->context->getAuthContext() === null | ||
) { | ||
return $next($input); | ||
} | ||
|
||
return $next( | ||
input: $input->withPrompt( | ||
$input->prompt | ||
->withAddedMessage( | ||
MessagePrompt::system( | ||
prompt: 'Session context: {active_context}', | ||
), | ||
)->withValues( | ||
values: [ | ||
'active_context' => \json_encode($input->context->getAuthContext()), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters