9
9
use PhpLlm \LlmChain \Chain \ToolBox \ParameterAnalyzer ;
10
10
use PhpLlm \LlmChain \Chain \ToolBox \ToolAnalyzer ;
11
11
use PhpLlm \LlmChain \Chain \ToolBox \ToolBox ;
12
- use PhpLlm \LlmChain \Exception \ToolNotFoundException ;
12
+ use PhpLlm \LlmChain \Exception \ToolBoxException ;
13
13
use PhpLlm \LlmChain \Model \Response \ToolCall ;
14
+ use PhpLlm \LlmChain \Tests \Fixture \Tool \ToolException ;
15
+ use PhpLlm \LlmChain \Tests \Fixture \Tool \ToolMisconfigured ;
14
16
use PhpLlm \LlmChain \Tests \Fixture \Tool \ToolNoParams ;
15
17
use PhpLlm \LlmChain \Tests \Fixture \Tool \ToolOptionalParam ;
16
18
use PhpLlm \LlmChain \Tests \Fixture \Tool \ToolRequiredParams ;
@@ -46,6 +48,7 @@ protected function setUp(): void
46
48
new ToolReturningInteger (),
47
49
new ToolReturningFloat (),
48
50
new ToolReturningStringable (),
51
+ new ToolException (),
49
52
]);
50
53
}
51
54
@@ -143,6 +146,13 @@ public function toolsMap(): void
143
146
'description ' => 'A tool returning an object which implements \Stringable ' ,
144
147
],
145
148
],
149
+ [
150
+ 'type ' => 'function ' ,
151
+ 'function ' => [
152
+ 'name ' => 'tool_exception ' ,
153
+ 'description ' => 'This tool is broken ' ,
154
+ ],
155
+ ],
146
156
];
147
157
148
158
self ::assertSame (json_encode ($ expected ), json_encode ($ actual ));
@@ -151,12 +161,32 @@ public function toolsMap(): void
151
161
#[Test]
152
162
public function executeWithUnknownTool (): void
153
163
{
154
- self ::expectException (ToolNotFoundException ::class);
164
+ self ::expectException (ToolBoxException ::class);
155
165
self ::expectExceptionMessage ('Tool not found for call: foo_bar_baz ' );
156
166
157
167
$ this ->toolBox ->execute (new ToolCall ('call_1234 ' , 'foo_bar_baz ' ));
158
168
}
159
169
170
+ #[Test]
171
+ public function executeWithMisconfiguredTool (): void
172
+ {
173
+ self ::expectException (ToolBoxException::class);
174
+ self ::expectExceptionMessage ('Method "foo" not found in tool "PhpLlm\LlmChain\Tests\Fixture\Tool\ToolMisconfigured". ' );
175
+
176
+ $ toolBox = new ToolBox (new ToolAnalyzer (), [new ToolMisconfigured ()]);
177
+
178
+ $ toolBox ->execute (new ToolCall ('call_1234 ' , 'tool_misconfigured ' ));
179
+ }
180
+
181
+ #[Test]
182
+ public function executeWithException (): void
183
+ {
184
+ self ::expectException (ToolBoxException::class);
185
+ self ::expectExceptionMessage ('Execution of tool "tool_exception" failed with error: Tool error. ' );
186
+
187
+ $ this ->toolBox ->execute (new ToolCall ('call_1234 ' , 'tool_exception ' ));
188
+ }
189
+
160
190
#[Test]
161
191
#[DataProvider('executeProvider ' )]
162
192
public function execute (string $ expected , string $ toolName , array $ toolPayload = []): void
0 commit comments