Skip to content

[Platform][Agent] Rework Platform API to invoke and result #154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions demo/src/Audio/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Platform\PlatformInterface;
use Symfony\AI\Platform\Response\TextResponse;
use Symfony\AI\Platform\Result\TextResult;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\RequestStack;

Expand All @@ -39,9 +39,9 @@ public function say(string $base64audio): void
$path = tempnam(sys_get_temp_dir(), 'audio-').'.wav';
file_put_contents($path, base64_decode($base64audio));

$response = $this->platform->request(new Whisper(), Audio::fromFile($path));
$result = $this->platform->invoke(new Whisper(), Audio::fromFile($path));

$this->submitMessage($response->asText());
$this->submitMessage($result->asText());
}

public function loadMessages(): MessageBag
Expand All @@ -54,11 +54,11 @@ public function submitMessage(string $message): void
$messages = $this->loadMessages();

$messages->add(Message::ofUser($message));
$response = $this->agent->call($messages);
$result = $this->agent->call($messages);

\assert($response instanceof TextResponse);
\assert($result instanceof TextResult);

$messages->add(Message::ofAssistant($response->getContent()));
$messages->add(Message::ofAssistant($result->getContent()));

$this->saveMessages($messages);
}
Expand Down
8 changes: 4 additions & 4 deletions demo/src/Blog/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Symfony\AI\Agent\AgentInterface;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Platform\Response\TextResponse;
use Symfony\AI\Platform\Result\TextResult;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\RequestStack;

Expand Down Expand Up @@ -49,11 +49,11 @@ public function submitMessage(string $message): void
$messages = $this->loadMessages();

$messages->add(Message::ofUser($message));
$response = $this->agent->call($messages);
$result = $this->agent->call($messages);

\assert($response instanceof TextResponse);
\assert($result instanceof TextResult);

$messages->add(Message::ofAssistant($response->getContent()));
$messages->add(Message::ofAssistant($result->getContent()));

$this->saveMessages($messages);
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/Blog/Command/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->comment(\sprintf('Converting "%s" to vector & searching in Chroma DB ...', $search));
$io->comment('Results are limited to 4 most similar documents.');

