Skip to content

Commit c27dafa

Browse files
committed
feature #349 Add tag for every agents (VincentLanglet)
This PR was merged into the main branch. Discussion ---------- Add tag for every agents | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no <!-- required for new features --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT This allows an easier manipulation of all agents with a CompilerPass and findTaggedServiceIds. This also allow to inject all agents with `AutowireIterator`. Commits ------- 49d5dbf Add tag for every agents
2 parents 48db6ae + 49d5dbf commit c27dafa

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/ai-bundle/src/AiBundle.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
380380

381381
// AGENT
382382
$agentDefinition = (new Definition(Agent::class))
383+
->addTag('ai.agent')
383384
->setArgument(0, new Reference($config['platform']))
384385
->setArgument(1, new Reference('ai.agent.'.$name.'.model'));
385386

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ public function testInjectionAgentAliasIsRegistered()
4949
$this->assertTrue($container->hasAlias('Symfony\AI\Agent\AgentInterface $myAgentAgent'));
5050
}
5151

52+
public function testAgentHasTag()
53+
{
54+
$container = $this->buildContainer([
55+
'ai' => [
56+
'agent' => [
57+
'my_agent' => [
58+
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
59+
],
60+
],
61+
],
62+
]);
63+
64+
$this->assertArrayHasKey('ai.agent.my_agent', $container->findTaggedServiceIds('ai.agent'));
65+
}
66+
5267
#[TestWith([true], 'enabled')]
5368
#[TestWith([false], 'disabled')]
5469
public function testFaultTolerantAgentSpecificToolbox(bool $enabled)

0 commit comments

Comments
 (0)