Skip to content

Commit 7a73288

Browse files
committed
feat(aibundle): injection alias added
1 parent 5aca06b commit 7a73288

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
@@ -102,9 +102,6 @@ public function loadExtension(array $config, ContainerConfigurator $container, C
102102
foreach ($config['agent'] as $agentName => $agent) {
103103
$this->processAgentConfig($agentName, $agent, $builder);
104104
}
105-
if (1 === \count($config['agent']) && isset($agentName)) {
106-
$builder->setAlias(AgentInterface::class, 'ai.agent.'.$agentName);
107-
}
108105

109106
foreach ($config['store'] ?? [] as $type => $store) {
110107
$this->processStoreConfig($type, $store, $builder);
@@ -438,6 +435,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
438435
;
439436

440437
$container->setDefinition('ai.agent.'.$name, $agentDefinition);
438+
$container->registerAliasForArgument('ai.agent.'.$name, AgentInterface::class, $name.'Agent');
441439
}
442440

443441
/**

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)