Skip to content

Commit 00c52a8

Browse files
committed
minor #545 [Run examples] Remove usage of Agent when not needed (MelaineGerard)
This PR was squashed before being merged into the main branch. Discussion ---------- [Run examples] Remove usage of `Agent` when not needed | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | Fix #522 | License | MIT Remove usage of agents when not needed Tasklist : - [x] Albert - [x] Anthropic - [x] Azure - [x] Bedrock - [x] Cerebras - [x] Commands - [x] Document - [x] ElevenLabs - [x] Gemini - [x] HuggingFace - [x] Indexer - [x] LMStudio - [x] Memory - [x] Misc - [x] Mistral - [x] Ollama - [x] OpenAI - [x] OpenRouter - [x] Perplexity - [x] Rag - [x] Replicate - [x] Toolbox - [x] Transformers - [x] VertexAI - [x] Voyage Commits ------- 9a6bf94 [Run examples] Remove usage of `Agent` when not needed
2 parents 9eb72bc + 9a6bf94 commit 00c52a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+100
-199
lines changed

examples/albert/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\Albert\PlatformFactory;
1413
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
1514
use Symfony\AI\Platform\Message\Message;
@@ -20,7 +19,6 @@
2019
$platform = PlatformFactory::create(env('ALBERT_API_KEY'), env('ALBERT_API_URL'), http_client());
2120

2221
$model = new Gpt('gpt-4o');
23-
$agent = new Agent($platform, $model, logger: logger());
2422

2523
$documentContext = <<<'CONTEXT'
2624
Document: AI Strategy of France
@@ -44,6 +42,6 @@
4442
Message::ofUser('What are the main objectives of France\'s AI strategy?'),
4543
);
4644

47-
$result = $agent->call($messages);
45+
$result = $platform->invoke($model, $messages);
4846

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

examples/anthropic/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\Anthropic\Claude;
1413
use Symfony\AI\Platform\Bridge\Anthropic\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Message;
@@ -20,11 +19,10 @@
2019
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
2120
$model = new Claude(Claude::SONNET_37);
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

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

examples/anthropic/image-input-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\Anthropic\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Content\Image;
@@ -21,14 +20,13 @@
2120
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
2221
$model = new Claude(Claude::SONNET_37);
2322

24-
$agent = new Agent($platform, $model, logger: logger());
2523
$messages = new MessageBag(
2624
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
2725
Message::ofUser(
2826
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
2927
'Describe this image.',
3028
),
3129
);
32-
$result = $agent->call($messages);
30+
$result = $platform->invoke($model, $messages);
3331

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

examples/anthropic/image-input-url.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\Anthropic\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Content\ImageUrl;
@@ -21,14 +20,13 @@
2120
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
2221
$model = new Claude(Claude::SONNET_37);
2322

24-
$agent = new Agent($platform, $model, logger: logger());
2523
$messages = new MessageBag(
2624
Message::forSystem('You are an image analyzer bot that helps identify the content of images.'),
2725
Message::ofUser(
2826
new ImageUrl('https://upload.wikimedia.org/wikipedia/commons/a/a7/Camponotus_flavomarginatus_ant.jpg'),
2927
'Describe this image.',
3028
),
3129
);
32-
$result = $agent->call($messages);
30+
$result = $platform->invoke($model, $messages);
3331

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

examples/anthropic/pdf-input-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\Anthropic\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Content\Document;
@@ -21,13 +20,12 @@
2120
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
2221
$model = new Claude(Claude::SONNET_37);
2322

24-
$agent = new Agent($platform, $model, logger: logger());
2523
$messages = new MessageBag(
2624
Message::ofUser(
2725
Document::fromFile(dirname(__DIR__, 2).'/fixtures/document.pdf'),
2826
'What is this document about?',
2927
),
3028
);
31-
$result = $agent->call($messages);
29+
$result = $platform->invoke($model, $messages);
3230

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

examples/anthropic/pdf-input-url.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\Anthropic\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Content\DocumentUrl;
@@ -21,13 +20,12 @@
2120
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
2221
$model = new Claude(Claude::SONNET_37);
2322

24-
$agent = new Agent($platform, $model, logger: logger());
2523
$messages = new MessageBag(
2624
Message::ofUser(
2725
new DocumentUrl('https://upload.wikimedia.org/wikipedia/commons/2/20/Re_example.pdf'),
2826
'What is this document about?',
2927
),
3028
);
31-
$result = $agent->call($messages);
29+
$result = $platform->invoke($model, $messages);
3230

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

examples/anthropic/stream.php

Lines changed: 2 additions & 6 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\Anthropic\PlatformFactory;
1514
use Symfony\AI\Platform\Message\Message;
@@ -20,16 +19,13 @@
2019
$platform = PlatformFactory::create(env('ANTHROPIC_API_KEY'), httpClient: http_client());
2120
$model = new Claude();
2221

23-
$agent = new Agent($platform, $model, logger: logger());
2422
$messages = new MessageBag(
2523
Message::forSystem('You are a thoughtful philosopher.'),
2624
Message::ofUser('What is the purpose of an ant?'),
2725
);
28-
$result = $agent->call($messages, [
29-
'stream' => true, // enable streaming of response text
30-
]);
26+
$result = $platform->invoke($model, $messages, ['stream' => true]);
3127

32-
foreach ($result->getContent() as $word) {
28+
foreach ($result->getResult()->getContent() as $word) {
3329
echo $word;
3430
}
3531
echo \PHP_EOL;

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;

0 commit comments

Comments
 (0)