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