Skip to content

Commit 5f23535

Browse files
committed
[Examples] Use MemoryToolFactory pattern in platform-as-tool example
Updated platform-as-tool.php to follow the same pattern as agent-as-tool.php: - Use MemoryToolFactory to register tool with name and description - Use ChainFactory to combine MemoryToolFactory and ReflectionToolFactory - Provides better tool metadata for the agent
1 parent 4382dca commit 5f23535

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

examples/openai/platform-as-tool.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
use Symfony\AI\Agent\Toolbox\AgentProcessor;
1414
use Symfony\AI\Agent\Toolbox\Tool\Platform;
1515
use Symfony\AI\Agent\Toolbox\Toolbox;
16+
use Symfony\AI\Agent\Toolbox\ToolFactory\ChainFactory;
17+
use Symfony\AI\Agent\Toolbox\ToolFactory\MemoryToolFactory;
18+
use Symfony\AI\Agent\Toolbox\ToolFactory\ReflectionToolFactory;
1619
use Symfony\AI\Platform\Bridge\ElevenLabs\PlatformFactory as ElevenLabsPlatformFactory;
1720
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory;
1821
use Symfony\AI\Platform\Message\Content\Audio;
@@ -33,8 +36,22 @@
3336
// Wrap ElevenLabs platform as a tool
3437
$speechToText = new Platform($elevenLabsPlatform, 'scribe_v1');
3538

39+
// Use MemoryToolFactory to register the tool with metadata
40+
$memoryFactory = new MemoryToolFactory();
41+
$memoryFactory->addTool(
42+
$speechToText,
43+
'transcribe_audio',
44+
'Transcribes audio files to text using ElevenLabs speech-to-text. Accepts audio file content.',
45+
);
46+
47+
// Combine with ReflectionToolFactory using ChainFactory
48+
$chainFactory = new ChainFactory([
49+
$memoryFactory,
50+
new ReflectionToolFactory(),
51+
]);
52+
3653
// Create toolbox with the platform tool
37-
$toolbox = new Toolbox([$speechToText], logger: logger());
54+
$toolbox = new Toolbox([$speechToText], toolFactory: $chainFactory, logger: logger());
3855
$processor = new AgentProcessor($toolbox);
3956

4057
// Create agent with OpenAI platform but with ElevenLabs tool available

0 commit comments

Comments
 (0)