Skip to content

Commit 0b218be

Browse files
committed
feat(aibundle): injection alias added
1 parent 0407910 commit 0b218be

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/ai-bundle/src/AiBundle.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
105105
foreach ($config['agent'] as $agentName => $agent) {
106106
$this->processAgentConfig($agentName, $agent, $builder);
107107
}
108-
if (1 === \count($config['agent']) && isset($agentName)) {
109-
$builder->setAlias(AgentInterface::class, 'ai.agent.'.$agentName);
110-
}
111108

112109
foreach ($config['store'] ?? [] as $type => $store) {
113110
$this->processStoreConfig($type, $store, $builder);
@@ -441,6 +438,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
441438
;
442439

443440
$container->setDefinition('ai.agent.'.$name, $agentDefinition);
441+
$container->registerAliasForArgument('ai.agent.'.$name, AgentInterface::class, $name.'Agent');
444442
}
445443

446444
/**

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,21 @@ public function testExtensionLoadDoesNotThrow()
3030
$this->buildContainer($this->getFullConfig());
3131
}
3232

33+
public function testInjectionAgentAliasIsRegistered()
34+
{
35+
$container = $this->buildContainer([
36+
'ai' => [
37+
'agent' => [
38+
'my_agent' => [
39+
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
40+
],
41+
],
42+
],
43+
]);
44+
45+
$this->assertTrue($container->hasAlias('.Symfony\AI\Agent\AgentInterface $my_agentAgent'));
46+
}
47+
3348
#[TestWith([true], 'enabled')]
3449
#[TestWith([false], 'disabled')]
3550
public function testFaultTolerantAgentSpecificToolbox(bool $enabled)

0 commit comments

Comments
 (0)