Skip to content

Commit d556c21

Browse files
committed
[Agent] Update Tool usage to use getters
1 parent 11c9172 commit d556c21

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

src/agent/src/InputProcessor/SystemPromptInputProcessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ public function processInput(Input $input): void
6868

6969
$tools = implode(\PHP_EOL.\PHP_EOL, array_map(
7070
fn (Tool $tool) => <<<TOOL
71-
## {$tool->name}
72-
{$tool->description}
71+
## {$tool->getName()}
72+
{$tool->getDescription()}
7373
TOOL,
7474
$this->toolbox->getTools()
7575
));

src/agent/src/Toolbox/AgentProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function processInput(Input $input): void
5252
$options = $input->getOptions();
5353
// only filter tool map if list of strings is provided as option
5454
if (isset($options['tools']) && $this->isFlatStringArray($options['tools'])) {
55-
$toolMap = array_values(array_filter($toolMap, fn (Tool $tool) => \in_array($tool->name, $options['tools'], true)));
55+
$toolMap = array_values(array_filter($toolMap, fn (Tool $tool) => \in_array($tool->getName(), $options['tools'], true)));
5656
}
5757

5858
$options['tools'] = $toolMap;

src/agent/src/Toolbox/FaultTolerantToolbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function execute(ToolCall $toolCall): mixed
4040
} catch (ToolExecutionExceptionInterface $e) {
4141
return $e->getToolCallResult();
4242
} catch (ToolNotFoundException) {
43-
$names = array_map(fn (Tool $metadata) => $metadata->name, $this->getTools());
43+
$names = array_map(fn (Tool $metadata) => $metadata->getName(), $this->getTools());
4444

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

src/agent/src/Toolbox/ToolCallArgumentResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(
4343
*/
4444
public function resolveArguments(Tool $metadata, ToolCall $toolCall): array
4545
{
46-
$method = new \ReflectionMethod($metadata->reference->getClass(), $metadata->reference->getMethod());
46+
$method = new \ReflectionMethod($metadata->getReference()->getClass(), $metadata->getReference()->getMethod());
4747

4848
/** @var array<string, \ReflectionParameter> $parameters */
4949
$parameters = array_column($method->getParameters(), null, 'name');

src/agent/src/Toolbox/Toolbox.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function execute(ToolCall $toolCall): mixed
8282

8383
$arguments = $this->argumentResolver->resolveArguments($metadata, $toolCall);
8484
$this->eventDispatcher?->dispatch(new ToolCallArgumentsResolved($tool, $metadata, $arguments));
85-
$result = $tool->{$metadata->reference->getMethod()}(...$arguments);
85+
$result = $tool->{$metadata->getReference()->getMethod()}(...$arguments);
8686
$this->eventDispatcher?->dispatch(new ToolCallSucceeded($tool, $metadata, $arguments, $result));
8787
} catch (ToolExecutionExceptionInterface $e) {
8888
$this->eventDispatcher?->dispatch(new ToolCallFailed($tool, $metadata, $arguments ?? [], $e));
@@ -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->getName()) {
102+
if ($metadata->getName() === $toolCall->getName()) {
103103
return $metadata;
104104
}
105105
}
@@ -109,13 +109,13 @@ private function getMetadata(ToolCall $toolCall): Tool
109109

110110
private function getExecutable(Tool $metadata): object
111111
{
112-
$className = $metadata->reference->getClass();
112+
$className = $metadata->getReference()->getClass();
113113
foreach ($this->tools as $tool) {
114114
if ($tool instanceof $className) {
115115
return $tool;
116116
}
117117
}
118118

119-
throw ToolNotFoundException::notFoundForReference($metadata->reference);
119+
throw ToolNotFoundException::notFoundForReference($metadata->getReference());
120120
}
121121
}

src/agent/tests/Toolbox/MetadataFactory/ReflectionFactoryTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ className: ToolMultiple::class,
127127

128128
private function assertToolConfiguration(Tool $metadata, string $className, string $name, string $description, string $method, array $parameters): void
129129
{
130-
$this->assertSame($className, $metadata->reference->getClass());
131-
$this->assertSame($method, $metadata->reference->getMethod());
132-
$this->assertSame($name, $metadata->name);
133-
$this->assertSame($description, $metadata->description);
134-
$this->assertSame($parameters, $metadata->parameters);
130+
$this->assertSame($className, $metadata->getReference()->getClass());
131+
$this->assertSame($method, $metadata->getReference()->getMethod());
132+
$this->assertSame($name, $metadata->getName());
133+
$this->assertSame($description, $metadata->getDescription());
134+
$this->assertSame($parameters, $metadata->getParameters());
135135
}
136136
}

0 commit comments

Comments
 (0)