From 620d62abdfac58b9b7abf8609e9b41e4612b8278 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Mon, 6 Oct 2025 21:23:36 +0200 Subject: [PATCH] [Platform] Make `ToolCall` properties private with getters --- examples/toolbox/weather-event.php | 2 +- .../Exception/ToolExecutionException.php | 4 +-- .../Exception/ToolNotFoundException.php | 2 +- .../src/Toolbox/FaultTolerantToolbox.php | 2 +- .../src/Toolbox/ToolCallArgumentResolver.php | 6 ++-- src/agent/src/Toolbox/Toolbox.php | 6 ++-- .../Contract/AssistantMessageNormalizer.php | 6 ++-- .../Contract/ToolCallMessageNormalizer.php | 2 +- .../Contract/AssistantMessageNormalizer.php | 6 ++-- .../Contract/ToolCallMessageNormalizer.php | 2 +- .../Contract/AssistantMessageNormalizer.php | 8 ++--- .../Contract/ToolCallMessageNormalizer.php | 4 +-- .../Contract/AssistantMessageNormalizer.php | 4 +-- .../Contract/AssistantMessageNormalizer.php | 6 ++-- .../Contract/ToolCallMessageNormalizer.php | 2 +- .../Message/ToolCallMessageNormalizer.php | 2 +- .../Normalizer/Result/ToolCallNormalizer.php | 6 ++-- src/platform/src/Result/ToolCall.php | 24 ++++++++++++-- .../Bridge/Anthropic/ResultConverterTest.php | 6 ++-- .../Anthropic/ClaudeResultConverterTest.php | 20 ++++++------ .../Bedrock/Nova/NovaResultConverterTest.php | 20 ++++++------ .../Gemini/Gemini/ResultConverterTest.php | 2 +- .../Ollama/OllamaResultConverterTest.php | 18 +++++------ .../Bridge/OpenAi/Gpt/ResultConverterTest.php | 6 ++-- .../Scaleway/Llm/ResultConverterTest.php | 6 ++-- .../VertexAi/Gemini/ResultConverterTest.php | 2 +- src/platform/tests/Result/ToolCallTest.php | 31 +++++++++++++++++-- 27 files changed, 124 insertions(+), 81 deletions(-) diff --git a/examples/toolbox/weather-event.php b/examples/toolbox/weather-event.php index 2773c9d1a..0288d1c72 100644 --- a/examples/toolbox/weather-event.php +++ b/examples/toolbox/weather-event.php @@ -33,7 +33,7 @@ // Add tool call result listener to enforce chain exits direct with structured response for weather tools $eventDispatcher->addListener(ToolCallsExecuted::class, function (ToolCallsExecuted $event): void { foreach ($event->toolResults as $toolCallResult) { - if (str_starts_with($toolCallResult->toolCall->name, 'weather_')) { + if (str_starts_with($toolCallResult->toolCall->getName(), 'weather_')) { $event->result = new ObjectResult($toolCallResult->result); } } diff --git a/src/agent/src/Toolbox/Exception/ToolExecutionException.php b/src/agent/src/Toolbox/Exception/ToolExecutionException.php index 6252d4cf8..2f0b0e3b9 100644 --- a/src/agent/src/Toolbox/Exception/ToolExecutionException.php +++ b/src/agent/src/Toolbox/Exception/ToolExecutionException.php @@ -22,7 +22,7 @@ final class ToolExecutionException extends \RuntimeException implements ToolExec public static function executionFailed(ToolCall $toolCall, \Throwable $previous): self { - $exception = new self(\sprintf('Execution of tool "%s" failed with error: %s', $toolCall->name, $previous->getMessage()), previous: $previous); + $exception = new self(\sprintf('Execution of tool "%s" failed with error: %s', $toolCall->getName(), $previous->getMessage()), previous: $previous); $exception->toolCall = $toolCall; return $exception; @@ -30,6 +30,6 @@ public static function executionFailed(ToolCall $toolCall, \Throwable $previous) public function getToolCallResult(): string { - return \sprintf('An error occurred while executing tool "%s".', $this->toolCall->name); + return \sprintf('An error occurred while executing tool "%s".', $this->toolCall->getName()); } } diff --git a/src/agent/src/Toolbox/Exception/ToolNotFoundException.php b/src/agent/src/Toolbox/Exception/ToolNotFoundException.php index 1cd9dea3c..bcdaf04b3 100644 --- a/src/agent/src/Toolbox/Exception/ToolNotFoundException.php +++ b/src/agent/src/Toolbox/Exception/ToolNotFoundException.php @@ -23,7 +23,7 @@ final class ToolNotFoundException extends \RuntimeException implements Exception public static function notFoundForToolCall(ToolCall $toolCall): self { - $exception = new self(\sprintf('Tool not found for call: %s.', $toolCall->name)); + $exception = new self(\sprintf('Tool not found for call: %s.', $toolCall->getName())); $exception->toolCall = $toolCall; return $exception; diff --git a/src/agent/src/Toolbox/FaultTolerantToolbox.php b/src/agent/src/Toolbox/FaultTolerantToolbox.php index 46f625084..236ccb8c4 100644 --- a/src/agent/src/Toolbox/FaultTolerantToolbox.php +++ b/src/agent/src/Toolbox/FaultTolerantToolbox.php @@ -42,7 +42,7 @@ public function execute(ToolCall $toolCall): mixed } catch (ToolNotFoundException) { $names = array_map(fn (Tool $metadata) => $metadata->name, $this->getTools()); - return \sprintf('Tool "%s" was not found, please use one of these: %s', $toolCall->name, implode(', ', $names)); + return \sprintf('Tool "%s" was not found, please use one of these: %s', $toolCall->getName(), implode(', ', $names)); } } } diff --git a/src/agent/src/Toolbox/ToolCallArgumentResolver.php b/src/agent/src/Toolbox/ToolCallArgumentResolver.php index 37e029767..d6232804d 100644 --- a/src/agent/src/Toolbox/ToolCallArgumentResolver.php +++ b/src/agent/src/Toolbox/ToolCallArgumentResolver.php @@ -50,14 +50,14 @@ public function resolveArguments(Tool $metadata, ToolCall $toolCall): array $arguments = []; foreach ($parameters as $name => $reflectionParameter) { - if (!\array_key_exists($name, $toolCall->arguments)) { + if (!\array_key_exists($name, $toolCall->getArguments())) { if (!$reflectionParameter->isOptional()) { - throw new ToolException(\sprintf('Parameter "%s" is mandatory for tool "%s".', $name, $toolCall->name)); + throw new ToolException(\sprintf('Parameter "%s" is mandatory for tool "%s".', $name, $toolCall->getName())); } continue; } - $value = $toolCall->arguments[$name]; + $value = $toolCall->getArguments()[$name]; $parameterType = $this->typeResolver->resolve($reflectionParameter); $dimensions = ''; while ($parameterType instanceof CollectionType) { diff --git a/src/agent/src/Toolbox/Toolbox.php b/src/agent/src/Toolbox/Toolbox.php index 53362ab23..16bf7e475 100644 --- a/src/agent/src/Toolbox/Toolbox.php +++ b/src/agent/src/Toolbox/Toolbox.php @@ -78,7 +78,7 @@ public function execute(ToolCall $toolCall): mixed $tool = $this->getExecutable($metadata); try { - $this->logger->debug(\sprintf('Executing tool "%s".', $toolCall->name), $toolCall->arguments); + $this->logger->debug(\sprintf('Executing tool "%s".', $toolCall->getName()), $toolCall->getArguments()); $arguments = $this->argumentResolver->resolveArguments($metadata, $toolCall); $this->eventDispatcher?->dispatch(new ToolCallArgumentsResolved($tool, $metadata, $arguments)); @@ -88,7 +88,7 @@ public function execute(ToolCall $toolCall): mixed $this->eventDispatcher?->dispatch(new ToolCallFailed($tool, $metadata, $arguments ?? [], $e)); throw $e; } catch (\Throwable $e) { - $this->logger->warning(\sprintf('Failed to execute tool "%s".', $toolCall->name), ['exception' => $e]); + $this->logger->warning(\sprintf('Failed to execute tool "%s".', $toolCall->getName()), ['exception' => $e]); $this->eventDispatcher?->dispatch(new ToolCallFailed($tool, $metadata, $arguments ?? [], $e)); throw ToolExecutionException::executionFailed($toolCall, $e); } @@ -99,7 +99,7 @@ public function execute(ToolCall $toolCall): mixed private function getMetadata(ToolCall $toolCall): Tool { foreach ($this->getTools() as $metadata) { - if ($metadata->name === $toolCall->name) { + if ($metadata->name === $toolCall->getName()) { return $metadata; } } diff --git a/src/platform/src/Bridge/Anthropic/Contract/AssistantMessageNormalizer.php b/src/platform/src/Bridge/Anthropic/Contract/AssistantMessageNormalizer.php index 09c256a72..abe2148f0 100644 --- a/src/platform/src/Bridge/Anthropic/Contract/AssistantMessageNormalizer.php +++ b/src/platform/src/Bridge/Anthropic/Contract/AssistantMessageNormalizer.php @@ -46,9 +46,9 @@ public function normalize(mixed $data, ?string $format = null, array $context = 'content' => $data->hasToolCalls() ? array_map(static function (ToolCall $toolCall) { return [ 'type' => 'tool_use', - 'id' => $toolCall->id, - 'name' => $toolCall->name, - 'input' => [] !== $toolCall->arguments ? $toolCall->arguments : new \stdClass(), + 'id' => $toolCall->getId(), + 'name' => $toolCall->getName(), + 'input' => [] !== $toolCall->getArguments() ? $toolCall->getArguments() : new \stdClass(), ]; }, $data->toolCalls) : $data->content, ]; diff --git a/src/platform/src/Bridge/Anthropic/Contract/ToolCallMessageNormalizer.php b/src/platform/src/Bridge/Anthropic/Contract/ToolCallMessageNormalizer.php index 20234456d..cc561643c 100644 --- a/src/platform/src/Bridge/Anthropic/Contract/ToolCallMessageNormalizer.php +++ b/src/platform/src/Bridge/Anthropic/Contract/ToolCallMessageNormalizer.php @@ -44,7 +44,7 @@ public function normalize(mixed $data, ?string $format = null, array $context = 'content' => [ [ 'type' => 'tool_result', - 'tool_use_id' => $data->toolCall->id, + 'tool_use_id' => $data->toolCall->getId(), 'content' => $data->content, ], ], diff --git a/src/platform/src/Bridge/Bedrock/Nova/Contract/AssistantMessageNormalizer.php b/src/platform/src/Bridge/Bedrock/Nova/Contract/AssistantMessageNormalizer.php index 9c9556d67..6df68a745 100644 --- a/src/platform/src/Bridge/Bedrock/Nova/Contract/AssistantMessageNormalizer.php +++ b/src/platform/src/Bridge/Bedrock/Nova/Contract/AssistantMessageNormalizer.php @@ -45,9 +45,9 @@ public function normalize(mixed $data, ?string $format = null, array $context = 'content' => array_map(static function (ToolCall $toolCall) { return [ 'toolUse' => [ - 'toolUseId' => $toolCall->id, - 'name' => $toolCall->name, - 'input' => [] !== $toolCall->arguments ? $toolCall->arguments : new \stdClass(), + 'toolUseId' => $toolCall->getId(), + 'name' => $toolCall->getName(), + 'input' => [] !== $toolCall->getArguments() ? $toolCall->getArguments() : new \stdClass(), ], ]; }, $data->toolCalls), diff --git a/src/platform/src/Bridge/Bedrock/Nova/Contract/ToolCallMessageNormalizer.php b/src/platform/src/Bridge/Bedrock/Nova/Contract/ToolCallMessageNormalizer.php index fbd868ec2..d6cf052ae 100644 --- a/src/platform/src/Bridge/Bedrock/Nova/Contract/ToolCallMessageNormalizer.php +++ b/src/platform/src/Bridge/Bedrock/Nova/Contract/ToolCallMessageNormalizer.php @@ -45,7 +45,7 @@ public function normalize(mixed $data, ?string $format = null, array $context = 'content' => [ [ 'toolResult' => [ - 'toolUseId' => $data->toolCall->id, + 'toolUseId' => $data->toolCall->getId(), 'content' => [['json' => $data->content]], ], ], diff --git a/src/platform/src/Bridge/Gemini/Contract/AssistantMessageNormalizer.php b/src/platform/src/Bridge/Gemini/Contract/AssistantMessageNormalizer.php index 381ea7123..bc6ad687d 100644 --- a/src/platform/src/Bridge/Gemini/Contract/AssistantMessageNormalizer.php +++ b/src/platform/src/Bridge/Gemini/Contract/AssistantMessageNormalizer.php @@ -36,12 +36,12 @@ public function normalize(mixed $data, ?string $format = null, array $context = if (isset($data->toolCalls[0])) { $normalized['functionCall'] = [ - 'id' => $data->toolCalls[0]->id, - 'name' => $data->toolCalls[0]->name, + 'id' => $data->toolCalls[0]->getId(), + 'name' => $data->toolCalls[0]->getName(), ]; - if ($data->toolCalls[0]->arguments) { - $normalized['functionCall']['args'] = $data->toolCalls[0]->arguments; + if ($data->toolCalls[0]->getArguments()) { + $normalized['functionCall']['args'] = $data->toolCalls[0]->getArguments(); } } diff --git a/src/platform/src/Bridge/Gemini/Contract/ToolCallMessageNormalizer.php b/src/platform/src/Bridge/Gemini/Contract/ToolCallMessageNormalizer.php index d20520179..2053aa532 100644 --- a/src/platform/src/Bridge/Gemini/Contract/ToolCallMessageNormalizer.php +++ b/src/platform/src/Bridge/Gemini/Contract/ToolCallMessageNormalizer.php @@ -38,8 +38,8 @@ public function normalize(mixed $data, ?string $format = null, array $context = return [[ 'functionResponse' => array_filter([ - 'id' => $data->toolCall->id, - 'name' => $data->toolCall->name, + 'id' => $data->toolCall->getId(), + 'name' => $data->toolCall->getName(), 'response' => \is_array($resultContent) ? $resultContent : [ 'rawResponse' => $resultContent, // Gemini expects the response to be an object, but not everyone uses objects as their responses. ], diff --git a/src/platform/src/Bridge/Ollama/Contract/AssistantMessageNormalizer.php b/src/platform/src/Bridge/Ollama/Contract/AssistantMessageNormalizer.php index 1d349958f..7edc08c74 100644 --- a/src/platform/src/Bridge/Ollama/Contract/AssistantMessageNormalizer.php +++ b/src/platform/src/Bridge/Ollama/Contract/AssistantMessageNormalizer.php @@ -51,9 +51,9 @@ public function normalize(mixed $data, ?string $format = null, array $context = return [ 'type' => 'function', 'function' => [ - 'name' => $message->name, + 'name' => $message->getName(), // stdClass forces empty object - 'arguments' => [] === $message->arguments ? new \stdClass() : $message->arguments, + 'arguments' => [] === $message->getArguments() ? new \stdClass() : $message->getArguments(), ], ]; }, $data->toolCalls ?? [])), diff --git a/src/platform/src/Bridge/VertexAi/Contract/AssistantMessageNormalizer.php b/src/platform/src/Bridge/VertexAi/Contract/AssistantMessageNormalizer.php index 790f463e8..613e93fd3 100644 --- a/src/platform/src/Bridge/VertexAi/Contract/AssistantMessageNormalizer.php +++ b/src/platform/src/Bridge/VertexAi/Contract/AssistantMessageNormalizer.php @@ -44,11 +44,11 @@ public function normalize(mixed $data, ?string $format = null, array $context = if (isset($data->toolCalls[0])) { $normalized['functionCall'] = [ - 'name' => $data->toolCalls[0]->name, + 'name' => $data->toolCalls[0]->getName(), ]; - if ($data->toolCalls[0]->arguments) { - $normalized['functionCall']['args'] = $data->toolCalls[0]->arguments; + if ($data->toolCalls[0]->getArguments()) { + $normalized['functionCall']['args'] = $data->toolCalls[0]->getArguments(); } } diff --git a/src/platform/src/Bridge/VertexAi/Contract/ToolCallMessageNormalizer.php b/src/platform/src/Bridge/VertexAi/Contract/ToolCallMessageNormalizer.php index 1caee0bd8..798637221 100644 --- a/src/platform/src/Bridge/VertexAi/Contract/ToolCallMessageNormalizer.php +++ b/src/platform/src/Bridge/VertexAi/Contract/ToolCallMessageNormalizer.php @@ -39,7 +39,7 @@ public function normalize(mixed $data, ?string $format = null, array $context = return [[ 'functionResponse' => array_filter([ - 'name' => $data->toolCall->name, + 'name' => $data->toolCall->getName(), 'response' => \is_array($resultContent) ? $resultContent : [ 'rawResponse' => $resultContent, ], diff --git a/src/platform/src/Contract/Normalizer/Message/ToolCallMessageNormalizer.php b/src/platform/src/Contract/Normalizer/Message/ToolCallMessageNormalizer.php index 9661717f8..e4313d441 100644 --- a/src/platform/src/Contract/Normalizer/Message/ToolCallMessageNormalizer.php +++ b/src/platform/src/Contract/Normalizer/Message/ToolCallMessageNormalizer.php @@ -47,7 +47,7 @@ public function normalize(mixed $data, ?string $format = null, array $context = return [ 'role' => $data->getRole()->value, 'content' => $this->normalizer->normalize($data->content, $format, $context), - 'tool_call_id' => $data->toolCall->id, + 'tool_call_id' => $data->toolCall->getId(), ]; } } diff --git a/src/platform/src/Contract/Normalizer/Result/ToolCallNormalizer.php b/src/platform/src/Contract/Normalizer/Result/ToolCallNormalizer.php index 22cf3357b..f4e9d1a0e 100644 --- a/src/platform/src/Contract/Normalizer/Result/ToolCallNormalizer.php +++ b/src/platform/src/Contract/Normalizer/Result/ToolCallNormalizer.php @@ -46,11 +46,11 @@ public function getSupportedTypes(?string $format): array public function normalize(mixed $data, ?string $format = null, array $context = []): array { return [ - 'id' => $data->id, + 'id' => $data->getId(), 'type' => 'function', 'function' => [ - 'name' => $data->name, - 'arguments' => json_encode($data->arguments), + 'name' => $data->getName(), + 'arguments' => json_encode($data->getArguments()), ], ]; } diff --git a/src/platform/src/Result/ToolCall.php b/src/platform/src/Result/ToolCall.php index 6a4beeb4b..86f5f32b5 100644 --- a/src/platform/src/Result/ToolCall.php +++ b/src/platform/src/Result/ToolCall.php @@ -20,12 +20,30 @@ * @param array $arguments */ public function __construct( - public string $id, - public string $name, - public array $arguments = [], + private string $id, + private string $name, + private array $arguments = [], ) { } + public function getId(): string + { + return $this->id; + } + + public function getName(): string + { + return $this->name; + } + + /** + * @return array + */ + public function getArguments(): array + { + return $this->arguments; + } + /** * @return array{ * id: string, diff --git a/src/platform/tests/Bridge/Anthropic/ResultConverterTest.php b/src/platform/tests/Bridge/Anthropic/ResultConverterTest.php index a67b318be..c11648976 100644 --- a/src/platform/tests/Bridge/Anthropic/ResultConverterTest.php +++ b/src/platform/tests/Bridge/Anthropic/ResultConverterTest.php @@ -38,8 +38,8 @@ public function testConvertThrowsExceptionWhenContentIsToolUseAndLacksText() $result = $handler->convert(new RawHttpResult($httpResponse)); $this->assertInstanceOf(ToolCallResult::class, $result); $this->assertCount(1, $result->getContent()); - $this->assertSame('toolu_01UM4PcTjC1UDiorSXVHSVFM', $result->getContent()[0]->id); - $this->assertSame('xxx_tool', $result->getContent()[0]->name); - $this->assertSame(['action' => 'get_data'], $result->getContent()[0]->arguments); + $this->assertSame('toolu_01UM4PcTjC1UDiorSXVHSVFM', $result->getContent()[0]->getId()); + $this->assertSame('xxx_tool', $result->getContent()[0]->getName()); + $this->assertSame(['action' => 'get_data'], $result->getContent()[0]->getArguments()); } } diff --git a/src/platform/tests/Bridge/Bedrock/Anthropic/ClaudeResultConverterTest.php b/src/platform/tests/Bridge/Bedrock/Anthropic/ClaudeResultConverterTest.php index de455def9..fd26e0b16 100644 --- a/src/platform/tests/Bridge/Bedrock/Anthropic/ClaudeResultConverterTest.php +++ b/src/platform/tests/Bridge/Bedrock/Anthropic/ClaudeResultConverterTest.php @@ -81,9 +81,9 @@ public function testConvertToolCallResult() $this->assertInstanceOf(ToolCallResult::class, $result); $toolCalls = $result->getContent(); $this->assertCount(1, $toolCalls); - $this->assertSame('toolu_01UM4PcTjC1UDiorSXVHSVFM', $toolCalls[0]->id); - $this->assertSame('get_weather', $toolCalls[0]->name); - $this->assertSame(['location' => 'Paris'], $toolCalls[0]->arguments); + $this->assertSame('toolu_01UM4PcTjC1UDiorSXVHSVFM', $toolCalls[0]->getId()); + $this->assertSame('get_weather', $toolCalls[0]->getName()); + $this->assertSame(['location' => 'Paris'], $toolCalls[0]->getArguments()); } #[TestDox('Converts response with multiple tool calls to ToolCallResult')] @@ -116,13 +116,13 @@ public function testConvertMultipleToolCalls() $toolCalls = $result->getContent(); $this->assertCount(2, $toolCalls); - $this->assertSame('toolu_01', $toolCalls[0]->id); - $this->assertSame('get_weather', $toolCalls[0]->name); - $this->assertSame(['location' => 'Paris'], $toolCalls[0]->arguments); + $this->assertSame('toolu_01', $toolCalls[0]->getId()); + $this->assertSame('get_weather', $toolCalls[0]->getName()); + $this->assertSame(['location' => 'Paris'], $toolCalls[0]->getArguments()); - $this->assertSame('toolu_02', $toolCalls[1]->id); - $this->assertSame('get_time', $toolCalls[1]->name); - $this->assertSame(['timezone' => 'UTC'], $toolCalls[1]->arguments); + $this->assertSame('toolu_02', $toolCalls[1]->getId()); + $this->assertSame('get_time', $toolCalls[1]->getName()); + $this->assertSame(['timezone' => 'UTC'], $toolCalls[1]->getArguments()); } #[TestDox('Prioritizes tool calls over text in mixed content')] @@ -153,7 +153,7 @@ public function testConvertMixedContentWithToolUse() $this->assertInstanceOf(ToolCallResult::class, $result); $toolCalls = $result->getContent(); $this->assertCount(1, $toolCalls); - $this->assertSame('toolu_01', $toolCalls[0]->id); + $this->assertSame('toolu_01', $toolCalls[0]->getId()); } #[TestDox('Throws RuntimeException when response has no content')] diff --git a/src/platform/tests/Bridge/Bedrock/Nova/NovaResultConverterTest.php b/src/platform/tests/Bridge/Bedrock/Nova/NovaResultConverterTest.php index 44fd46d58..34e8900cf 100644 --- a/src/platform/tests/Bridge/Bedrock/Nova/NovaResultConverterTest.php +++ b/src/platform/tests/Bridge/Bedrock/Nova/NovaResultConverterTest.php @@ -90,9 +90,9 @@ public function testConvertToolCallResult() $this->assertInstanceOf(ToolCallResult::class, $result); $toolCalls = $result->getContent(); $this->assertCount(1, $toolCalls); - $this->assertSame('nova-tool-123', $toolCalls[0]->id); - $this->assertSame('calculate', $toolCalls[0]->name); - $this->assertSame(['expression' => '2+2'], $toolCalls[0]->arguments); + $this->assertSame('nova-tool-123', $toolCalls[0]->getId()); + $this->assertSame('calculate', $toolCalls[0]->getName()); + $this->assertSame(['expression' => '2+2'], $toolCalls[0]->getArguments()); } #[TestDox('Converts response with multiple tool calls to ToolCallResult')] @@ -134,13 +134,13 @@ public function testConvertMultipleToolCalls() $toolCalls = $result->getContent(); $this->assertCount(2, $toolCalls); - $this->assertSame('nova-tool-1', $toolCalls[0]->id); - $this->assertSame('get_weather', $toolCalls[0]->name); - $this->assertSame(['location' => 'New York'], $toolCalls[0]->arguments); + $this->assertSame('nova-tool-1', $toolCalls[0]->getId()); + $this->assertSame('get_weather', $toolCalls[0]->getName()); + $this->assertSame(['location' => 'New York'], $toolCalls[0]->getArguments()); - $this->assertSame('nova-tool-2', $toolCalls[1]->id); - $this->assertSame('get_time', $toolCalls[1]->name); - $this->assertSame(['timezone' => 'EST'], $toolCalls[1]->arguments); + $this->assertSame('nova-tool-2', $toolCalls[1]->getId()); + $this->assertSame('get_time', $toolCalls[1]->getName()); + $this->assertSame(['timezone' => 'EST'], $toolCalls[1]->getArguments()); } #[TestDox('Prioritizes tool calls over text in mixed content')] @@ -175,7 +175,7 @@ public function testConvertMixedContentWithToolUse() $this->assertInstanceOf(ToolCallResult::class, $result); $toolCalls = $result->getContent(); $this->assertCount(1, $toolCalls); - $this->assertSame('nova-tool-123', $toolCalls[0]->id); + $this->assertSame('nova-tool-123', $toolCalls[0]->getId()); } #[TestDox('Throws RuntimeException when response has no output')] diff --git a/src/platform/tests/Bridge/Gemini/Gemini/ResultConverterTest.php b/src/platform/tests/Bridge/Gemini/Gemini/ResultConverterTest.php index 62052d888..846d115c9 100644 --- a/src/platform/tests/Bridge/Gemini/Gemini/ResultConverterTest.php +++ b/src/platform/tests/Bridge/Gemini/Gemini/ResultConverterTest.php @@ -75,7 +75,7 @@ public function testReturnsToolCallEvenIfMultipleContentPartsAreGiven() $this->assertCount(1, $result->getContent()); $toolCall = $result->getContent()[0]; $this->assertInstanceOf(ToolCall::class, $toolCall); - $this->assertSame('1234', $toolCall->id); + $this->assertSame('1234', $toolCall->getId()); } public function testConvertsInlineDataToBinaryResult() diff --git a/src/platform/tests/Bridge/Ollama/OllamaResultConverterTest.php b/src/platform/tests/Bridge/Ollama/OllamaResultConverterTest.php index 4ebe63fb3..9008b4d7c 100644 --- a/src/platform/tests/Bridge/Ollama/OllamaResultConverterTest.php +++ b/src/platform/tests/Bridge/Ollama/OllamaResultConverterTest.php @@ -69,9 +69,9 @@ public function testConvertToolCallResponse() $this->assertInstanceOf(ToolCallResult::class, $result); $toolCalls = $result->getContent(); $this->assertCount(1, $toolCalls); - $this->assertSame('0', $toolCalls[0]->id); // ID is the array index as a string - $this->assertSame('test_function', $toolCalls[0]->name); - $this->assertSame(['arg1' => 'value1'], $toolCalls[0]->arguments); + $this->assertSame('0', $toolCalls[0]->getId()); // ID is the array index as a string + $this->assertSame('test_function', $toolCalls[0]->getName()); + $this->assertSame(['arg1' => 'value1'], $toolCalls[0]->getArguments()); } public function testConvertMultipleToolCallsResponse() @@ -103,13 +103,13 @@ public function testConvertMultipleToolCallsResponse() $toolCalls = $result->getContent(); $this->assertCount(2, $toolCalls); - $this->assertSame('0', $toolCalls[0]->id); - $this->assertSame('function1', $toolCalls[0]->name); - $this->assertSame(['param1' => 'value1'], $toolCalls[0]->arguments); + $this->assertSame('0', $toolCalls[0]->getId()); + $this->assertSame('function1', $toolCalls[0]->getName()); + $this->assertSame(['param1' => 'value1'], $toolCalls[0]->getArguments()); - $this->assertSame('1', $toolCalls[1]->id); - $this->assertSame('function2', $toolCalls[1]->name); - $this->assertSame(['param2' => 'value2'], $toolCalls[1]->arguments); + $this->assertSame('1', $toolCalls[1]->getId()); + $this->assertSame('function2', $toolCalls[1]->getName()); + $this->assertSame(['param2' => 'value2'], $toolCalls[1]->getArguments()); } public function testThrowsExceptionWhenNoMessage() diff --git a/src/platform/tests/Bridge/OpenAi/Gpt/ResultConverterTest.php b/src/platform/tests/Bridge/OpenAi/Gpt/ResultConverterTest.php index f1a90f2b9..2d06095de 100644 --- a/src/platform/tests/Bridge/OpenAi/Gpt/ResultConverterTest.php +++ b/src/platform/tests/Bridge/OpenAi/Gpt/ResultConverterTest.php @@ -79,9 +79,9 @@ public function testConvertToolCallResult() $this->assertInstanceOf(ToolCallResult::class, $result); $toolCalls = $result->getContent(); $this->assertCount(1, $toolCalls); - $this->assertSame('call_123', $toolCalls[0]->id); - $this->assertSame('test_function', $toolCalls[0]->name); - $this->assertSame(['arg1' => 'value1'], $toolCalls[0]->arguments); + $this->assertSame('call_123', $toolCalls[0]->getId()); + $this->assertSame('test_function', $toolCalls[0]->getName()); + $this->assertSame(['arg1' => 'value1'], $toolCalls[0]->getArguments()); } public function testConvertMultipleChoices() diff --git a/src/platform/tests/Bridge/Scaleway/Llm/ResultConverterTest.php b/src/platform/tests/Bridge/Scaleway/Llm/ResultConverterTest.php index 4b484ed80..fe0404d8b 100644 --- a/src/platform/tests/Bridge/Scaleway/Llm/ResultConverterTest.php +++ b/src/platform/tests/Bridge/Scaleway/Llm/ResultConverterTest.php @@ -80,9 +80,9 @@ public function testConvertToolCallResult() $this->assertInstanceOf(ToolCallResult::class, $result); $toolCalls = $result->getContent(); $this->assertCount(1, $toolCalls); - $this->assertSame('call_123', $toolCalls[0]->id); - $this->assertSame('test_function', $toolCalls[0]->name); - $this->assertSame(['arg1' => 'value1'], $toolCalls[0]->arguments); + $this->assertSame('call_123', $toolCalls[0]->getId()); + $this->assertSame('test_function', $toolCalls[0]->getName()); + $this->assertSame(['arg1' => 'value1'], $toolCalls[0]->getArguments()); } public function testConvertMultipleChoices() diff --git a/src/platform/tests/Bridge/VertexAi/Gemini/ResultConverterTest.php b/src/platform/tests/Bridge/VertexAi/Gemini/ResultConverterTest.php index 5c6ba611b..b6ab31e79 100644 --- a/src/platform/tests/Bridge/VertexAi/Gemini/ResultConverterTest.php +++ b/src/platform/tests/Bridge/VertexAi/Gemini/ResultConverterTest.php @@ -93,7 +93,7 @@ public function testItReturnsToolCallEvenIfMultipleContentPartsAreGiven() $this->assertCount(1, $result->getContent()); $toolCall = $result->getContent()[0]; $this->assertInstanceOf(ToolCall::class, $toolCall); - $this->assertSame('some_tool', $toolCall->id); + $this->assertSame('some_tool', $toolCall->getId()); } public function testItThrowsExceptionOnFailure() diff --git a/src/platform/tests/Result/ToolCallTest.php b/src/platform/tests/Result/ToolCallTest.php index 9ffd1fbd2..cb4b1195c 100644 --- a/src/platform/tests/Result/ToolCallTest.php +++ b/src/platform/tests/Result/ToolCallTest.php @@ -19,9 +19,34 @@ final class ToolCallTest extends TestCase public function testToolCall() { $toolCall = new ToolCall('id', 'name', ['foo' => 'bar']); - $this->assertSame('id', $toolCall->id); - $this->assertSame('name', $toolCall->name); - $this->assertSame(['foo' => 'bar'], $toolCall->arguments); + $this->assertSame('id', $toolCall->getId()); + $this->assertSame('name', $toolCall->getName()); + $this->assertSame(['foo' => 'bar'], $toolCall->getArguments()); + } + + public function testGetId() + { + $toolCall = new ToolCall('test-id', 'function-name'); + $this->assertSame('test-id', $toolCall->getId()); + } + + public function testGetName() + { + $toolCall = new ToolCall('id', 'test-function'); + $this->assertSame('test-function', $toolCall->getName()); + } + + public function testGetArguments() + { + $arguments = ['param1' => 'value1', 'param2' => 42]; + $toolCall = new ToolCall('id', 'name', $arguments); + $this->assertSame($arguments, $toolCall->getArguments()); + } + + public function testGetArgumentsReturnsEmptyArrayByDefault() + { + $toolCall = new ToolCall('id', 'name'); + $this->assertSame([], $toolCall->getArguments()); } public function testToolCallJsonSerialize()