|
21 | 21 | use PhpLlm\LlmChain\Chain\OutputProcessor;
|
22 | 22 | use PhpLlm\LlmChain\Chain\StructuredOutput\ChainProcessor as StructureOutputProcessor;
|
23 | 23 | use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool;
|
| 24 | +use PhpLlm\LlmChain\Chain\ToolBox\ChainProcessor as ToolProcessor; |
24 | 25 | use PhpLlm\LlmChain\ChainInterface;
|
25 | 26 | use PhpLlm\LlmChain\Embedder;
|
26 | 27 | use PhpLlm\LlmChain\Model\EmbeddingsModel;
|
@@ -224,27 +225,33 @@ private function processChainConfig(string $name, array $config, ContainerBuilde
|
224 | 225 | $outputProcessor = [];
|
225 | 226 |
|
226 | 227 | // TOOL & PROCESSOR
|
227 |
| - if (0 !== count($config['tools'])) { |
228 |
| - $tools = array_map(static fn (string $tool) => new Reference($tool), $config['tools']); |
229 |
| - $toolboxDefinition = (new ChildDefinition('llm_chain.toolbox.abstract')) |
230 |
| - ->replaceArgument('$tools', $tools); |
231 |
| - $container->setDefinition('llm_chain.toolbox.'.$name, $toolboxDefinition); |
232 |
| - |
233 |
| - if ($container->getParameter('kernel.debug')) { |
234 |
| - $traceableToolboxDefinition = (new Definition('llm_chain.traceable_toolbox.'.$name)) |
235 |
| - ->setClass(TraceableToolBox::class) |
236 |
| - ->setAutowired(true) |
237 |
| - ->setDecoratedService('llm_chain.toolbox.'.$name) |
238 |
| - ->addTag('llm_chain.traceable_toolbox'); |
239 |
| - $container->setDefinition('llm_chain.traceable_toolbox.'.$name, $traceableToolboxDefinition); |
240 |
| - } |
| 228 | + if ($config['tools']['enabled']) { |
| 229 | + // Create specific tool box and process if tools are explicitly defined |
| 230 | + if (0 !== count($config['tools']['services'])) { |
| 231 | + $tools = array_map(static fn (string $tool) => new Reference($tool), $config['tools']['services']); |
| 232 | + $toolboxDefinition = (new ChildDefinition('llm_chain.toolbox.abstract')) |
| 233 | + ->replaceArgument('$tools', $tools); |
| 234 | + $container->setDefinition('llm_chain.toolbox.'.$name, $toolboxDefinition); |
| 235 | + |
| 236 | + if ($container->getParameter('kernel.debug')) { |
| 237 | + $traceableToolboxDefinition = (new Definition('llm_chain.traceable_toolbox.'.$name)) |
| 238 | + ->setClass(TraceableToolBox::class) |
| 239 | + ->setAutowired(true) |
| 240 | + ->setDecoratedService('llm_chain.toolbox.'.$name) |
| 241 | + ->addTag('llm_chain.traceable_toolbox'); |
| 242 | + $container->setDefinition('llm_chain.traceable_toolbox.'.$name, $traceableToolboxDefinition); |
| 243 | + } |
241 | 244 |
|
242 |
| - $toolProcessorDefinition = (new ChildDefinition('llm_chain.tool.chain_processor.abstract')) |
243 |
| - ->replaceArgument('$toolBox', new Reference('llm_chain.toolbox.'.$name)); |
244 |
| - $container->setDefinition('llm_chain.tool.chain_processor.'.$name, $toolProcessorDefinition); |
| 245 | + $toolProcessorDefinition = (new ChildDefinition('llm_chain.tool.chain_processor.abstract')) |
| 246 | + ->replaceArgument('$toolBox', new Reference('llm_chain.toolbox.'.$name)); |
| 247 | + $container->setDefinition('llm_chain.tool.chain_processor.'.$name, $toolProcessorDefinition); |
245 | 248 |
|
246 |
| - $inputProcessor[] = new Reference('llm_chain.tool.chain_processor.'.$name); |
247 |
| - $outputProcessor[] = new Reference('llm_chain.tool.chain_processor.'.$name); |
| 249 | + $inputProcessor[] = new Reference('llm_chain.tool.chain_processor.'.$name); |
| 250 | + $outputProcessor[] = new Reference('llm_chain.tool.chain_processor.'.$name); |
| 251 | + } else { |
| 252 | + $inputProcessor[] = new Reference(ToolProcessor::class); |
| 253 | + $outputProcessor[] = new Reference(ToolProcessor::class); |
| 254 | + } |
248 | 255 | }
|
249 | 256 |
|
250 | 257 | // STRUCTURED OUTPUT
|
|
0 commit comments