bug #1792 [Platform][Generic][Scaleway] Fix tool call without arguments (guillaume-ro-fr)

This PR was squashed before being merged into the main branch.

Discussion
----------

[Platform][Generic][Scaleway] Fix tool call without arguments

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| Docs?         | no <!-- required for new features -->
| Issues        | None <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead -->
| License       | MIT

When calling a tool on Scaleway (extends Generic, the `arguments` array may not be included in the results, which causes problems when converting the result with `ResultConverter`.

This PR fixes the issue by checking that the array exists before retrieving its content.

Linked to #1649 (closed - merge conflicts)

Commits
-------

59601c0b [Platform][Generic][Scaleway] Fix tool call without arguments
This commit is contained in:
Christopher Hertel
2026-03-22 23:52:35 +01:00

View File

@@ -49,7 +49,7 @@ final class ResultConverterTest extends TestCase
$this->assertSame('Hello world', $result->getContent());
}
public function testConvertToolCallResult()
public function testConvertToolWithArgsCallResult()
{
$converter = new ResultConverter();
$httpResponse = self::createMock(ResponseInterface::class);
@@ -85,6 +85,77 @@ final class ResultConverterTest extends TestCase
$this->assertSame(['arg1' => 'value1'], $toolCalls[0]->getArguments());
}
public function testConvertToolWithEmptyArgsCallResult()
{
$converter = new ResultConverter();
$httpResponse = self::createMock(ResponseInterface::class);
$httpResponse->method('toArray')->willReturn([
'choices' => [
[
'message' => [
'role' => 'assistant',
'content' => null,
'tool_calls' => [
[
'id' => 'call_123',
'type' => 'function',
'function' => [
'name' => 'test_function',
'arguments' => '',
],
],
],
],
'finish_reason' => 'tool_calls',
],
],
]);
$result = $converter->convert(new RawHttpResult($httpResponse));
$this->assertInstanceOf(ToolCallResult::class, $result);
$toolCalls = $result->getContent();
$this->assertCount(1, $toolCalls);
$this->assertSame('call_123', $toolCalls[0]->getId());
$this->assertSame('test_function', $toolCalls[0]->getName());
$this->assertSame([], $toolCalls[0]->getArguments());
}
public function testConvertToolWithoutArgsCallResult()
{
$converter = new ResultConverter();
$httpResponse = self::createMock(ResponseInterface::class);
$httpResponse->method('toArray')->willReturn([
'choices' => [
[
'message' => [
'role' => 'assistant',
'content' => null,
'tool_calls' => [
[
'id' => 'call_123',
'type' => 'function',
'function' => [
'name' => 'test_function',
],
],
],
],
'finish_reason' => 'tool_calls',
],
],
]);
$result = $converter->convert(new RawHttpResult($httpResponse));
$this->assertInstanceOf(ToolCallResult::class, $result);
$toolCalls = $result->getContent();
$this->assertCount(1, $toolCalls);
$this->assertSame('call_123', $toolCalls[0]->getId());
$this->assertSame('test_function', $toolCalls[0]->getName());
$this->assertSame([], $toolCalls[0]->getArguments());
}
public function testConvertMultipleChoices()
{
$converter = new ResultConverter();