Skip to content

Commit a588afe

Browse files
authored
docs: add section about chain in chain (#268)
1 parent 3a813b7 commit a588afe

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,24 @@ $toolbox = new Toolbox(new ChainFactory($metadataFactory, $reflectionFactory), [
275275
> [!NOTE]
276276
> The order of the factories in the `ChainFactory` matters, as the first factory has the highest priority.
277277
278+
#### Chain in Chain 🤯
279+
280+
Similar to third-party tools, you can also use a chain as a tool in another chain. This can be useful to encapsulate
281+
complex logic or to reuse a chain in multiple places or hide sub-chains from the LLM.
282+
283+
```php
284+
use PhpLlm\LlmChain\Chain\Toolbox\MetadataFactory\MemoryFactory;
285+
use PhpLlm\LlmChain\Chain\Toolbox\Toolbox;
286+
use PhpLlm\LlmChain\Chain\Toolbox\Tool\Chain;
287+
288+
// Chain was initialized before
289+
290+
$chainTool = new Chain($chain);
291+
$metadataFactory = (new MemoryFactory())
292+
->addTool($chainTool, 'research_agent', 'Meaningful description for sub-chain');
293+
$toolbox = new Toolbox($metadataFactory, [$chainTool]);
294+
```
295+
278296
#### Fault Tolerance
279297

280298
To gracefully handle errors that occur during tool calling, e.g. wrong tool names or runtime errors, you can use the

0 commit comments

Comments
 (0)