Skip to content

Commit a29a7b2

Browse files
committed
feature #512 [AI Bundle][AiBundle] Set agent name from configuration key (OskarStark)
This PR was merged into the main branch. Discussion ---------- [AI Bundle][AiBundle] Set agent name from configuration key | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | Issues | Follows #509 | License | MIT Commits ------- 8622ef2 [AiBundle] Set agent name from configuration key
2 parents 3ac1ac9 + 8622ef2 commit a29a7b2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/ai-bundle/src/AiBundle.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,8 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
600600
$agentDefinition
601601
->setArgument(2, []) // placeholder until ProcessorCompilerPass process.
602602
->setArgument(3, []) // placeholder until ProcessorCompilerPass process.
603-
->setArgument(4, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
603+
->setArgument(4, $name)
604+
->setArgument(5, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
604605
;
605606

606607
$container->setDefinition($agentId, $agentDefinition);

src/ai-bundle/tests/DependencyInjection/AiBundleTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,33 @@ public function testAgentHasTag()
108108
$this->assertArrayHasKey('ai.agent.my_agent', $container->findTaggedServiceIds('ai.agent'));
109109
}
110110

111+
public function testAgentNameIsSetFromConfigKey()
112+
{
113+
$container = $this->buildContainer([
114+
'ai' => [
115+
'agent' => [
116+
'my_custom_agent' => [
117+
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
118+
],
119+
],
120+
],
121+
]);
122+
123+
$this->assertTrue($container->hasDefinition('ai.agent.my_custom_agent'));
124+
125+
$agentDefinition = $container->getDefinition('ai.agent.my_custom_agent');
126+
$arguments = $agentDefinition->getArguments();
127+
128+
// The 5th argument (index 4) should be the config key as agent name
129+
$this->assertArrayHasKey(4, $arguments, 'Agent definition should have argument at index 4 for name');
130+
$this->assertSame('my_custom_agent', $arguments[4]);
131+
132+
// Check that the tag uses the config key as name
133+
$tags = $agentDefinition->getTag('ai.agent');
134+
$this->assertNotEmpty($tags, 'Agent should have ai.agent tag');
135+
$this->assertSame('my_custom_agent', $tags[0]['name'], 'Agent tag should use config key as name');
136+
}
137+
111138
#[TestWith([true], 'enabled')]
112139
#[TestWith([false], 'disabled')]
113140
public function testFaultTolerantAgentSpecificToolbox(bool $enabled)

0 commit comments

Comments
 (0)