Skip to content
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
2 changes: 1 addition & 1 deletion fixtures/Tool/ToolArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\AI\Agent\Toolbox\Attribute\AsTool;

#[AsTool('tool_no_params', 'A tool without parameters')]
#[AsTool('tool_array', 'A tool with array parameters')]
final class ToolArray
{
/**
Expand Down
3 changes: 2 additions & 1 deletion src/agent/src/Toolbox/ToolCallArgumentResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public function resolveArguments(object $tool, Tool $metadata, ToolCall $toolCal
$arguments = [];

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

return $arguments;
Expand Down
21 changes: 21 additions & 0 deletions src/agent/tests/Toolbox/ToolCallArgumentResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\AI\Agent\Toolbox\ToolCallArgumentResolver;
use Symfony\AI\Fixtures\Tool\ToolArray;
use Symfony\AI\Fixtures\Tool\ToolDate;
use Symfony\AI\Platform\Response\ToolCall;
use Symfony\AI\Platform\Tool\ExecutionReference;
Expand All @@ -38,4 +39,24 @@ public function resolveArguments(): void

self::assertEquals(['date' => new \DateTimeImmutable('2025-06-29')], $resolver->resolveArguments($tool, $metadata, $toolCall));
}

#[Test]
public function resolveScalarArrayArguments(): void
{
$resolver = new ToolCallArgumentResolver();

$tool = new ToolArray();
$metadata = new Tool(new ExecutionReference(ToolArray::class, '__invoke'), 'tool_array', 'A tool with array parameters');
$toolCall = new ToolCall('tool_id_1234', 'tool_array', [
'urls' => ['https://symfony.com', 'https://php.net'],
'ids' => [1, 2, 3],
]);

$expected = [
'urls' => ['https://symfony.com', 'https://php.net'],
'ids' => [1, 2, 3],
];

self::assertSame($expected, $resolver->resolveArguments($tool, $metadata, $toolCall));
}
}