$platformResponse = $this->platform->request(new Embeddings(), $search);
$platformResponse = $this->platform->invoke(new Embeddings(), $search);
$queryResponse = $collection->query(
queryEmbeddings: [$platformResponse->asVectors()[0]->getData()],
nResults: 4,
Expand Down
4 changes: 2 additions & 2 deletions demo/src/Blog/FeedLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public function __construct(
*/
public function load(): array
{
$response = $this->httpClient->request('GET', 'https://feeds.feedburner.com/symfony/blog');
$result = $this->httpClient->request('GET', 'https://feeds.feedburner.com/symfony/blog');

$posts = [];
$crawler = new Crawler($response->getContent());
$crawler = new Crawler($result->getContent());
$crawler->filter('item')->each(function (Crawler $node) use (&$posts) {
$title = $node->filter('title')->text();
$posts[] = new Post(
Expand Down
4 changes: 2 additions & 2 deletions demo/src/Video/TwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ public function submit(#[LiveArg] string $instruction, #[LiveArg] string $image)
Message::ofUser($instruction, Image::fromDataUrl($image))
);

$response = $this->platform->request(new GPT(GPT::GPT_4O_MINI), $messageBag, [
$result = $this->platform->invoke(new GPT(GPT::GPT_4O_MINI), $messageBag, [
'max_tokens' => 100,
]);

$this->caption = $response->asText();
$this->caption = $result->asText();
}
}
8 changes: 4 additions & 4 deletions demo/src/Wikipedia/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Symfony\AI\Agent\AgentInterface;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Platform\Response\TextResponse;
use Symfony\AI\Platform\Result\TextResult;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\RequestStack;

Expand All @@ -39,11 +39,11 @@ public function submitMessage(string $message): void
$messages = $this->loadMessages();

$messages->add(Message::ofUser($message));
$response = $this->agent->call($messages);
$result = $this->agent->call($messages);

\assert($response instanceof TextResponse);
\assert($result instanceof TextResult);

$messages->add(Message::ofAssistant($response->getContent()));
$messages->add(Message::ofAssistant($result->getContent()));

$this->saveMessages($messages);
}
Expand Down
8 changes: 4 additions & 4 deletions demo/src/YouTube/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Symfony\AI\Agent\AgentInterface;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Platform\Response\TextResponse;
use Symfony\AI\Platform\Result\TextResult;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\RequestStack;

Expand Down Expand Up @@ -61,11 +61,11 @@ public function submitMessage(string $message): void
$messages = $this->loadMessages();

$messages->add(Message::ofUser($message));
$response = $this->agent->call($messages);
$result = $this->agent->call($messages);

\assert($response instanceof TextResponse);
\assert($result instanceof TextResult);

$messages->add(Message::ofAssistant($response->getContent()));
$messages->add(Message::ofAssistant($result->getContent()));

$this->saveMessages($messages);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/albert/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
Message::ofUser('What are the main objectives of France\'s AI strategy?'),
);

$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/anthropic/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/anthropic/image-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
'Describe this image.',
),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/anthropic/image-input-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
'Describe this image.',
),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/anthropic/pdf-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
'What is this document about?',
),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/anthropic/pdf-input-url.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
'What is this document about?',
),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/anthropic/stream.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
Message::forSystem('You are a thoughtful philosopher.'),
Message::ofUser('What is the purpose of an ant?'),
);
$response = $agent->call($messages, [
$result = $agent->call($messages, [
'stream' => true, // enable streaming of response text
]);

foreach ($response->getContent() as $word) {
foreach ($result->getContent() as $word) {
echo $word;
}
echo \PHP_EOL;
4 changes: 2 additions & 2 deletions examples/anthropic/toolcall.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
$agent = new Agent($platform, $model, [$processor], [$processor], logger());

$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/azure/audio-transcript.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
$model = new Whisper();
$file = Audio::fromFile(dirname(__DIR__, 2).'/fixtures/audio.mp3');

$response = $platform->request($model, $file);
$result = $platform->invoke($model, $file);

echo $response->asText().\PHP_EOL;
echo $result->asText().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/azure/chat-gpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/azure/chat-llama.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

$agent = new Agent($platform, $model, logger: logger());
$messages = new MessageBag(Message::ofUser('I am going to Paris, what should I see?'));
$response = $agent->call($messages, [
$result = $agent->call($messages, [
'max_tokens' => 2048,
'temperature' => 0.8,
'top_p' => 0.1,
'presence_penalty' => 0,
'frequency_penalty' => 0,
]);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/azure/embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
);
$embeddings = new Embeddings();

$response = $platform->request($embeddings, <<<TEXT
$result = $platform->invoke($embeddings, <<<TEXT
Once upon a time, there was a country called Japan. It was a beautiful country with a lot of mountains and rivers.
The people of Japan were very kind and hardworking. They loved their country very much and took care of it. The
country was very peaceful and prosperous. The people lived happily ever after.
TEXT);

echo 'Dimensions: '.$response->asVectors()[0]->getDimensions().\PHP_EOL;
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/bedrock/chat-claude.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
Message::forSystem('You answer questions in short and concise manner.'),
Message::ofUser('What is the Symfony framework?'),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/bedrock/chat-llama.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/bedrock/chat-nova.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/bedrock/image-claude-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/bedrock/image-nova.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/bedrock/toolcall-claude.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@
$agent = new Agent($platform, $model, [$processor], [$processor], logger());

$messages = new MessageBag(Message::ofUser('Who is the current chancellor of Germany?'));
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/bedrock/toolcall-nova.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
$messages = new MessageBag(
Message::ofUser('Who is the current chancellor of Germany? Use Wikipedia to find the answer.')
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/google/audio-input.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
Audio::fromFile(dirname(__DIR__, 2).'/fixtures/audio.mp3'),
),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/google/chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
Message::forSystem('You are a pirate and you write funny.'),
Message::ofUser('What is the Symfony framework?'),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/google/embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
$platform = PlatformFactory::create(env('GEMINI_API_KEY'), http_client());
$embeddings = new Embeddings();

$response = $platform->request($embeddings, <<<TEXT
$result = $platform->invoke($embeddings, <<<TEXT
Once upon a time, there was a country called Japan. It was a beautiful country with a lot of mountains and rivers.
The people of Japan were very kind and hardworking. They loved their country very much and took care of it. The
country was very peaceful and prosperous. The people lived happily ever after.
TEXT);

echo 'Dimensions: '.$response->asVectors()[0]->getDimensions().\PHP_EOL;
echo 'Dimensions: '.$result->asVectors()[0]->getDimensions().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/google/image-input.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
Image::fromFile(dirname(__DIR__, 2).'/fixtures/image.jpg'),
),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/google/pdf-input-binary.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
'What is this document about?',
),
);
$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions examples/google/server-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
),
);

$response = $agent->call($messages);
$result = $agent->call($messages);

echo $response->getContent().\PHP_EOL;
echo $result->getContent().\PHP_EOL;
Loading