@@ -26,7 +26,7 @@ final class ChainProcessor implements InputProcessor, OutputProcessor, ChainAwar
26
26
27
27
public function __construct (
28
28
private readonly ToolBoxInterface $ toolBox ,
29
- private ToolResultConverter $ resultConverter = new ToolResultConverter (),
29
+ private readonly ToolResultConverter $ resultConverter = new ToolResultConverter (),
30
30
private readonly ?EventDispatcherInterface $ eventDispatcher = null ,
31
31
) {
32
32
}
@@ -44,7 +44,7 @@ public function processInput(Input $input): void
44
44
45
45
$ options = $ input ->getOptions ();
46
46
// 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 ' ])) {
48
48
$ toolMap = array_values (array_filter ($ toolMap , fn (Metadata $ tool ) => in_array ($ tool ->name , $ options ['tools ' ], true )));
49
49
}
50
50
@@ -70,6 +70,14 @@ public function processOutput(Output $output): void
70
70
$ output ->response = $ this ->handleToolCallsCallback ($ output )($ output ->response );
71
71
}
72
72
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
+
73
81
private function handleToolCallsCallback (Output $ output ): \Closure
74
82
{
75
83
return function (ToolCallResponse $ response , ?AssistantMessage $ streamedAssistantResponse = null ) use ($ output ): ResponseInterface {
0 commit comments