diff --git a/src/Chain/ToolBox/ToolBox.php b/src/Chain/ToolBox/ToolBox.php index bc3f852e..bca547a1 100644 --- a/src/Chain/ToolBox/ToolBox.php +++ b/src/Chain/ToolBox/ToolBox.php @@ -4,7 +4,7 @@ namespace PhpLlm\LlmChain\Chain\ToolBox; -use PhpLlm\LlmChain\Exception\RuntimeException; +use PhpLlm\LlmChain\Exception\ToolNotFoundException; use PhpLlm\LlmChain\Model\Response\ToolCall; final class ToolBox implements ToolBoxInterface @@ -55,6 +55,6 @@ public function execute(ToolCall $toolCall): string } } - throw new RuntimeException('Tool not found'); + throw ToolNotFoundException::forToolCall($toolCall); } } diff --git a/src/Exception/ToolNotFoundException.php b/src/Exception/ToolNotFoundException.php new file mode 100644 index 00000000..d68a93a4 --- /dev/null +++ b/src/Exception/ToolNotFoundException.php @@ -0,0 +1,15 @@ +name)); + } +} diff --git a/tests/Chain/ToolBox/ToolBoxTest.php b/tests/Chain/ToolBox/ToolBoxTest.php index a02b3444..c494d60f 100644 --- a/tests/Chain/ToolBox/ToolBoxTest.php +++ b/tests/Chain/ToolBox/ToolBoxTest.php @@ -9,6 +9,7 @@ use PhpLlm\LlmChain\Chain\ToolBox\ParameterAnalyzer; use PhpLlm\LlmChain\Chain\ToolBox\ToolAnalyzer; use PhpLlm\LlmChain\Chain\ToolBox\ToolBox; +use PhpLlm\LlmChain\Exception\ToolNotFoundException; use PhpLlm\LlmChain\Model\Response\ToolCall; use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolNoParams; use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolOptionalParam; @@ -101,6 +102,15 @@ public function toolsMap(): void self::assertSame(json_encode($expected), json_encode($actual)); } + #[Test] + public function executeWithUnknownTool(): void + { + self::expectException(ToolNotFoundException::class); + self::expectExceptionMessage('Tool not found for call: foo_bar_baz'); + + $this->toolBox->execute(new ToolCall('call_1234', 'foo_bar_baz')); + } + #[Test] public function execute(): void {