@@ -139,9 +139,6 @@ Tool calling can be enabled by registering the processors in the chain:
139139use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
140140use PhpLlm\LlmChain\Chain\ToolBox\ToolAnalyzer;
141141use PhpLlm\LlmChain\Chain\ToolBox\ToolBox;
142- use Symfony\Component\Serializer\Encoder\JsonEncoder;
143- use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
144- use Symfony\Component\Serializer\Serializer;
145142
146143// Platform & LLM instantiation
147144
@@ -180,7 +177,6 @@ You can configure the method to be called by the LLM with the `#[AsTool]` attrib
180177``` php
181178use PhpLlm\LlmChain\ToolBox\Attribute\AsTool;
182179
183-
184180#[AsTool(name: 'weather_current', description: 'get current weather for a location', method: 'current')]
185181#[AsTool(name: 'weather_forecast', description: 'get weather forecast for a location', method: 'forecast')]
186182final readonly class OpenMeteo
@@ -231,6 +227,24 @@ See attribute class [ToolParameter](src/Chain/ToolBox/Attribute/ToolParameter.ph
231227> [ !NOTE]
232228> Please be aware, that this is only converted in a JSON Schema for the LLM to respect, but not validated by LLM Chain.
233229
230+ #### Fault Tolerance
231+
232+ To gracefully handle errors that occur during tool calling, e.g. wrong tool names or runtime errors, you can use the
233+ ` FaultTolerantToolBox ` as a decorator for the ` ToolBox ` . It will catch the exceptions and return readable error messages
234+ to the LLM.
235+
236+ ``` php
237+ use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor;
238+ use PhpLlm\LlmChain\Chain\ToolBox\FaultTolerantToolBox;
239+
240+ // Platform, LLM & ToolBox instantiation
241+
242+ $toolBox = new FaultTolerantToolBox($innerToolBox);
243+ $toolProcessor = new ChainProcessor($toolBox);
244+
245+ $chain = new Chain($platform, $llm, inputProcessor: [$toolProcessor], outputProcessor: [$toolProcessor]);
246+ ```
247+
234248#### Tool Result Interception
235249
236250To react to the result of a tool, you can implement an EventListener or EventSubscriber, that listens to the
0 commit comments