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
10 changes: 7 additions & 3 deletions src/ai-bundle/src/AiBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,11 +356,9 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
$container->setDefinition('ai.toolbox.'.$name, $toolboxDefinition);

if ($config['fault_tolerant_toolbox']) {
$faultTolerantToolboxDefinition = (new Definition('ai.fault_tolerant_toolbox.'.$name))
->setClass(FaultTolerantToolbox::class)
$container->setDefinition('ai.fault_tolerant_toolbox.'.$name, new Definition(FaultTolerantToolbox::class))
->setArguments([new Reference('.inner')])
->setDecoratedService('ai.toolbox.'.$name);
$container->setDefinition('ai.fault_tolerant_toolbox.'.$name, $faultTolerantToolboxDefinition);
}

if ($container->getParameter('kernel.debug')) {
Expand All @@ -379,6 +377,12 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
$inputProcessors[] = new Reference('ai.tool.agent_processor.'.$name);
$outputProcessors[] = new Reference('ai.tool.agent_processor.'.$name);
} else {
if ($config['fault_tolerant_toolbox'] && !$container->hasDefinition('ai.fault_tolerant_toolbox')) {
$container->setDefinition('ai.fault_tolerant_toolbox', new Definition(FaultTolerantToolbox::class))
->setArguments([new Reference('.inner')])
->setDecoratedService('ai.toolbox');
}

$inputProcessors[] = new Reference('ai.tool.agent_processor');
$outputProcessors[] = new Reference('ai.tool.agent_processor');
}
Expand Down
41 changes: 41 additions & 0 deletions src/ai-bundle/tests/DependencyInjection/AiBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\AI\AiBundle\AiBundle;
Expand All @@ -29,6 +30,46 @@ public function testExtensionLoadDoesNotThrow()
$this->buildContainer($this->getFullConfig());
}

#[TestWith([true], 'enabled')]
#[TestWith([false], 'disabled')]
public function testFaultTolerantAgentSpecificToolbox(bool $enabled)
{
$container = $this->buildContainer([
'ai' => [
'agent' => [
'my_agent' => [
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
'tools' => [
['service' => 'some_service', 'description' => 'Some tool'],
],
'fault_tolerant_toolbox' => $enabled,
],
],
],
]);

$this->assertSame($enabled, $container->hasDefinition('ai.fault_tolerant_toolbox.my_agent'));
}

#[TestWith([true], 'enabled')]
#[TestWith([false], 'disabled')]
public function testFaultTolerantDefaultToolbox(bool $enabled)
{
$container = $this->buildContainer([
'ai' => [
'agent' => [
'my_agent' => [
'model' => ['class' => 'Symfony\AI\Platform\Bridge\OpenAi\Gpt'],
'tools' => true,
'fault_tolerant_toolbox' => $enabled,
],
],
],
]);

$this->assertSame($enabled, $container->hasDefinition('ai.fault_tolerant_toolbox'));
}

public function testAgentsCanBeRegisteredAsTools()
{
$container = $this->buildContainer([
Expand Down