Skip to content

Commit 1b58da5

Browse files
committed
Update Vertexai bridge as well
1 parent 847aa89 commit 1b58da5

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

examples/vertexai/toolcall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
$toolbox = new Toolbox([new Clock()], logger: logger());
2525
$processor = new AgentProcessor($toolbox);
26-
$agent = new Agent($platform, 'gemini-2.0-flash-lite', [$processor], [$processor], logger: logger());
26+
$agent = new Agent($platform, 'gemini-2.5-flash-lite', [$processor], [$processor], logger: logger());
2727

2828
$messages = new MessageBag(Message::ofUser('What time is it?'));
2929
$result = $agent->call($messages);

src/platform/src/Bridge/VertexAi/Gemini/ResultConverter.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,15 @@ private function convertChoice(array $choice): ToolCallResult|TextResult
129129
{
130130
$contentParts = $choice['content']['parts'];
131131

132-
if (1 === \count($contentParts)) {
133-
$contentPart = $contentParts[0];
134-
132+
// If any part is a function call, return it immediately and ignore all other parts.
133+
foreach ($contentParts as $contentPart) {
135134
if (isset($contentPart['functionCall'])) {
136135
return new ToolCallResult($this->convertToolCall($contentPart['functionCall']));
137136
}
137+
}
138+
139+
if (1 === \count($contentParts)) {
140+
$contentPart = $contentParts[0];
138141

139142
if (isset($contentPart['text'])) {
140143
return new TextResult($contentPart['text']);

src/platform/tests/Bridge/VertexAi/Gemini/ResultConverterTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Symfony\AI\Platform\Bridge\VertexAi\Gemini\ResultConverter;
1616
use Symfony\AI\Platform\Result\RawHttpResult;
1717
use Symfony\AI\Platform\Result\TextResult;
18+
use Symfony\AI\Platform\Result\ToolCall;
19+
use Symfony\AI\Platform\Result\ToolCallResult;
1820
use Symfony\Contracts\HttpClient\ResponseInterface;
1921

2022
final class ResultConverterTest extends TestCase
@@ -57,6 +59,42 @@ public function testItReturnsAggregatedTextOnSuccess()
5759
$this->assertEquals("Second text\nThird text\nFourth text", $result->getContent());
5860
}
5961

62+
public function testItReturnsToolCallEvenIfMultipleContentPartsAreGiven()
63+
{
64+
$payload = [
65+
'content' => [
66+
'parts' => [
67+
[
68+
'text' => 'foo',
69+
],
70+
[
71+
'functionCall' => [
72+
'name' => 'some_tool',
73+
'args' => [],
74+
],
75+
],
76+
],
77+
],
78+
];
79+
$expectedResponse = [
80+
'candidates' => [$payload],
81+
];
82+
$response = $this->createStub(ResponseInterface::class);
83+
$response
84+
->method('toArray')
85+
->willReturn($expectedResponse);
86+
87+
$resultConverter = new ResultConverter();
88+
89+
$result = $resultConverter->convert(new RawHttpResult($response));
90+
91+
$this->assertInstanceOf(ToolCallResult::class, $result);
92+
$this->assertCount(1, $result->getContent());
93+
$toolCall = $result->getContent()[0];
94+
$this->assertInstanceOf(ToolCall::class, $toolCall);
95+
$this->assertSame('some_tool', $toolCall->id);
96+
}
97+
6098
public function testItThrowsExceptionOnFailure()
6199
{
62100
$response = $this->createStub(ResponseInterface::class);

0 commit comments

Comments
 (0)