Skip to content

Commit b9f33f2

Browse files
authored
fix: array access of tool override (#226)
1 parent a4edfb5 commit b9f33f2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Chain/ToolBox/ChainProcessor.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class ChainProcessor implements InputProcessor, OutputProcessor, ChainAwar
2626

2727
public function __construct(
2828
private readonly ToolBoxInterface $toolBox,
29-
private ToolResultConverter $resultConverter = new ToolResultConverter(),
29+
private readonly ToolResultConverter $resultConverter = new ToolResultConverter(),
3030
private readonly ?EventDispatcherInterface $eventDispatcher = null,
3131
) {
3232
}
@@ -44,7 +44,7 @@ public function processInput(Input $input): void
4444

4545
$options = $input->getOptions();
4646
// only filter tool map if list of strings is provided as option
47-
if (isset($options['tools']) && is_array($options['tools']) && is_string($options['tools'][0])) {
47+
if (isset($options['tools']) && $this->isFlatStringArray($options['tools'])) {
4848
$toolMap = array_values(array_filter($toolMap, fn (Metadata $tool) => in_array($tool->name, $options['tools'], true)));
4949
}
5050

@@ -70,6 +70,14 @@ public function processOutput(Output $output): void
7070
$output->response = $this->handleToolCallsCallback($output)($output->response);
7171
}
7272

73+
/**
74+
* @param array<mixed> $tools
75+
*/
76+
private function isFlatStringArray(array $tools): bool
77+
{
78+
return array_reduce($tools, fn (bool $carry, mixed $item) => $carry && is_string($item), true);
79+
}
80+
7381
private function handleToolCallsCallback(Output $output): \Closure
7482
{
7583
return function (ToolCallResponse $response, ?AssistantMessage $streamedAssistantResponse = null) use ($output): ResponseInterface {

0 commit comments

Comments
 (0)