Skip to content

Commit 7e666ea

Browse files
committed
feature #737 [Platform] Make ToolCall properties private with getters (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [Platform] Make `ToolCall` properties private with getters | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | Docs? | no | Issues | -- | License | MIT Commits ------- 620d62a [Platform] Make `ToolCall` properties private with getters
2 parents 401ac27 + 620d62a commit 7e666ea

27 files changed

+124
-81
lines changed

examples/toolbox/weather-event.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// Add tool call result listener to enforce chain exits direct with structured response for weather tools
3434
$eventDispatcher->addListener(ToolCallsExecuted::class, function (ToolCallsExecuted $event): void {
3535
foreach ($event->toolResults as $toolCallResult) {
36-
if (str_starts_with($toolCallResult->toolCall->name, 'weather_')) {
36+
if (str_starts_with($toolCallResult->toolCall->getName(), 'weather_')) {
3737
$event->result = new ObjectResult($toolCallResult->result);
3838
}
3939
}

src/agent/src/Toolbox/Exception/ToolExecutionException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ final class ToolExecutionException extends \RuntimeException implements ToolExec
2222

2323
public static function executionFailed(ToolCall $toolCall, \Throwable $previous): self
2424
{
25-
$exception = new self(\sprintf('Execution of tool "%s" failed with error: %s', $toolCall->name, $previous->getMessage()), previous: $previous);
25+
$exception = new self(\sprintf('Execution of tool "%s" failed with error: %s', $toolCall->getName(), $previous->getMessage()), previous: $previous);
2626
$exception->toolCall = $toolCall;
2727

2828
return $exception;
2929
}
3030

3131
public function getToolCallResult(): string
3232
{
33-
return \sprintf('An error occurred while executing tool "%s".', $this->toolCall->name);
33+
return \sprintf('An error occurred while executing tool "%s".', $this->toolCall->getName());
3434
}
3535
}

src/agent/src/Toolbox/Exception/ToolNotFoundException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class ToolNotFoundException extends \RuntimeException implements Exception
2323

2424
public static function notFoundForToolCall(ToolCall $toolCall): self
2525
{
26-
$exception = new self(\sprintf('Tool not found for call: %s.', $toolCall->name));
26+
$exception = new self(\sprintf('Tool not found for call: %s.', $toolCall->getName()));
2727
$exception->toolCall = $toolCall;
2828

2929
return $exception;

src/agent/src/Toolbox/FaultTolerantToolbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function execute(ToolCall $toolCall): mixed
4242
} catch (ToolNotFoundException) {
4343
$names = array_map(fn (Tool $metadata) => $metadata->name, $this->getTools());
4444

45-
return \sprintf('Tool "%s" was not found, please use one of these: %s', $toolCall->name, implode(', ', $names));
45+
return \sprintf('Tool "%s" was not found, please use one of these: %s', $toolCall->getName(), implode(', ', $names));
4646
}
4747
}
4848
}

src/agent/src/Toolbox/ToolCallArgumentResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ public function resolveArguments(Tool $metadata, ToolCall $toolCall): array
5050
$arguments = [];
5151

