From 9018ed99e9a3d1e0e8ee67d0f971d3f618a768d3 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 3 Sep 2025 21:22:43 +0200 Subject: [PATCH] [AI-Bundle] Fix processor config --- src/ai-bundle/doc/index.rst | 2 +- src/ai-bundle/src/AiBundle.php | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/ai-bundle/doc/index.rst b/src/ai-bundle/doc/index.rst index 3e4814858..6425fe112 100644 --- a/src/ai-bundle/doc/index.rst +++ b/src/ai-bundle/doc/index.rst @@ -164,7 +164,7 @@ the ``#[AsOutputProcessor]`` attributes:: use Symfony\AI\Agent\OutputProcessorInterface; #[AsInputProcessor(priority: 99)] // This applies to every agent - #[AsOutputProcessor(agent: 'my_agent_id')] // The output processor will only be registered for 'my_agent_id' + #[AsOutputProcessor(agent: 'ai.agent.my_agent_name')] // The output processor will only be registered for 'ai.agent.my_agent_name' final readonly class MyService implements InputProcessorInterface, OutputProcessorInterface { public function processInput(Input $input): void diff --git a/src/ai-bundle/src/AiBundle.php b/src/ai-bundle/src/AiBundle.php index b5d446d06..9e6399357 100644 --- a/src/ai-bundle/src/AiBundle.php +++ b/src/ai-bundle/src/AiBundle.php @@ -456,6 +456,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde $container->setDefinition('ai.agent.'.$name.'.model', $modelDefinition); // AGENT + $agentId = 'ai.agent.'.$name; $agentDefinition = (new Definition(Agent::class)) ->addTag('ai.agent', ['name' => $name]) ->setArgument(0, new Reference($config['platform'])) @@ -516,8 +517,8 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde ->replaceArgument(0, new Reference('ai.toolbox.'.$name)); $container->setDefinition('ai.tool.agent_processor.'.$name, $toolProcessorDefinition) - ->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -10]) - ->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -10]); + ->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -10]) + ->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -10]); } else { if ($config['fault_tolerant_toolbox'] && !$container->hasDefinition('ai.fault_tolerant_toolbox')) { $container->setDefinition('ai.fault_tolerant_toolbox', new Definition(FaultTolerantToolbox::class)) @@ -526,16 +527,16 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde } $container->getDefinition('ai.tool.agent_processor') - ->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -10]) - ->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -10]); + ->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -10]) + ->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -10]); } } // STRUCTURED OUTPUT if ($config['structured_output']) { $container->getDefinition('ai.agent.structured_output_processor') - ->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -20]) - ->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -20]); + ->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -20]) + ->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -20]); } // TOKEN USAGE TRACKING @@ -555,7 +556,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde if ($container->hasDefinition('ai.platform.token_usage_processor.'.$platform)) { $container->getDefinition('ai.platform.token_usage_processor.'.$platform) - ->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -30]); + ->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -30]); } } } @@ -568,7 +569,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde $config['include_tools'] ? new Reference('ai.toolbox.'.$name) : null, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE), ]) - ->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -30]); + ->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -30]); $container->setDefinition('ai.agent.'.$name.'.system_prompt_processor', $systemPromptInputProcessorDefinition); } @@ -579,8 +580,8 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde ->setArgument(4, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)) ; - $container->setDefinition('ai.agent.'.$name, $agentDefinition); - $container->registerAliasForArgument('ai.agent.'.$name, AgentInterface::class, (new Target($name.'Agent'))->getParsedName()); + $container->setDefinition($agentId, $agentDefinition); + $container->registerAliasForArgument($agentId, AgentInterface::class, (new Target($name.'Agent'))->getParsedName()); } /**