Skip to content

Commit

Permalink
Adds an ability to merge options
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Aug 26, 2024
1 parent 1ab3f63 commit 1b37d52
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Agent/AgentExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use LLM\Agents\LLM\ContextInterface;
use LLM\Agents\LLM\LLMInterface;
use LLM\Agents\LLM\OptionsFactoryInterface;
use LLM\Agents\LLM\OptionsInterface;
use LLM\Agents\LLM\Prompt\Chat\Prompt;
use LLM\Agents\LLM\Prompt\Tool;
use LLM\Agents\LLM\Response\ChatResponse;
Expand All @@ -34,6 +35,7 @@ public function execute(
string $agent,
string|\Stringable|Prompt $prompt,
?ContextInterface $context = null,
?OptionsInterface $options = null,
?array $sessionContext = null,
): Execution {
$agent = $this->agents->get($agent);
Expand All @@ -51,7 +53,7 @@ public function execute(
$agent->getTools(),
);

$options = $this->optionsFactory
$defaultOptions = $this->optionsFactory
->create()
->with('model', $model->name)
->with(
Expand All @@ -67,6 +69,12 @@ public function execute(
),
);

if ($options === null) {
$options = $defaultOptions;
} else {
$options = $defaultOptions->merge($options);
}

foreach ($agent->getConfiguration() as $configuration) {
$options = $options->with($configuration->key, $configuration->content);
}
Expand Down
2 changes: 2 additions & 0 deletions src/LLM/OptionsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public function has(string $option): bool;
public function get(string $option, mixed $default = null): mixed;

public function with(string $option, mixed $value): static;

public function merge(OptionsInterface $options): static;
}

0 comments on commit 1b37d52

Please sign in to comment.