@@ -589,9 +589,37 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
589589 ->setArgument (0 , new Reference ($ config ['platform ' ]))
590590 ->setArgument (1 , $ config ['model ' ]);
591591
592- // TOOL & PROCESSOR
592+ // TOOLBOX
593593 if ($ config ['tools ' ]['enabled ' ]) {
594- // Create specific toolbox and process if tools are explicitly defined
594+ // Setup toolbox for agent
595+ $ toolboxDefinition = (new ChildDefinition ('ai.toolbox.abstract ' ))
596+ ->replaceArgument (1 , new Reference ('ai.toolbox. ' .$ name .'.chain_factory ' ))
597+ ->addTag ('ai.toolbox ' , ['name ' => $ name ]);
598+ $ container ->setDefinition ('ai.toolbox. ' .$ name , $ toolboxDefinition );
599+
600+ if ($ config ['fault_tolerant_toolbox ' ]) {
601+ $ container ->setDefinition ('ai.fault_tolerant_toolbox. ' .$ name , new Definition (FaultTolerantToolbox::class))
602+ ->setArguments ([new Reference ('.inner ' )])
603+ ->setDecoratedService ('ai.toolbox. ' .$ name );
604+ }
605+
606+ if ($ container ->getParameter ('kernel.debug ' )) {
607+ $ traceableToolboxDefinition = (new Definition ('ai.traceable_toolbox. ' .$ name ))
608+ ->setClass (TraceableToolbox::class)
609+ ->setArguments ([new Reference ('.inner ' )])
610+ ->setDecoratedService ('ai.toolbox. ' .$ name )
611+ ->addTag ('ai.traceable_toolbox ' );
612+ $ container ->setDefinition ('ai.traceable_toolbox. ' .$ name , $ traceableToolboxDefinition );
613+ }
614+
615+ $ toolProcessorDefinition = (new ChildDefinition ('ai.tool.agent_processor.abstract ' ))
616+ ->replaceArgument (0 , new Reference ('ai.toolbox. ' .$ name ));
617+
618+ $ container ->setDefinition ('ai.tool.agent_processor. ' .$ name , $ toolProcessorDefinition )
619+ ->addTag ('ai.agent.input_processor ' , ['agent ' => $ agentId , 'priority ' => -10 ])
620+ ->addTag ('ai.agent.output_processor ' , ['agent ' => $ agentId , 'priority ' => -10 ]);
621+
622+ // Define specific list of tools if are explicitly defined
595623 if ([] !== $ config ['tools ' ]['services ' ]) {
596624 $ memoryFactoryDefinition = new ChildDefinition ('ai.tool_factory.abstract ' );
597625 $ memoryFactoryDefinition ->setClass (MemoryToolFactory::class);
@@ -620,42 +648,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
620648 $ tools [] = $ reference ;
621649 }
622650
623- $ toolboxDefinition = (new ChildDefinition ('ai.toolbox.abstract ' ))
624- ->replaceArgument (0 , $ tools )
625- ->replaceArgument (1 , new Reference ('ai.toolbox. ' .$ name .'.chain_factory ' ));
626- $ container ->setDefinition ('ai.toolbox. ' .$ name , $ toolboxDefinition );
627-
628- if ($ config ['fault_tolerant_toolbox ' ]) {
629- $ container ->setDefinition ('ai.fault_tolerant_toolbox. ' .$ name , new Definition (FaultTolerantToolbox::class))
630- ->setArguments ([new Reference ('.inner ' )])
631- ->setDecoratedService ('ai.toolbox. ' .$ name );
632- }
633-
634- if ($ container ->getParameter ('kernel.debug ' )) {
635- $ traceableToolboxDefinition = (new Definition ('ai.traceable_toolbox. ' .$ name ))
636- ->setClass (TraceableToolbox::class)
637- ->setArguments ([new Reference ('.inner ' )])
638- ->setDecoratedService ('ai.toolbox. ' .$ name )
639- ->addTag ('ai.traceable_toolbox ' );
640- $ container ->setDefinition ('ai.traceable_toolbox. ' .$ name , $ traceableToolboxDefinition );
641- }
642-
643- $ toolProcessorDefinition = (new ChildDefinition ('ai.tool.agent_processor.abstract ' ))
644- ->replaceArgument (0 , new Reference ('ai.toolbox. ' .$ name ));
645-
646- $ container ->setDefinition ('ai.tool.agent_processor. ' .$ name , $ toolProcessorDefinition )
647- ->addTag ('ai.agent.input_processor ' , ['agent ' => $ agentId , 'priority ' => -10 ])
648- ->addTag ('ai.agent.output_processor ' , ['agent ' => $ agentId , 'priority ' => -10 ]);
649- } else {
650- if ($ config ['fault_tolerant_toolbox ' ] && !$ container ->hasDefinition ('ai.fault_tolerant_toolbox ' )) {
651- $ container ->setDefinition ('ai.fault_tolerant_toolbox ' , new Definition (FaultTolerantToolbox::class))
652- ->setArguments ([new Reference ('.inner ' )])
653- ->setDecoratedService ('ai.toolbox ' );
654- }
655-
656- $ container ->getDefinition ('ai.tool.agent_processor ' )
657- ->addTag ('ai.agent.input_processor ' , ['agent ' => $ agentId , 'priority ' => -10 ])
658- ->addTag ('ai.agent.output_processor ' , ['agent ' => $ agentId , 'priority ' => -10 ]);
651+ $ toolboxDefinition ->replaceArgument (0 , $ tools );
659652 }
660653 }
661654
0 commit comments