diff --git a/src/agent/src/Toolbox/AgentProcessor.php b/src/agent/src/Toolbox/AgentProcessor.php index b966d29d6..6cd273b82 100644 --- a/src/agent/src/Toolbox/AgentProcessor.php +++ b/src/agent/src/Toolbox/AgentProcessor.php @@ -44,12 +44,18 @@ public function __construct( public function processInput(Input $input): void { + $options = $input->getOptions(); + + // If the option 'tools' is already an array of tools, do nothing + if (isset($options['tools']) && $this->isToolsArray($options['tools'])) { + return; + } + $toolMap = $this->toolbox->getTools(); if ([] === $toolMap) { return; } - $options = $input->getOptions(); // only filter tool map if list of strings is provided as option if (isset($options['tools']) && $this->isFlatStringArray($options['tools'])) { $toolMap = array_values(array_filter($toolMap, fn (Tool $tool) => \in_array($tool->name, $options['tools'], true))); @@ -85,6 +91,14 @@ private function isFlatStringArray(array $tools): bool return array_reduce($tools, fn (bool $carry, mixed $item) => $carry && \is_string($item), true); } + /** + * @param array $tools + */ + private function isToolsArray(array $tools): bool + { + return array_reduce($tools, fn (bool $carry, mixed $item) => $carry && $item instanceof Tool, true); + } + private function handleToolCallsCallback(Output $output): \Closure { return function (ToolCallResult $result, ?AssistantMessage $streamedAssistantResponse = null) use ($output): ResultInterface {