Skip to content

Commit 9c82746

Browse files
committed
fix: resolve array tool arguments (#368)
@valtzu any idea about this case? found it after merging #359 with example [examples/toolbox/tavily.php](https://github.com/php-llm/llm-chain/blob/main/examples/toolbox/tavily.php) patch feels a bit hacky, but does the job atm
1 parent 4e0caf8 commit 9c82746

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/Toolbox/ToolCallArgumentResolver.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public function resolveArguments(object $tool, Tool $metadata, ToolCall $toolCal
3737
$arguments = [];
3838

3939
foreach ($toolCall->arguments as $name => $value) {
40-
$arguments[$name] = $this->denormalizer->denormalize($value, (string) $parameters[$name]->getType());
40+
$parameterType = (string) $parameters[$name]->getType();
41+
$arguments[$name] = 'array' === $parameterType ? $value : $this->denormalizer->denormalize($value, $parameterType);
4142
}
4243

4344
return $arguments;

tests/Toolbox/ToolCallArgumentResolverTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use PHPUnit\Framework\Attributes\UsesClass;
1717
use PHPUnit\Framework\TestCase;
1818
use Symfony\AI\Agent\Toolbox\ToolCallArgumentResolver;
19+
use Symfony\AI\Fixtures\Tool\ToolArray;
1920
use Symfony\AI\Fixtures\Tool\ToolDate;
2021
use Symfony\AI\Platform\Response\ToolCall;
2122
use Symfony\AI\Platform\Tool\ExecutionReference;
@@ -38,4 +39,24 @@ public function resolveArguments(): void
3839

3940
self::assertEquals(['date' => new \DateTimeImmutable('2025-06-29')], $resolver->resolveArguments($tool, $metadata, $toolCall));
4041
}
42+
43+
#[Test]
44+
public function resolveScalarArrayArguments(): void
45+
{
46+
$resolver = new ToolCallArgumentResolver();
47+
48+
$tool = new ToolArray();
49+
$metadata = new Tool(new ExecutionReference(ToolArray::class, '__invoke'), 'tool_array', 'A tool with array parameters');
50+
$toolCall = new ToolCall('tool_id_1234', 'tool_array', [
51+
'urls' => ['https://symfony.com', 'https://php.net'],
52+
'ids' => [1, 2, 3],
53+
]);
54+
55+
$expected = [
56+
'urls' => ['https://symfony.com', 'https://php.net'],
57+
'ids' => [1, 2, 3],
58+
];
59+
60+
self::assertSame($expected, $resolver->resolveArguments($tool, $metadata, $toolCall));
61+
}
4162
}

0 commit comments

Comments
 (0)