Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ai-bundle/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ the ``#[AsOutputProcessor]`` attributes::
use Symfony\AI\Agent\OutputProcessorInterface;

#[AsInputProcessor(priority: 99)] // This applies to every agent
#[AsOutputProcessor(agent: 'my_agent_id')] // The output processor will only be registered for 'my_agent_id'
#[AsOutputProcessor(agent: 'ai.agent.my_agent_name')] // The output processor will only be registered for 'ai.agent.my_agent_name'
final readonly class MyService implements InputProcessorInterface, OutputProcessorInterface
{
public function processInput(Input $input): void
Expand Down
21 changes: 11 additions & 10 deletions src/ai-bundle/src/AiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
$container->setDefinition('ai.agent.'.$name.'.model', $modelDefinition);

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

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

$container->getDefinition('ai.tool.agent_processor')
->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -10])
->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -10]);
->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -10])
->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -10]);
}
}

// STRUCTURED OUTPUT
if ($config['structured_output']) {
$container->getDefinition('ai.agent.structured_output_processor')
->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -20])
->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -20]);
->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -20])
->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -20]);
}

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

if ($container->hasDefinition('ai.platform.token_usage_processor.'.$platform)) {
$container->getDefinition('ai.platform.token_usage_processor.'.$platform)
->addTag('ai.agent.output_processor', ['agent' => $name, 'priority' => -30]);
->addTag('ai.agent.output_processor', ['agent' => $agentId, 'priority' => -30]);
}
}
}
Expand All @@ -568,7 +569,7 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
$config['include_tools'] ? new Reference('ai.toolbox.'.$name) : null,
new Reference('logger', ContainerInterface::IGNORE_ON_INVALID_REFERENCE),
])
->addTag('ai.agent.input_processor', ['agent' => $name, 'priority' => -30]);
->addTag('ai.agent.input_processor', ['agent' => $agentId, 'priority' => -30]);

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

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

/**
Expand Down