Skip to content
16 changes: 15 additions & 1 deletion src/agent/src/Toolbox/AgentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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<mixed> $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 {
Expand Down
Loading