Skip to content

Commit b4eedec

Browse files
committed
[Agent] Simplify Platform tool by using asText() method
Removed explicit await() and result type matching by using the ResultPromise::asText() convenience method which handles the await internally and extracts text content directly.
1 parent d7aa851 commit b4eedec

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/agent/src/Toolbox/Tool/Platform.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
namespace Symfony\AI\Agent\Toolbox\Tool;
1313

1414
use Symfony\AI\Platform\PlatformInterface;
15-
use Symfony\AI\Platform\Result\AudioResult;
16-
use Symfony\AI\Platform\Result\ImageResult;
17-
use Symfony\AI\Platform\Result\TextResult;
1815

1916
/**
2017
* Wraps a Platform instance as a tool, allowing agents to use specialized platforms for specific tasks.
@@ -41,17 +38,10 @@ public function __construct(
4138
*/
4239
public function __invoke(array|string|object $input): string
4340
{
44-
$result = $this->platform->invoke(
41+
return $this->platform->invoke(
4542
$this->model,
4643
$input,
4744
$this->options,
48-
)->await();
49-
50-
return match (true) {
51-
$result instanceof TextResult => $result->getContent(),
52-
$result instanceof AudioResult => $result->getText() ?? base64_encode($result->getAudio()),
53-
$result instanceof ImageResult => $result->getText() ?? base64_encode($result->getImage()),
54-
default => throw new \LogicException(\sprintf('Unsupported result type "%s".', $result::class)),
55-
};
45+
)->asText();
5646
}
5747
}

0 commit comments

Comments
 (0)