|
12 | 12 | use Symfony\AI\Agent\Agent;
|
13 | 13 | use Symfony\AI\Agent\Toolbox\AgentProcessor;
|
14 | 14 | use Symfony\AI\Agent\Toolbox\Tool\Platform as PlatformTool;
|
| 15 | +use Symfony\AI\Agent\Toolbox\Toolbox; |
15 | 16 | use Symfony\AI\Agent\Toolbox\ToolFactory\ChainFactory;
|
16 | 17 | use Symfony\AI\Agent\Toolbox\ToolFactory\MemoryToolFactory;
|
17 | 18 | use Symfony\AI\Agent\Toolbox\ToolFactory\ReflectionToolFactory;
|
18 |
| -use Symfony\AI\Agent\Toolbox\Toolbox; |
19 | 19 | use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory;
|
20 | 20 | use Symfony\AI\Platform\Message\Message;
|
21 | 21 | use Symfony\AI\Platform\Message\MessageBag;
|
|
24 | 24 |
|
25 | 25 | $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
|
26 | 26 |
|
27 |
| -// Create a specialized OpenAI platform tool using gpt-4o for complex analysis |
28 |
| -$analysisTool = new PlatformTool($platform, 'gpt-4o'); |
| 27 | +// Create a specialized OpenAI platform tool using gpt-4o for mathematical calculations |
| 28 | +$mathTool = new PlatformTool($platform, 'gpt-4o'); |
29 | 29 |
|
30 | 30 | // Use MemoryToolFactory to register the tool with metadata
|
31 | 31 | $memoryFactory = new MemoryToolFactory();
|
32 | 32 | $memoryFactory->addTool(
|
33 |
| - $analysisTool, |
34 |
| - 'advanced_analysis', |
35 |
| - 'Performs deep analysis and complex reasoning tasks using GPT-4o. Use this for tasks requiring sophisticated understanding.', |
| 33 | + $mathTool, |
| 34 | + 'calculate', |
| 35 | + 'Performs mathematical calculations using GPT-4o. Use this when you need to solve math problems or do arithmetic.', |
36 | 36 | );
|
37 | 37 |
|
38 | 38 | // Combine with ReflectionToolFactory using ChainFactory
|
|
42 | 42 | ]);
|
43 | 43 |
|
44 | 44 | // Create the main agent with gpt-4o-mini but with gpt-4o available as a tool
|
45 |
| -$toolbox = new Toolbox([$analysisTool], toolFactory: $chainFactory, logger: logger()); |
| 45 | +$toolbox = new Toolbox([$mathTool], toolFactory: $chainFactory, logger: logger()); |
46 | 46 | $processor = new AgentProcessor($toolbox);
|
47 | 47 | $agent = new Agent($platform, 'gpt-4o-mini', [$processor], [$processor], logger: logger());
|
48 | 48 |
|
49 |
| -// Ask a question that could benefit from advanced analysis |
| 49 | +// Ask a question that requires mathematical calculation |
50 | 50 | $result = $agent->call(new MessageBag(Message::ofUser(
|
51 |
| - 'Analyze the philosophical implications of artificial consciousness and whether current AI systems exhibit any form of genuine understanding. Provide a detailed analysis.' |
| 51 | + 'I have 15 apples and I want to share them equally among 4 friends. How many apples does each friend get and how many are left over?' |
52 | 52 | )));
|
53 | 53 |
|
54 | 54 | echo $result->getContent().\PHP_EOL;
|
0 commit comments