Skip to content

Commit 02fb8e3

Browse files
committed
[AiBundle] Add configuration support for platform tools
Platforms can now be configured as tools in agent definitions: ai: agent: my_agent: tools: - platform: 'elevenlabs' model: 'scribe_v1' name: 'transcribe_audio' description: 'Transcribes audio files to text' options: [] This allows agents to use specialized platforms as tools, enabling scenarios like an OpenAI agent using ElevenLabs for speech-to-text.
1 parent 9a47a8a commit 02fb8e3

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

src/ai-bundle/config/options.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,12 @@
391391
->children()
392392
->stringNode('service')->cannotBeEmpty()->end()
393393
->stringNode('agent')->cannotBeEmpty()->end()
394+
->stringNode('platform')->cannotBeEmpty()->end()
395+
->stringNode('model')->cannotBeEmpty()->end()
396+
->arrayNode('options')
397+
->info('Options to pass to the platform')
398+
->scalarPrototype()->end()
399+
->end()
394400
->stringNode('name')->end()
395401
->stringNode('description')->end()
396402
->stringNode('method')->end()
@@ -402,8 +408,27 @@
402408
})
403409
->end()
404410
->validate()
405-
->ifTrue(static fn ($v) => !(empty($v['agent']) xor empty($v['service'])))
406-
->thenInvalid('Either "agent" or "service" must be configured, and never both.')
411+
->ifTrue(static function ($v) {
412+
$count = 0;
413+
if (!empty($v['agent'])) {
414+
++$count;
415+
}
416+
if (!empty($v['service'])) {
417+
++$count;
418+
}
419+
if (!empty($v['platform'])) {
420+
++$count;
421+
}
422+
423+
return 1 !== $count;
424+
})
425+
->thenInvalid('Exactly one of "agent", "service", or "platform" must be configured.')
426+
->end()
427+
->validate()
428+
->ifTrue(static function ($v) {
429+
return !empty($v['platform']) && empty($v['model']);
430+
})
431+
->thenInvalid('When "platform" is configured, "model" must also be provided.')
407432
->end()
408433
->end()
409434
->end()

src/ai-bundle/src/AiBundle.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Symfony\AI\Agent\Toolbox\Attribute\AsTool;
2828
use Symfony\AI\Agent\Toolbox\FaultTolerantToolbox;
2929
use Symfony\AI\Agent\Toolbox\Tool\Agent as AgentTool;
30+
use Symfony\AI\Agent\Toolbox\Tool\Platform as PlatformTool;
3031
use Symfony\AI\Agent\Toolbox\ToolFactory\ChainFactory;
3132
use Symfony\AI\Agent\Toolbox\ToolFactory\MemoryToolFactory;
3233
use Symfony\AI\AiBundle\DependencyInjection\ProcessorCompilerPass;
@@ -637,6 +638,17 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
637638
if (isset($tool['agent'])) {
638639
$tool['name'] ??= $tool['agent'];
639640
$tool['service'] = \sprintf('ai.agent.%s', $tool['agent']);
641+
} elseif (isset($tool['platform'])) {
642+
$tool['name'] ??= $tool['platform'].'_'.$tool['model'];
643+
$platformReference = new Reference(\sprintf('ai.platform.%s', $tool['platform']));
644+
$platformWrapperDefinition = new Definition(PlatformTool::class, [
645+
$platformReference,
646+
$tool['model'],
647+
$tool['options'] ?? [],
648+
]);
649+
$wrapperServiceId = 'ai.toolbox.'.$name.'.platform_wrapper.'.$tool['name'];
650+
$container->setDefinition($wrapperServiceId, $platformWrapperDefinition);
651+
$tool['service'] = $wrapperServiceId;
640652
}
641653
$reference = new Reference($tool['service']);
642654
// We use the memory factory in case method, description and name are set

0 commit comments

Comments
 (0)