5252
foreach ($parameters as $name => $reflectionParameter) {
53-
if (!\array_key_exists($name, $toolCall->arguments)) {
53+
if (!\array_key_exists($name, $toolCall->getArguments())) {
5454
if (!$reflectionParameter->isOptional()) {
55-
throw new ToolException(\sprintf('Parameter "%s" is mandatory for tool "%s".', $name, $toolCall->name));
55+
throw new ToolException(\sprintf('Parameter "%s" is mandatory for tool "%s".', $name, $toolCall->getName()));
5656
}
5757
continue;
5858
}
5959

60-
$value = $toolCall->arguments[$name];
60+
$value = $toolCall->getArguments()[$name];
6161
$parameterType = $this->typeResolver->resolve($reflectionParameter);
6262
$dimensions = '';
6363
while ($parameterType instanceof CollectionType) {

src/agent/src/Toolbox/Toolbox.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function execute(ToolCall $toolCall): mixed
7878
$tool = $this->getExecutable($metadata);
7979

8080
try {
81-
$this->logger->debug(\sprintf('Executing tool "%s".', $toolCall->name), $toolCall->arguments);
81+
$this->logger->debug(\sprintf('Executing tool "%s".', $toolCall->getName()), $toolCall->getArguments());
8282

8383
$arguments = $this->argumentResolver->resolveArguments($metadata, $toolCall);
8484
$this->eventDispatcher?->dispatch(new ToolCallArgumentsResolved($tool, $metadata, $arguments));
@@ -88,7 +88,7 @@ public function execute(ToolCall $toolCall): mixed
8888
$this->eventDispatcher?->dispatch(new ToolCallFailed($tool, $metadata, $arguments ?? [], $e));
8989
throw $e;
9090
} catch (\Throwable $e) {
91-
$this->logger->warning(\sprintf('Failed to execute tool "%s".', $toolCall->name), ['exception' => $e]);
91+
$this->logger->warning(\sprintf('Failed to execute tool "%s".', $toolCall->getName()), ['exception' => $e]);
9292
$this->eventDispatcher?->dispatch(new ToolCallFailed($tool, $metadata, $arguments ?? [], $e));
9393
throw ToolExecutionException::executionFailed($toolCall, $e);
9494
}
@@ -99,7 +99,7 @@ public function execute(ToolCall $toolCall): mixed
9999
private function getMetadata(ToolCall $toolCall): Tool
100100
{
101101
foreach ($this->getTools() as $metadata) {
102-
if ($metadata->name === $toolCall->name) {
102+
if ($metadata->name === $toolCall->getName()) {
103103
return $metadata;
104104
}
105105
}

src/platform/src/Bridge/Anthropic/Contract/AssistantMessageNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public function normalize(mixed $data, ?string $format = null, array $context =
4646
'content' => $data->hasToolCalls() ? array_map(static function (ToolCall $toolCall) {
4747
return [
4848
'type' => 'tool_use',
49-
'id' => $toolCall->id,
50-
'name' => $toolCall->name,
51-
'input' => [] !== $toolCall->arguments ? $toolCall->arguments : new \stdClass(),
49+
'id' => $toolCall->getId(),
50+
'name' => $toolCall->getName(),
51+
'input' => [] !== $toolCall->getArguments() ? $toolCall->getArguments() : new \stdClass(),
5252
];
5353
}, $data->toolCalls) : $data->content,
5454
];

src/platform/src/Bridge/Anthropic/Contract/ToolCallMessageNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
4444
'content' => [
4545
[
4646
'type' => 'tool_result',
47-
'tool_use_id' => $data->toolCall->id,
47+
'tool_use_id' => $data->toolCall->getId(),
4848
'content' => $data->content,
4949
],
5050
],

src/platform/src/Bridge/Bedrock/Nova/Contract/AssistantMessageNormalizer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ public function normalize(mixed $data, ?string $format = null, array $context =
4545
'content' => array_map(static function (ToolCall $toolCall) {
4646
return [
4747
'toolUse' => [
48-
'toolUseId' => $toolCall->id,
49-
'name' => $toolCall->name,
50-
'input' => [] !== $toolCall->arguments ? $toolCall->arguments : new \stdClass(),
48+
'toolUseId' => $toolCall->getId(),
49+
'name' => $toolCall->getName(),
50+
'input' => [] !== $toolCall->getArguments() ? $toolCall->getArguments() : new \stdClass(),
5151
],
5252
];
5353
}, $data->toolCalls),

src/platform/src/Bridge/Bedrock/Nova/Contract/ToolCallMessageNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
4545
'content' => [
4646
[
4747
'toolResult' => [
48-
'toolUseId' => $data->toolCall->id,
48+
'toolUseId' => $data->toolCall->getId(),
4949
'content' => [['json' => $data->content]],
5050
],
5151
],

0 commit comments

Comments
 (0)