Skip to content

Commit 98e4760

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 1cbb279 commit 98e4760

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
@@ -390,6 +390,12 @@
390390
->children()
391391
->stringNode('service')->cannotBeEmpty()->end()
392392
->stringNode('agent')->cannotBeEmpty()->end()
393+
->stringNode('platform')->cannotBeEmpty()->end()
394+
->stringNode('model')->cannotBeEmpty()->end()
395+
->arrayNode('options')
396+
->info('Options to pass to the platform')
397+
->scalarPrototype()->end()
398+
->end()
393399
->stringNode('name')->end()
394400
->stringNode('description')->end()
395401
->stringNode('method')->end()
@@ -401,8 +407,27 @@
401407
})
402408
->end()
403409
->validate()
404-
->ifTrue(static fn ($v) => !(empty($v['agent']) xor empty($v['service'])))
405-
->thenInvalid('Either "agent" or "service" must be configured, and never both.')
410+
->ifTrue(static function ($v) {
411+
$count = 0;
412+
if (!empty($v['agent'])) {
413+
++$count;
414+
}
415+
if (!empty($v['service'])) {
416+
++$count;
417+
}
418+
if (!empty($v['platform'])) {
419+
++$count;
420+
}
421+
422+
return 1 !== $count;
423+
})
424+
->thenInvalid('Exactly one of "agent", "service", or "platform" must be configured.')
425+
->end()
426+
->validate()
427+
->ifTrue(static function ($v) {
428+
return !empty($v['platform']) && empty($v['model']);
429+
})
430+
->thenInvalid('When "platform" is configured, "model" must also be provided.')
406431
->end()
407432
->end()
408433
->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;
@@ -589,6 +590,17 @@ private function processAgentConfig(string $name, array $config, ContainerBuilde
589590
if (isset($tool['agent'])) {
590591
$tool['name'] ??= $tool['agent'];
591592
$tool['service'] = \sprintf('ai.agent.%s', $tool['agent']);
593+
} elseif (isset($tool['platform'])) {
594+
$tool['name'] ??= $tool['platform'].'_'.$tool['model'];
595+
$platformReference = new Reference(\sprintf('ai.platform.%s', $tool['platform']));
596+
$platformWrapperDefinition = new Definition(PlatformTool::class, [
597+
$platformReference,
598+
$tool['model'],
599+
$tool['options'] ?? [],
600+
]);
601+
$wrapperServiceId = 'ai.toolbox.'.$name.'.platform_wrapper.'.$tool['name'];
602+
$container->setDefinition($wrapperServiceId, $platformWrapperDefinition);
603+
$tool['service'] = $wrapperServiceId;
592604
}
593605
$reference = new Reference($tool['service']);
594606
// We use the memory factory in case method, description and name are set

0 commit comments

Comments
 (0)