Skip to content

Commit 52e1d5a

Browse files
committed
minor #759 [Agent] Convert public properties to private in agent component (chr-hertel)
This PR was merged into the main branch. Discussion ---------- [Agent] Convert public properties to private in agent component | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | | License | MIT Commits ------- c59a63f Convert public properties to private in agent component
2 parents a4747cb + c59a63f commit 52e1d5a

File tree

17 files changed

+161
-43
lines changed

17 files changed

+161
-43
lines changed

examples/toolbox/weather-event.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232

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 {
35-
foreach ($event->toolResults as $toolCallResult) {
36-
if (str_starts_with($toolCallResult->toolCall->getName(), 'weather_')) {
37-
$event->result = new ObjectResult($toolCallResult->result);
35+
foreach ($event->getToolResults() as $toolCallResult) {
36+
if (str_starts_with($toolCallResult->getToolCall()->getName(), 'weather_')) {
37+
$event->setResult(new ObjectResult($toolCallResult->getResult()));
3838
}
3939
}
4040
});

src/agent/src/Memory/Memory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@
1616
*/
1717
final readonly class Memory
1818
{
19-
public function __construct(public string $content)
19+
public function __construct(
20+
private string $content,
21+
) {
22+
}
23+
24+
public function getContent(): string
2025
{
26+
return $this->content;
2127
}
2228
}

src/agent/src/Memory/MemoryInputProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function processInput(Input $input): void
6161
$memory .= \PHP_EOL.\PHP_EOL;
6262
$memory .= implode(
6363
\PHP_EOL,
64-
array_map(static fn (Memory $memory): string => $memory->content, $memoryMessages),
64+
array_map(static fn (Memory $memory): string => $memory->getContent(), $memoryMessages),
6565
);
6666
}
6767

src/agent/src/MultiAgent/Handoff/Decision.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
* @param string $reasoning The reasoning behind the selection
2424
*/
2525
public function __construct(
26-
public string $agentName,
27-
public string $reasoning = 'No reasoning provided',
26+
private string $agentName,
27+
private string $reasoning = 'No reasoning provided',
2828
) {
2929
}
3030

@@ -35,4 +35,14 @@ public function hasAgent(): bool
3535
{
3636
return '' !== $this->agentName;
3737
}
38+
39+
public function getAgentName(): string
40+
{
41+
return $this->agentName;
42+
}
43+
44+
public function getReasoning(): string
45+
{
46+
return $this->reasoning;
47+
}
3848
}

src/agent/src/MultiAgent/MultiAgent.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public function call(MessageBag $messages, array $options = []): ResultInterface
9191
}
9292

9393
$this->logger->debug('MultiAgent: Agent selection completed', [
94-
'selected_agent' => $decision->agentName,
95-
'reasoning' => $decision->reasoning,
94+
'selected_agent' => $decision->getAgentName(),
95+
'reasoning' => $decision->getReasoning(),
9696
]);
9797

