Skip to content

Commit 5ba97a6

Browse files
committed
bug #428 [AI-Bundle] Fix processor config (VincentLanglet)
This PR was squashed before being merged into the main branch. Discussion ---------- [AI-Bundle] Fix processor config | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | 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 Commits ------- 9018ed9 [AI-Bundle] Fix processor config
2 parents 299e1a7 + 9018ed9 commit 5ba97a6

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/ai-bundle/doc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ the ``#[AsOutputProcessor]`` attributes::
164164
use Symfony\AI\Agent\OutputProcessorInterface;
165165

166166
#[AsInputProcessor(priority: 99)] // This applies to every agent
167-
#[AsOutputProcessor(agent: 'my_agent_id')] // The output processor will only be registered for 'my_agent_id'
167+
#[AsOutputProcessor(agent: 'ai.agent.my_agent_name')] // The output processor will only be registered for 'ai.agent.my_agent_name'
168168
final readonly class MyService implements InputProcessorInterface, OutputProcessorInterface
169169
{
170170
public function processInput(Input $input): void

src/ai-bundle/src/AiBundle.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
456456
$container->setDefinition('ai.agent.'.$name.'.model', $modelDefinition);
457457

458458
// AGENT
459+
$agentId = 'ai.agent.'.$name;
459460
$agentDefinition = (new Definition(Agent::class))
460461
->addTag('ai.agent', ['name' => $name])
461462
->setArgument(0, new Reference($config['platform']))
@@ -516,8 +517,8 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
516517
->replaceArgument(0, new Reference('ai.toolbox.'.$name));
517518

518519
$container->setDefinition('ai.tool.agent_processor.'.$name, $toolProcessorDefinition)
519-
->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -10])
520-
->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -10]);
520+
->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -10])
521+
->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -10]);
521522
} else {
522523
if ($config['fault_tolerant_toolbox'] && !$container->hasDefinition('ai.fault_tolerant_toolbox')) {
523524
$container->setDefinition('ai.fault_tolerant_toolbox', new Definition(FaultTolerantToolbox::class))
@@ -526,16 +527,16 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
526527
}
527528

528529
$container->getDefinition('ai.tool.agent_processor')
529-
->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -10])
530-
->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -10]);
530+
->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -10])
531+
->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -10]);
531532
}
532533
}
533534

534535
// STRUCTURED OUTPUT
535536
if ($config['structured_output']) {
536537
$container->getDefinition('ai.agent.structured_output_processor')
537-
->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -20])
538-
->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -20]);
538+
->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -20])
539+
->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -20]);
539540
}
540541

541542
// TOKEN USAGE TRACKING
@@ -555,7 +556,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
555556

556557
if ($container->hasDefinition('ai.platform.token_usage_processor.'.$platform)) {
557558
$container->getDefinition('ai.platform.token_usage_processor.'.$platform)
558-
->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -30]);
559+
->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -30]);
559560
}
560561
}
561562
}
@@ -568,7 +569,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
568569
$config['include_tools'] ? new Reference('ai.toolbox.'.$name) : null,
569570
new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
570571
])
571-
->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -30]);
572+
->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -30]);
572573

573574
$container->setDefinition('ai.agent.'.$name.'.system_prompt_processor', $systemPromptInputProcessorDefinition);
574575
}
@@ -579,8 +580,8 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
579580
->setArgument(4, new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE))
580581
;
581582

582-
$container->setDefinition('ai.agent.'.$name, $agentDefinition);
583-
$container->registerAliasForArgument('ai.agent.'.$name, AgentInterface::class, (new Target($name.'Agent'))->getParsedName());
583+
$container->setDefinition($agentId, $agentDefinition);
584+
$container->registerAliasForArgument($agentId, AgentInterface::class, (new Target($name.'Agent'))->getParsedName());
584585
}
585586

586587
/**

0 commit comments

Comments
 (0)