This repository was archived by the owner on Jul 16, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Expand file tree Collapse file tree 3 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 44
55namespace PhpLlm \LlmChain \Chain \ToolBox ;
66
7- use PhpLlm \LlmChain \Exception \RuntimeException ;
7+ use PhpLlm \LlmChain \Exception \ToolNotFoundException ;
88use PhpLlm \LlmChain \Model \Response \ToolCall ;
99
1010final class ToolBox implements ToolBoxInterface
@@ -55,6 +55,6 @@ public function execute(ToolCall $toolCall): string
5555 }
5656 }
5757
58- throw new RuntimeException ( ' Tool not found ' );
58+ throw ToolNotFoundException:: forToolCall ( $ toolCall );
5959 }
6060}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace PhpLlm \LlmChain \Exception ;
6+
7+ use PhpLlm \LlmChain \Model \Response \ToolCall ;
8+
9+ final class ToolNotFoundException extends RuntimeException
10+ {
11+ public static function forToolCall (ToolCall $ toolCall ): self
12+ {
13+ return new self (sprintf ('Tool not found for call: %s ' , $ toolCall ->name ));
14+ }
15+ }
Original file line number Diff line number Diff line change 99use PhpLlm \LlmChain \Chain \ToolBox \ParameterAnalyzer ;
1010use PhpLlm \LlmChain \Chain \ToolBox \ToolAnalyzer ;
1111use PhpLlm \LlmChain \Chain \ToolBox \ToolBox ;
12+ use PhpLlm \LlmChain \Exception \ToolNotFoundException ;
1213use PhpLlm \LlmChain \Model \Response \ToolCall ;
1314use PhpLlm \LlmChain \Tests \Fixture \Tool \ToolNoParams ;
1415use PhpLlm \LlmChain \Tests \Fixture \Tool \ToolOptionalParam ;
@@ -101,6 +102,15 @@ public function toolsMap(): void
101102 self ::assertSame (json_encode ($ expected ), json_encode ($ actual ));
102103 }
103104
105+ #[Test]
106+ public function executeWithUnknownTool (): void
107+ {
108+ self ::expectException (ToolNotFoundException::class);
109+ self ::expectExceptionMessage ('Tool not found for call: foo_bar_baz ' );
110+
111+ $ this ->toolBox ->execute (new ToolCall ('call_1234 ' , 'foo_bar_baz ' ));
112+ }
113+
104114 #[Test]
105115 public function execute (): void
106116 {
You can’t perform that action at this time.
0 commit comments