1818use Symfony \AI \Agent \Toolbox \Attribute \AsTool ;
1919use Symfony \AI \Agent \Toolbox \Exception \ToolConfigurationException ;
2020use Symfony \AI \Agent \Toolbox \Exception \ToolExecutionException ;
21+ use Symfony \AI \Agent \Toolbox \Exception \ToolExecutionExceptionInterface ;
2122use Symfony \AI \Agent \Toolbox \Exception \ToolNotFoundException ;
2223use Symfony \AI \Agent \Toolbox \Toolbox ;
2324use Symfony \AI \Agent \Toolbox \ToolFactory \ChainFactory ;
2425use Symfony \AI \Agent \Toolbox \ToolFactory \MemoryToolFactory ;
2526use Symfony \AI \Agent \Toolbox \ToolFactory \ReflectionToolFactory ;
27+ use Symfony \AI \Fixtures \Tool \ToolCustomException ;
2628use Symfony \AI \Fixtures \Tool \ToolDate ;
2729use Symfony \AI \Fixtures \Tool \ToolException ;
2830use Symfony \AI \Fixtures \Tool \ToolMisconfigured ;
@@ -60,6 +62,7 @@ protected function setUp(): void
6062 new ToolOptionalParam (),
6163 new ToolNoParams (),
6264 new ToolException (),
65+ new ToolCustomException (),
6366 new ToolDate (),
6467 ], new ReflectionToolFactory ());
6568 }
@@ -122,6 +125,12 @@ public function testGetTools()
122125 'This tool is broken ' ,
123126 );
124127
128+ $ toolCustomException = new Tool (
129+ new ExecutionReference (ToolCustomException::class, 'bar ' ),
130+ 'tool_custom_exception ' ,
131+ 'This tool is broken and it exposes the error ' ,
132+ );
133+
125134 $ toolDate = new Tool (
126135 new ExecutionReference (ToolDate::class, '__invoke ' ),
127136 'tool_date ' ,
@@ -145,6 +154,7 @@ public function testGetTools()
145154 $ toolOptionalParam ,
146155 $ toolNoParams ,
147156 $ toolException ,
157+ $ toolCustomException ,
148158 $ toolDate ,
149159 ];
150160
@@ -177,6 +187,14 @@ public function testExecuteWithException()
177187 $ this ->toolbox ->execute (new ToolCall ('call_1234 ' , 'tool_exception ' ));
178188 }
179189
190+ public function testExecuteWithCustomException ()
191+ {
192+ $ this ->expectException (ToolExecutionExceptionInterface::class);
193+ $ this ->expectExceptionMessage ('Custom error. ' );
194+
195+ $ this ->toolbox ->execute (new ToolCall ('call_1234 ' , 'tool_custom_exception ' ));
196+ }
197+
180198 #[DataProvider('executeProvider ' )]
181199 public function testExecute (string $ expected , string $ toolName , array $ toolPayload = [])
182200 {
0 commit comments