Skip to content

Commit 7804187

Browse files
committed
💄 Remove usage of agent when not needed on :
- Azure - Bedrock
1 parent 7b188c7 commit 7804187

File tree

9 files changed

+18
-34
lines changed

9 files changed

+18
-34
lines changed

examples/azure/chat-gpt.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use Symfony\AI\Agent\Agent;
1312
use Symfony\AI\Platform\Bridge\Azure\OpenAi\PlatformFactory;
1413
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
1514
use Symfony\AI\Platform\Message\Message;
@@ -26,11 +25,10 @@
2625
);
2726
$model = new Gpt(Gpt::GPT_4O_MINI);
2827

29-
$agent = new Agent($platform, $model, logger: logger());
3028
$messages = new MessageBag(
3129
Message::forSystem('You are a pirate and you write funny.'),
3230
Message::ofUser('What is the Symfony framework?'),
3331
);
34-
$result = $agent->call($messages);
32+
$result = $platform->invoke($model, $messages);
3533

36-
echo $result->getContent().\PHP_EOL;
34+
echo $result->getResult()->getContent().\PHP_EOL;

examples/azure/chat-llama.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use Symfony\AI\Agent\Agent;
1312
use Symfony\AI\Platform\Bridge\Azure\Meta\PlatformFactory;
1413
use Symfony\AI\Platform\Bridge\Meta\Llama;
1514
use Symfony\AI\Platform\Message\Message;
@@ -20,14 +19,13 @@
2019
$platform = PlatformFactory::create(env('AZURE_LLAMA_BASEURL'), env('AZURE_LLAMA_KEY'), http_client());
2120
$model = new Llama(Llama::V3_3_70B_INSTRUCT);
2221

23-
$agent = new Agent($platform, $model, logger: logger());
2422
$messages = new MessageBag(Message::ofUser('I am going to Paris, what should I see?'));
25-
$result = $agent->call($messages, [
23+
$result = $platform->invoke($model, $messages, [
2624
'max_tokens' => 2048,
2725
'temperature' => 0.8,
2826
'top_p' => 0.1,
2927
'presence_penalty' => 0,
3028
'frequency_penalty' => 0,
3129
]);
3230

33-
echo $result->getContent().\PHP_EOL;
31+
echo $result->getResult()->getContent().\PHP_EOL;

examples/bedrock/chat-claude.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use Symfony\AI\Agent\Agent;
1312
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
1413
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Message;
@@ -26,11 +25,10 @@
2625
$platform = PlatformFactory::create();
2726
$model = new Claude('claude-3-7-sonnet-20250219');
2827

29-
$agent = new Agent($platform, $model, logger: logger());
3028
$messages = new MessageBag(
3129
Message::forSystem('You answer questions in short and concise manner.'),
3230
Message::ofUser('What is the Symfony framework?'),
3331
);
34-
$result = $agent->call($messages);
32+
$result = $platform->invoke($model, $messages);
3533

36-
echo $result->getContent().\PHP_EOL;
34+
echo $result->getResult()->getContent().\PHP_EOL;

examples/bedrock/chat-llama.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use Symfony\AI\Agent\Agent;
1312
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory;
1413
use Symfony\AI\Platform\Bridge\Meta\Llama;
1514
use Symfony\AI\Platform\Message\Message;
@@ -26,11 +25,10 @@
2625
$platform = PlatformFactory::create();
2726
$model = new Llama(Llama::V3_2_3B_INSTRUCT);
2827

29-
$agent = new Agent($platform, $model, logger: logger());
3028
$messages = new MessageBag(
3129
Message::forSystem('You are a pirate and you write funny.'),
3230
Message::ofUser('What is the Symfony framework?'),
3331
);
34-
$result = $agent->call($messages);
32+
$result = $platform->invoke($model, $messages);
3533

36-
echo $result->getContent().\PHP_EOL;
34+
echo $result->getResult()->getContent().\PHP_EOL;

examples/bedrock/chat-nova.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use Symfony\AI\Agent\Agent;
1312
use Symfony\AI\Platform\Bridge\Bedrock\Nova\Nova;
1413
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Message;
@@ -26,11 +25,10 @@
2625
$platform = PlatformFactory::create();
2726
$model = new Nova(Nova::PRO);
2827

29-
$agent = new Agent($platform, $model, logger: logger());
3028
$messages = new MessageBag(
3129
Message::forSystem('You are a pirate and you write funny.'),
3230
Message::ofUser('What is the Symfony framework?'),
3331
);
34-
$result = $agent->call($messages);
32+
$result = $platform->invoke($model, $messages);
3533

36-
echo $result->getContent().\PHP_EOL;
34+
echo $result->getResult()->getContent().\PHP_EOL;

examples/bedrock/image-claude-binary.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use Symfony\AI\Agent\Agent;
1312
use Symfony\AI\Platform\Bridge\Anthropic\Claude;
1413
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Content\Image;
@@ -27,14 +26,13 @@
2726
$platform = PlatformFactory::create();
2827
$model = new Claude('claude-3-7-sonnet-20250219');
2928

30-
$agent = new Agent($platform, $model, logger: logger());
3129
$messages = new MessageBag(
3230
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
3331
Message::ofUser(
3432
'Describe the image as a comedian would do it.',
3533
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
3634
),
3735
);
38-
$result = $agent->call($messages);
36+
$result = $platform->invoke($model, $messages);
3937

40-
echo $result->getContent().\PHP_EOL;
38+
echo $result->getResult()->getContent().\PHP_EOL;

examples/bedrock/image-nova.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use Symfony\AI\Agent\Agent;
1312
use Symfony\AI\Platform\Bridge\Bedrock\Nova\Nova;
1413
use Symfony\AI\Platform\Bridge\Bedrock\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Content\Image;
@@ -27,14 +26,13 @@
2726
$platform = PlatformFactory::create();
2827
$model = new Nova(Nova::PRO);
2928

30-
$agent = new Agent($platform, $model, logger: logger());
3129
$messages = new MessageBag(
3230
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
3331
Message::ofUser(
3432
'Describe the image as a comedian would do it.',
3533
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
3634
),
3735
);
38-
$result = $agent->call($messages);
36+
$result = $platform->invoke($model, $messages);
3937

40-
echo $result->getContent().\PHP_EOL;
38+
echo $result->getResult()->getContent().\PHP_EOL;

examples/lmstudio/chat.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
use Symfony\AI\Agent\Agent;
1312
use Symfony\AI\Platform\Bridge\LmStudio\Completions;
1413
use Symfony\AI\Platform\Bridge\LmStudio\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Message;
@@ -20,13 +19,12 @@
2019
$platform = PlatformFactory::create(env('LMSTUDIO_HOST_URL'), http_client());
2120
$model = new Completions('gemma-3-4b-it-qat');
2221

23-
$agent = new Agent($platform, $model, logger: logger());
2422
$messages = new MessageBag(
2523
Message::forSystem('You are a pirate and you write funny.'),
2624
Message::ofUser('What is the Symfony framework?'),
2725
);
28-
$result = $agent->call($messages, [
26+
$result = $platform->invoke($model, $messages, [
2927
'max_tokens' => 500, // specific options just for this call
3028
]);
3129

32-
echo $result->getContent().\PHP_EOL;
30+
echo $result->getResult()->getContent().\PHP_EOL;

examples/lmstudio/image-input-binary.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
3434
),
3535
);
36-
$result = $agent->call($messages);
36+
$result = $platform->invoke($model, $messages);
3737

38-
echo $result->getContent().\PHP_EOL;
38+
echo $result->getResult()->getContent().\PHP_EOL;

0 commit comments

Comments
 (0)