9898
if (!$decision->hasAgent()) {
@@ -104,22 +104,22 @@ public function call(MessageBag $messages, array $options = []): ResultInterface
104104
// Find the target agent by name
105105
$targetAgent = null;
106106
foreach ($this->handoffs as $handoff) {
107-
if ($handoff->getTo()->getName() === $decision->agentName) {
107+
if ($handoff->getTo()->getName() === $decision->getAgentName()) {
108108
$targetAgent = $handoff->getTo();
109109
break;
110110
}
111111
}
112112

113113
if (!$targetAgent) {
114114
$this->logger->debug('MultiAgent: Target agent not found, using fallback agent', [
115-
'requested_agent' => $decision->agentName,
115+
'requested_agent' => $decision->getAgentName(),
116116
'reason' => 'agent_not_found',
117117
]);
118118

119119
return $this->fallback->call($messages, $options);
120120
}
121121

122-
$this->logger->debug('MultiAgent: Delegating to agent', ['agent_name' => $decision->agentName]);
122+
$this->logger->debug('MultiAgent: Delegating to agent', ['agent_name' => $decision->getAgentName()]);
123123

124124
// Call the selected agent with the original user question
125125
return $targetAgent->call(new MessageBag($userMessage), $options);

src/agent/src/Toolbox/AgentProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private function handleToolCallsCallback(Output $output): \Closure
107107
$event = new ToolCallsExecuted(...$results);
108108
$this->eventDispatcher?->dispatch($event);
109109

110-
$result = $event->hasResponse() ? $event->result : $this->agent->call($messages, $output->getOptions());
110+
$result = $event->hasResponse() ? $event->getResult() : $this->agent->call($messages, $output->getOptions());
111111
} while ($result instanceof ToolCallResult);
112112

113113
return $result;

src/agent/src/Toolbox/Event/ToolCallArgumentsResolved.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,27 @@
2424
* @param array<string, mixed> $arguments
2525
*/
2626
public function __construct(
27-
public object $tool,
28-
public Tool $metadata,
29-
public array $arguments,
27+
private object $tool,
28+
private Tool $metadata,
29+
private array $arguments,
3030
) {
3131
}
32+
33+
public function getTool(): object
34+
{
35+
return $this->tool;
36+
}
37+
38+
public function getMetadata(): Tool
39+
{
40+
return $this->metadata;
41+
}
42+
43+
/**
44+
* @return array<string, mixed>
45+
*/
46+
public function getArguments(): array
47+
{
48+
return $this->arguments;
49+
}
3250
}

src/agent/src/Toolbox/Event/ToolCallFailed.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,33 @@
2222
* @param array<string, mixed> $arguments
2323
*/
2424
public function __construct(
25-
public object $tool,
26-
public Tool $metadata,
27-
public array $arguments,
28-
public \Throwable $exception,
25+
private object $tool,
26+
private Tool $metadata,
27+
private array $arguments,
28+
private \Throwable $exception,
2929
) {
3030
}
31+
32+
public function getTool(): object
33+
{
34+
return $this->tool;
35+
}
36+
37+
public function getMetadata(): Tool
38+
{
39+
return $this->metadata;
40+
}
41+
42+
/**
43+
* @return array<string, mixed>
44+
*/
45+
public function getArguments(): array
46+
{
47+
return $this->arguments;
48+
}
49+
50+
public function getException(): \Throwable
51+
{
52+
return $this->exception;
53+
}
3154
}

src/agent/src/Toolbox/Event/ToolCallSucceeded.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,33 @@
2222
* @param array<string, mixed> $arguments
2323
*/
2424
public function __construct(
25-
public object $tool,
26-
public Tool $metadata,
27-
public array $arguments,
28-
public mixed $result,
25+
private object $tool,
26+
private Tool $metadata,
27+
private array $arguments,
28+
private mixed $result,
2929
) {
3030
}
31+
32+
public function getTool(): object
33+
{
34+
return $this->tool;
35+
}
36+
37+
public function getMetadata(): Tool
38+
{
39+
return $this->metadata;
40+
}
41+
42+
/**
43+
* @return array<string, mixed>
44+
*/
45+
public function getArguments(): array
46+
{
47+
return $this->arguments;
48+
}
49+
50+
public function getResult(): mixed
51+
{
52+
return $this->result;
53+
}
3154
}

src/agent/src/Toolbox/Event/ToolCallsExecuted.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ final class ToolCallsExecuted
2222
/**
2323
* @var ToolResult[]
2424
*/
25-
public readonly array $toolResults;
26-
public ResultInterface $result;
25+
private readonly array $toolResults;
26+
private ResultInterface $result;
2727

2828
public function __construct(ToolResult ...$toolResults)
2929
{
@@ -34,4 +34,22 @@ public function hasResponse(): bool
3434
{
3535
return isset($this->result);
3636
}
37+
38+
public function setResult(ResultInterface $result): void
39+
{
40+
$this->result = $result;
41+
}
42+
43+
public function getResult(): ResultInterface
44+
{
45+
return $this->result;
46+
}
47+
48+
/**
49+
* @return ToolResult[]
50+
*/
51+
public function getToolResults(): array
52+
{
53+
return $this->toolResults;
54+
}
3755
}

0 commit comments

Comments
 (0)