|
11 | 11 |
|
12 | 12 | use Symfony\AI\Agent\Agent; |
13 | 13 | use Symfony\AI\Agent\Toolbox\AgentProcessor; |
| 14 | +use Symfony\AI\Agent\Toolbox\Tool\Clock; |
14 | 15 | use Symfony\AI\Agent\Toolbox\Tool\Tavily; |
15 | 16 | use Symfony\AI\Agent\Toolbox\Toolbox; |
16 | 17 | use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory; |
17 | 18 | use Symfony\AI\Platform\Message\Message; |
18 | 19 | use Symfony\AI\Platform\Message\MessageBag; |
| 20 | +use Symfony\Component\Clock\Clock as SymfonyClock; |
19 | 21 |
|
20 | 22 | require_once dirname(__DIR__).'/bootstrap.php'; |
21 | 23 |
|
22 | 24 | $platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client()); |
23 | 25 |
|
| 26 | +$clock = new Clock(new SymfonyClock()); |
24 | 27 | $tavily = new Tavily(http_client(), env('TAVILY_API_KEY')); |
25 | | -$toolbox = new Toolbox([$tavily], logger: logger()); |
26 | | -$processor = new AgentProcessor($toolbox); |
27 | | -$agent = new Agent($platform, 'gpt-4o-mini', [$processor], [$processor]); |
| 28 | +$toolbox = new Toolbox([$clock, $tavily], logger: logger()); |
| 29 | +$processor = new AgentProcessor($toolbox, includeSources: true); |
| 30 | +$agent = new Agent($platform, 'gpt-4o', [$processor], [$processor]); |
28 | 31 |
|
29 | | -$messages = new MessageBag(Message::ofUser('What was the latest game result of Dallas Cowboys?')); |
30 | | -$result = $agent->call($messages); |
| 32 | +$prompt = <<<PROMPT |
| 33 | + Summarize the latest game of the Dallas Cowboys. When and where was it? Who was the opponent, what was the result, |
| 34 | + and how was the game and the weather in the city. Use tools for the research and only answer based on information |
| 35 | + given in the context - don't make up information. |
| 36 | + PROMPT; |
31 | 37 |
|
32 | | -echo $result->getContent().\PHP_EOL; |
| 38 | +$result = $agent->call(new MessageBag(Message::ofUser($prompt))); |
| 39 | + |
| 40 | +echo $result->getContent().\PHP_EOL.\PHP_EOL; |
| 41 | + |
| 42 | +echo 'Used sources:'.\PHP_EOL; |
| 43 | +foreach ($result->getMetadata()->get('sources', []) as $source) { |
| 44 | + echo sprintf(' - %s (%s)', $source->getName(), $source->getReference()).\PHP_EOL; |
| 45 | +} |
| 46 | +echo \PHP_EOL; |
0 commit comments