diff --git a/src/ai-bundle/src/AiBundle.php b/src/ai-bundle/src/AiBundle.php index f52212ec2..72bba0c20 100644 --- a/src/ai-bundle/src/AiBundle.php +++ b/src/ai-bundle/src/AiBundle.php @@ -600,7 +600,8 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde $agentDefinition ->setArgument(2, []) // placeholder until ProcessorCompilerPass process. ->setArgument(3, []) // placeholder until ProcessorCompilerPass process. - ->setArgument(4, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)) + ->setArgument(4, $name) + ->setArgument(5, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE)) ; $container->setDefinition($agentId, $agentDefinition); diff --git a/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php b/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php index 35e340b01..ae2142724 100644 --- a/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php +++ b/src/ai-bundle/tests/DependencyInjection/AiBundleTest.php @@ -108,6 +108,33 @@ public function testAgentHasTag() $this->assertArrayHasKey('ai.agent.my_agent', $container->findTaggedServiceIds('ai.agent')); } + public function testAgentNameIsSetFromConfigKey() + { + $container = $this->buildContainer([ + 'ai' => [ + 'agent' => [ + 'my_custom_agent' => [ + 'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'], + ], + ], + ], + ]); + + $this->assertTrue($container->hasDefinition('ai.agent.my_custom_agent')); + + $agentDefinition = $container->getDefinition('ai.agent.my_custom_agent'); + $arguments = $agentDefinition->getArguments(); + + // The 5th argument (index 4) should be the config key as agent name + $this->assertArrayHasKey(4, $arguments, 'Agent definition should have argument at index 4 for name'); + $this->assertSame('my_custom_agent', $arguments[4]); + + // Check that the tag uses the config key as name + $tags = $agentDefinition->getTag('ai.agent'); + $this->assertNotEmpty($tags, 'Agent should have ai.agent tag'); + $this->assertSame('my_custom_agent', $tags[0]['name'], 'Agent tag should use config key as name'); + } + #[TestWith([true], 'enabled')] #[TestWith([false], 'disabled')] public function testFaultTolerantAgentSpecificToolbox(bool $enabled)