Skip to content

Commit d7aa851

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 2d94d16 commit d7aa851

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
@@ -389,6 +389,12 @@
389389
->children()
390390
->stringNode('service')->cannotBeEmpty()->end()
391391
->stringNode('agent')->cannotBeEmpty()->end()
392+
->stringNode('platform')->cannotBeEmpty()->end()
393+
->stringNode('model')->cannotBeEmpty()->end()
394+
->arrayNode('options')
395+
->info('Options to pass to the platform')
396+
->scalarPrototype()->end()
397+
->end()
392398
->stringNode('name')->end()
393399
->stringNode('description')->end()
394400
->stringNode('method')->end()
@@ -400,8 +406,27 @@
400406
})
401407
->end()
402408
->validate()
403-
->ifTrue(static fn ($v) => !(empty($v['agent']) xor empty($v['service'])))
404-
->thenInvalid('Either "agent" or "service" must be configured, and never both.')
409+
->ifTrue(static function ($v) {
410+
$count = 0;
411+
if (!empty($v['agent'])) {
412+
++$count;
413+
}
414+
if (!empty($v['service'])) {
415+
++$count;
416+
}
417+
if (!empty($v['platform'])) {
418+
++$count;
419+
}
420+
421+
return 1 !== $count;
422+
})
423+
->thenInvalid('Exactly one of "agent", "service", or "platform" must be configured.')
424+
->end()
425+
->validate()
426+
->ifTrue(static function ($v) {
427+
return !empty($v['platform']) && empty($v['model']);
428+
})
429+
->thenInvalid('When "platform" is configured, "model" must also be provided.')
405430
->end()
406431
->end()
407432
->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;
@@ -567,6 +568,17 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
567568
if (isset($tool['agent'])) {
568569
$tool['name'] ??= $tool['agent'];
569570
$tool['service'] = \sprintf('ai.agent.%s', $tool['agent']);
571+
} elseif (isset($tool['platform'])) {
572+
$tool['name'] ??= $tool['platform'].'_'.$tool['model'];
573+
$platformReference = new Reference(\sprintf('ai.platform.%s', $tool['platform']));
574+
$platformWrapperDefinition = new Definition(PlatformTool::class, [
575+
$platformReference,
576+
$tool['model'],
577+
$tool['options'] ?? [],
578+
]);
579+
$wrapperServiceId = 'ai.toolbox.'.$name.'.platform_wrapper.'.$tool['name'];
580+
$container->setDefinition($wrapperServiceId, $platformWrapperDefinition);
581+
$tool['service'] = $wrapperServiceId;
570582
}
571583
$reference = new Reference($tool['service']);
572584
// We use the memory factory in case method, description and name are set

0 commit comments

Comments
 (0)